The following section describes how to programatically configure the FxLogging system.
Each appender got its own corresponding configuration object, instantiated and modified via a builder. This builder then provides a setter method for each configuration option, returning itself*1 enabling a fluent interface.
To finally get the actual configuration object, you have to call the end()
method,
which then can be directly passed to the appender (no need of storing the final result in a variable).
Of course you could also create a configuration object yourself and change its properties just as you are maybe used to be. But these builders are sooo cute, aren't they?! ;)
const traceConfigBuilder:TraceAppenderConfigurationBuilder = new TraceAppenderConfigurationBuilder(); traceConfigBuilder .level(LogLevel.WARN) .messageFormat("%d [%l] %c -- %m") .ringBufferEnabled(true) .whiteList([ /net\.sourceforge\.fxpotpourri\.fxlogging\.api\..*/ ]); LogCentral.instance.addAppender(new TraceAppender(traceConfigBuilder.end()));
*1 ... Until now, general configuration options are covered by a base class, therefore breaking a real fluent interfaces :(
Until now, every appender is "stream based", meaning it prints messages line by line (not like something semi structured as XML is). So it is fundamentaly to use patterns (passed as a String) to specify the output format.
Pattern | Description |
---|---|
%d | Date |
%l | LogLevel |
%c | Class |
%m | Message |
For example, the pattern %d [%l] %c -- %m
results in the log entry:
2009-05-04,00:01:19.724 [DEBUG] net.sourceforge.fxpotpourri.SomeClass -- my quick and dirty log message
You can of course write your own appender, you only have to implement the
IAppender
interface and add an instance of it to the ILogCentral
.
public class MyFlashyAppender implements IAppender { public function append(item:LogItem):void { trace("==> " + item.message + " <=="); } public function willAppend(level:LogLevel, source:Class):Boolean { return true; } }