. .


ST 4U 213: Useful log4s APIs

March 30, 2012 12:23:07.457

Today's Smalltalk 4 You wraps up our look at log4s with an examination of some of the more useful API methods we've brushed over. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll look at some of the useful API methods for log4s that we've brushed over in the last few screencasts. To get started, we'll add a Transcript appender to the root logger (which was set up in the ini file):

"logging apis"
logger := EsLogManager getLogger: 'root'.

"Add a transcript appender programmatically, but set at a higher level"
level := EsLogManager getLevel: 'Error'.
pattern := EsPatternLayout new: 'ڴe{ISO8601}: [%level] %message'.
transcriptAppender := EsTranscriptAppender level: level layout:  pattern.
logger addAppender: transcriptAppender.

One of the things you can do is ask a logger for all of the appenders it has:

"get all appenders"
logger allAppenders.

Which gives us this, if we inspect that line of code:

all appenders

You can also get a specific appender by name:

"get the transcript appender"
logger getAppender: 'Transcript'

If we inspect that, we'll see the following:


Next we'll remove the Transcript appender. Note that we need to send the appender, not the name, as the argument. The VA 8.5 document is not clear about that:

"remove the Transcript appender"
logger removeAppender: transcriptAppender.

Now inspect the all appenders API again, and you should see:


Note that we're back where we started just the appender specified in the ini file. Finally, you can remove all appenders:

"remove all"
logger removeAllAppenders.

And inspecting the all appenders api yields:


And that about wraps it up for log4s. You should definitely peruse the documentation for more information

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u213-iPhone.m4v ( Size: 3360554 )]

posted by James Robertson

 Share Tweet This