Customizing What Gets Logged
This section discusses how to programmatically change what gets logged.control can be exerted at a global level, or within the scope of a single filter.
globalLevel
The ini file setting globalLevel specifies what level of logging to allow globally. The choices are as decribed in levelName in “Initializing the log4s Framework”. It is generally a good idea to leave this value set to All, and control what gets logged by specifying a level on individual log messages. Setting it to Off will disable all logging.
You can change the value of globalLevel to Warn with this piece of code:
EsLogManager singleton level: EsLevel Warn
Filters
This section discusses how to use predefined filters to change what gets logged programmatically.
classNameFilter
A class name filter allows you accept or reject a log entry based on the name of the class whose method did the logging. The classNameFilter can be useful if loggingEvents of the same level are sent to an Appender from different classes. This section discusses how to use filters to change what gets logged programmatically.
For example,
"Execute this code in a workspace.
 
Create a transcriptAppender.
Create a ClassNameFilter that will accept log messages.
If they are sent from an instance of class Foo
add the filter to the appender.
Add the appender to the root logger.
Test the logging."
 
| transcriptAppender classNameFilter |
 
EsLogManager removeAllLoggers.
EsLogManager rootLogger removeAllAppenders.
transcriptAppender := EsTranscriptAppender
level: EsLevel Warn
layout: (EsPatternLayout new: '%d %m').
classNameFilter := EsClassNameFilter
name: 'aClassNameFilter' "someCaseSensitiveFilterName"
classNameToFilter: 'Foo'
acceptOnMatch: true.
transcriptAppender addFilter: classNameFilter.
EsLogManager rootLogger addAppender: transcriptAppender deepCopy.
 
EsLogManager logWarn: 'Hi, Mom'
locationInfo: self currentClassAndMethod.
 
The above example will fail, correctly, to print the message when run from a workspace, because a workspace is not an instance of the class Foo. Note also that you must use the method #logWarn:locationInfo: so that the class name is set in the log message.
levelMatchFilter
A level match filter allows you accept or reject a log message based on the level of the message.
For example,
"Execute this code in a workspace.
 
Create a transcriptAppender.
Create a LevelMatchFilter that will accept log messages
only if they have the level Warn.
Add the filter to the appender.
Add the appender to the root logger.
Test the logging."
 
| transcriptAppender levelMatchFilter |
 
EsLogManager removeAllLoggers.
EsLogManager rootLogger removeAllAppenders.
transcriptAppender := EsTranscriptAppender
level: EsLevel Warn
layout: (EsPatternLayout new: '%d %m').
levelMatchFilter := EsLevelMatchFilter
name: 'aLevelMatchFilter' "someCaseSensitiveFilterName"
levelToMatch: EsLevel Warn
acceptOnMatch: true. "print the message if level = Warn"
transcriptAppender addFilter: levelMatchFilter.
EsLogManager rootLogger addAppender: transcriptAppender deepCopy.
 
EsLogManager logWarn: 'Warning'. "this will print"
EsLogManager logDebug: 'Debug'. "this will not print"
The above example will result in a line in the transcript for the 'warning' message. The transcript will look something like this. The first part of the line is the date and time including the milliseconds; the second part is the warning message itself.
2017-06-07 11:57:57,028 Warning
 
levelRangeFilter
A level range filter allows you accept or reject a log entry based on a range of message levels.
In the example below, the level range filter allows only logging events with a level between Info and Warn inclusive to print on the Transcript. Note that the two level names that specify the level range can be specified in any order.
For example,
"Execute this code in a workspace.
 
Create a transcriptAppender.
Create a LevelRangeFilter that will accept log messages
only if their level is in the specified range.
Add the filter to the appender.
Add the appender to the root logger.
Test the logging."
 
| transcriptAppender levelRangeFilter |
 
EsLogManager removeAllLoggers.
EsLogManager rootLogger removeAllAppenders.
transcriptAppender := EsTranscriptAppender
level: EsLevel Warn
layout: (EsPatternLayout new: '%d %m').
levelRangeFilter :=EsLevelRangeFilter
name: 'aLevelRangeFilter' "someCaseSensitiveFilterName"
lowLevel: EsLevel Debug
highLevel: EsLevel Warn
acceptOnMatch: true.
transcriptAppender addFilter: levelRangeFilter.
EsLogManager rootLogger addAppender: transcriptAppender deepCopy.
 
EsLogManager logWarn: 'Warning - this will print'.
EsLogManager logInfo: 'Info - this will not print'.
The above example will result in a line in the transcript for the 'warning' message. The transcript will look something like this. The first part of the line is the date and time including the milliseconds; the second part is the warning message itself.
2017-06-07 11:57:57,028 Warning - this will print
stringMatchFilter
A string match filter allows logging entries to be accepted or rejected if the message matches a particular string, which can be case-insensitive.
For example,
"Execute this code in a workspace.
 
Create a transcriptAppender.
Create a stringMatchFilter that will accept log messages
only if their level is in the specified range.
Add the filter to the appender.
Add the appender to the root logger.
Test the logging."
 
| transcriptAppender stringMatchFilter |
 
EsLogManager removeAllLoggers.
EsLogManager rootLogger removeAllAppenders.
transcriptAppender := EsTranscriptAppender
level: EsLevel Warn
layout: (EsPatternLayout new: '%d %m').
stringMatchFilter := EsStringMatchFilter
name: 'stringMatchFilterName' "someCaseSensitiveFilterName"
stringToMatch: 'Mo'
acceptOnMatch: true
ignoreCase: true.
transcriptAppender addFilter: stringMatchFilter.
EsLogManager rootLogger addAppender: transcriptAppender deepCopy.
 
EsLogManager logWarn: 'Hi Mom - this will print'.
EsLogManager logWarn: 'The moon is full - this will print'.
EsLogManager logWarn: 'Hi, Dad - this will not print'.
The above example will result in a line in the transcript for the first two 'warning' messages. The transcript will look something like this. The first part of the line is the date and time including the milliseconds; the second part is the warning message itself.
 
2017-06-07 11:57:57,301 Hi Mom - this will print
2017-06-07 11:57:57,303 The moon is full - this will print
 
Last modified date: 12/20/2017