3.2 Logging Tools
There are several logging tools available for Pharo: Logging, Toothpick, SimpleLogger.
Logging
Logging developed by Keith Hodges is available at
Gofer new squeaksource: 'Logging'; package: 'ProcessSpecific'; package: 'Logging'; load
The documentation says: Logging, a front end to Toothpick, SimpleLog or LogEngine
Toothpick
Toothpick developed by Joseph Pelrine from MetaProg. http://www.metaprog.com/Toothpick/. It is the most advanced and provides a nice documentation.
SimpleLogger
SimpleLogger developed by Germán Arduino is available at http://ss3.gemstone.com/ss/SimpleLogger.html. SimpleLogger is a really simple text only logger.
It's simple to install, only point your Monticello Browser to:
MCHttpRepository location: 'http://ss3.gemstone.com/ss/SimpleLogger' user: '' password: ''
and load the latest version.
Use it is also simple:
aLogger := G9Logger new.
Creates a new instance of SimpleLogger, opening a text file named for example: "15 July 2010 6#15#01 am.txt"
Then, to log things on such file you can use the following messages:
aLogger log: 'Text to log on the logfile'.
Will log the phrase 'Text to log on the logfile" on the logfile.
aLogger logSeparator.
Will log a line of '-' to separate sections on the logfile.
aLogger logWithTimeStamp: 'This text was written at: '
Will log a the phrase 'This text was written at: 15 July 2010 6:24:03 am' in the logfile.
aLogger closeLogFile.
Will close the log file, writing some closing text.
The complete session of the previous samples will generate this log file:
---------------------------------------------------------------- G9Logger started at: 15 July 2010 6:15:01 am ---------------------------------------------------------------- Text to log on the logfile ---------------------------------------------------------------- This text was written at: 15 July 2010 6:24:03 am ---------------------------------------------------------------- G9Logger ended at: 15 July 2010 6:27:09 am ---------------------------------------------------------------- -------G9Logger is a product from Arduino Software-------------- ---Web: http://www.arduinosoftware.com---Mail: info@arsol.net---
Another simple logging approach method using syslog
If you're prefer to use standard syslog facilities found in Linux or in Windows with cygwin installed, you can use the method below to send log statements over UDP to syslog.
Create a class SysLog and put this method on the class side, or if you prefer an instance of a logger, put it on the instance side and create a constructor to pass in the IP address upon instance creation.
Syslog will then handle all the messy details of concurrency, files, log rollover, etc, using the standard facilities of the system rather than reinventing everything in Smalltalk. This is merely an example, not a final solution. - Ramon Leon
SysLog>>sendPriority: aPriority body: aBody toServer: anIPAddress | logServer client logHostIP | anIPAddress isEmptyOrNil ifTrue: [ ^self ]. logServer := Socket newUDP setPort: 514. [ client := Socket newUDP. [ logHostIP := ((anIPAddress split: '.') collect: [:e | e asInteger ]) asByteArray. client sendUDPData: aPriority , ' ' , aBody toHost: logHostIP port: logServer port ] ensure: [ client closeAndDestroy ] ] ensure: [ logServer closeAndDestroy ]