The Toothpick Logo

Configuring Loggers

There are times when you'd like to save your Logger configuration and be able to re-install it quickly. There are times when you're trying to debug a packaged run-time image, and would like to be able to change what you're logging on the fly. For these and other reasons, Toothpick has an external configuration facility.

Toothpick allows you to define logger configurations in an external file, and be able to read the file into the image to re-configure the logging setup. The name of the file is 'toothpick.ini', and we're going to look at its' syntax here.

The configuration file

The Toothpick configuration file uses a standard format well-known from Windows ini files. The file is divided into sections, whereby each section describes the configuration options for one logger. Sections are delineated by a section header, which encloses the name of the logger in square brackets. Let's declare two loggers as an example:

[My first Logger]
[My second Logger]
[top]  [home]

Configuring the Logger

As the next step, we need to declare which type of Logger we want. Since our example is for a run-time image, we'll declare two FileLoggers, one which will output text, and another which will output XML. Obviously, we probably wouldn't want a TranscriptLogger in a packaged run-time image.

[My first Logger]
type=file
[My second Logger] type=file
To find out which Loggers are available in your image, you can display or inspect the following expression:
	Logger mappings keys
In a standard Toothpick installation, you'll have 'file' and 'transcript'.

FileLogger

As you may remember, the FileLogger requires yet another parameter, namely, the name of the file to which to log. Let's add that next.

[My first Logger]
type=file
fileName=MyLog.txt
[My second Logger] type=file fileName=MyLog.xml
[top]  [home]

Configuring the Formatter

Next, we'll configure the LoggingFormatter.

[My first Logger]
type=file
fileName=MyLog.txt
format=simple
[My second Logger] type=file fileName=MyLog.xml
format=xml
To find out which Loggers are available in your image, you can display or inspect the following expression:
	LoggingFormatter mappings keys
In a standard Toothpick installation, you'll have these four: 'simple', 'timestamp', 'xml', 'pattern'.

PatternLoggingFormatter

Let's add yet another Logger, this one using a PatternLoggingFormatter. Here, we also need to pass in the conversion pattern we want used.

[My first Logger]
type=file
fileName=MyLog.txt
format=simple
[My second Logger] type=file fileName=MyLog.xml format=xml
[My third Logger] type=file fileName=MyLog.xml format=pattern pattern=%p - %m
[top]  [home]

Configuring the LoggingPolicy

Configuring the LoggingPolicy is done similar to configuring the Logger and LoggingFormatter. To use the standard LoggingPolicy, all you need to provide is the category and threshold level of the policy.

[My first Logger]
type=file
fileName=MyLog.txt
format=simple
category=debug
threshold=info
[My second Logger] type=file fileName=MyLog.xml format=xml category=debug threshold=warn
[My third Logger] type=file fileName=MyLog.xml format=pattern pattern=%p - %m category=debug threshold=error

CompositeLoggingPolicy

To use a CompositeLoggingPolicy, set the value of 'policy' to 'composite', and provide a list of LoggingEventPatterns, one per line. Label each line uniquely, starting the label with 'filter'. See 'My Fourth Logger' below for an example.

[My first Logger]
type=file
fileName=MyLog.txt
format=simple
category=debug
threshold=info
[My second Logger] type=file fileName=MyLog.xml format=xml category=debug threshold=warn
[My third Logger] type=file fileName=MyLog.xml format=pattern pattern=%p - %m category=debug threshold=error [My Fourth Logger] type=file category=debug threshold=error format=timestamp filename=fourthlog.txt policy=composite filter1=perf.=debug filter2=debug.info filter3=ui.!error
[top]  [home]

Making custom Loggers configurable

^self needsMoreWork




Published Thursday, October 19, 2006
supported dialects