Summary: A nice and simple logging package.
Author: Göran Krampe & Magnus Kling
Owner: Göran Krampe (gk)
PackageInfo name: SimpleLog
RSS feed:


Nice and simple logging. There are eight messages for logging based on severity. These correspond to the eight levels defined in syslog:

7 - debug (Debug-level messages)
6 - info (Informational)
5 - notice (Normal but significant Condition)
4 - warning (Warning Condition)
3 - err (Error Condition)
2 - crit (Critical Conditions)
1 - alert (must be handled immediately)
0 - emerg (System is unusable)

The absolutely easiest way to log is like this:

SLLog warn: 'Oopsidaisy'

...this utilizes the class SLLog as a facade onto a singleton that you reach with "SLLog instance". You can also register an instance in global #Log like:

SLLog useGlobalLog: true

...and then you can use:

Log warn: 'Hey, nicer to type!'

We only need to include the actual message in the string, timestamp etc is added automatically.
You can also explicitly supply a "sender" object which can be anything you like, a symbol or a specific domain object even:

SLLog warn: 'Yowsa' sender: #email

SLLog uses printString on the sender when producing the log entry, so if you use domain objects - make sure they have a unique printOn: method defined so that you can distinguish them. See class side category "logging" and "logging shorthand" for the available log messages.

By default there is a single emitter registered that logs on Transcript, you can turn this default initialization off (for new SLLog instances) with:

SLLog useTranscript: false

You can also use addTranscript/removeTranscript, addMorphic/removeMorphic etc to add and remove known emitters:

SLLog removeTranscript; addMorphic; addSyslog

The above removes default transcript emitter and adds an SLLogMorph as an emitter (and opens it), and also a SLSyslogSender emitter that will log onto localhost using UDP on port 514, see its class comment for details.

You can set a threshold for the syslog levels that should be logged onto Transcript (levels <= threshold are logged) using:

SLLog transcript transcriptMaxLevel: 4

...and you can set a threshold for raising a notifier (debugger) using:

SLLog instance notifierMaxLevel: 3

...or set a global threshold for all emitters:

SLLog instance globalMaxLevel: 4

Global flushing of all emitters can be done using "SLLog flush" and should ideally be called regularly by some background process.

Finally take a look at SLLogFile for details on how to add it as an emitter to get logging onto file instead of Transcript.