Log Back
Log Back
~
No revolution, only evolution. log4j is no longer being actively developed The same basic plumbing only done better. Faster, smaller, higher gas mileage, and generally more bang for the buck.
Modular architecture
id Components
logback-core Joran, Status, Context, pattern parsing logback-classic developer logging logback-access container (access) logging
logback-core
logback-classic
logback-access
Access Logging
Definition: Access log The log generated when a user accesses a web-page on a web server.
Logback-access integrates seamlessly with Jetty and Tomcat
Configuration example:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>logFile.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern> logFile.%d{yyyy-MM-dd}.log.zip </FileNamePatter> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> %d{HH:mm:ss,SSS} [%thread] %-5level %logger{22} - %msg%n </Pattern> </layout> </appender>
7
Logback-access configuration
<appender name="FILE" class="c.q.l.c.r.RollingFileAppender"> <File>access.log"</File> <rollingPolicy class="c.q.l.c.r.TimeBasedRollingPolicy"> <FileNamePattern> access.%d{yyyy-MM-dd}.log.zip </FileNamePattern> </rollingPolicy> <layout class="c.q.l.access.PatternLayout"> <Pattern">combined</Pattern"> </layout> </appender>
Another example:
<testShell name="test1"> <period>5 minutes</period> <!-- we need to configure a totally new test object for each run of the test --> <test class="com.wombat.myTest"> <DataSource class="c.w.JNDIDS"> <url>jndi://com.wombat/ds"</url> </DataSource> </test> <testShell> <testShell name="test2"> <period>60 seconds</period> <test class="com.wombat.myTest2"> <file>c:/wombat/foo.properties</file> </test> </testShell>
9
Joran is ideal for building frameworks which need to support arbitrary userdeveloped plug-ins.
10
11
Errors in action
Internal state available via StatusManager Exceptions and status messages accompanied by references, i.e. URLs, to external documents
12
JMX
Logback configuration can be reloaded via JMX Statistical results exposed via JMX
13
Documentation
Major area of effort. Complete manual, with over 150 pages of documentation, is available for free A short introduction to access logging with logback-access and Jetty javadoc, FAQ, error codes,
14
15
TurboFilters
<turboFilter class="c.q.l.classic.turbo.MDCFilter"> <MDCKey>userid</MDCKey> <Value>sebastien</Value> <OnMatch>ACCEPT</OnMatch> </turboFilter>
17
Parameterized logging
Integer entry = new Interger(50); logger.debug("The entry is "+entry+"."); can be optimized as: if(logger.isDebugEnabled()) { logger.debug("The entry is "+entry+"."); } or better yet: logger.debug("The entry is {}.", entry);
18
Markers are metadata for logging statements, coloring them for specialized processing
19
20
SiftingAppender (continued)
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator> <Key>userid</Key> <DefaultValue>unknown</DefaultValue> </discriminator> <sift> <appender name="FILE-${userid}" class="ch.qos.logback.core.FileAppender"> <File>${userid}.log</File>s <Append>false</Append> <layout> <Pattern>%d %level %mdc %logger - %msg%n</Pattern> </layout> </appender> </sift> </appender>
21
22
23
%logger
mainPackage.sub.sample.Bar
%logger{15}
m.s.sample.Bar
24
RollingFileAppender automatic file compression the background FileAppender and RollingFileAppender allow for the same log file to be written to by instances located in different JVMs 10 fold improvement in the speed of transporting logging events over the wire SMTPAppender now does TLS and SSL, subject line in outgoing email now based on PatternLayout
25
26
27
Finer threading model leading to less contention Better documentation Eclipse plug-in to visualize your logs
28
Conclusion
Logback is the unofficial successor of log4j, as the latter is no longer being actively developed.
29
Questions?
read the docs at http://logback.qos.ch/ study the code at http://svn.qos.ch write to us at [email protected] file a bug report at http://jira.qos.ch/ chat with us at irc.freenode.net#qos talk to us at +41 21 312 32 26
30