. .

st4u

ST 4U 209: Creating a new Logger with log4s

March 21, 2012 7:53:08.913

Today's Smalltalk 4 You delves deeper into log4s, looking at how to create a new logger in code (as opposed to in the ini file). 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:

log4s.

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 create a new logger in VA Smalltalk, programmatically. Recall that the way we set up the standard (root) logger to write to a file was via the ini file for the VA image:


[log4s]
debugEnabled=true
quietMode=false
globalLevel=All
dailyRollingFileAppender =(fileAppender, root, vaLog.log, false, Info, EsPatternLayout,
 'ڴe{ISO8601}: [%level] %message', true, topOfDay )


What we need to do today is create a brand new logger:


"create a new logger using the Transcript"
myLogger := EsLogManager createLogger: 'myLogger'.
level := EsLogManager getLevel: 'All'.
pattern := EsPatternLayout new: 'ڴe{ISO8601}: [%level] %message'.
transcriptAppender := EsTranscriptAppender level: level layout: pattern.
myLogger addAppender: transcriptAppender.

That creates a brand new logger using the name 'myLogger' - to use it, we now need to specify that specifically (without being specific, we get the root logger):


"use the root logger"
EsLogManager warn: 'This is a warning!'.

"use the new logger"
(EsLogManager getLogger: 'myLogger') warn: 'This is another warning!'.


The first warning goes to the file logger set up on root; the second one goes to the Transcript using the new logger.

We'll delve more into the settings and filtering options for log4s in a future screencast

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: , , ,

Enclosures:
[st4u209-iPhone.m4v ( Size: 4192505 )]

posted by James Robertson

 Share Tweet This