for using Log4j Old. You know you’re old when open Bugzilla tickets make it to primary school Pretty much dead. Little active development Java 4 compatible -- no Java 5 or 6 classes used, like Reentrant locks or CopyOnWrite lists for appenders Easily baffled if you step outside the box RollingFileAppender can deadlock easily Or reconfiguring Appenders at runtime, @Ken :) Thursday, April 18, 13
Java introduced java.util.logging as a “standard” given log4j’s popularity It sucked in 1.4 and it sucks now Still better than println’s Advantage: Every VM since 1.4 has it Thursday, April 18, 13
developers Fixes many architectural issues More scalable (10x performance over log4j) Java code not written by prehistoric man “simply put, logback is just a better log4j” 3 packages: logback-core, logback-classic, logback-access logback-classic implements SLF4J natively Thursday, April 18, 13
a valid value java.lang.Exception: 99 is invalid at ch.qos.logback.demo.prime.PrimeAction.execute(PrimeAction.java:28) [classes/:na] at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) [struts-‐1.2.9.jar:1.2.9] at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) [struts-‐1.2.9.jar:1.2.9] at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [struts-‐1.2.9.jar:1.2.9] at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [servlet-‐api-‐2.5-‐6.1.12.jar:6.1.12] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) [jetty-‐6.1.12.jar:6.1.12] at ch.qos.logback.demo.UserServletFilter.doFilter(UserServletFilter.java:44) [classes/:na] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115) [jetty-‐6.1.12.jar:6.1.12] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:361) [jetty-‐6.1.12.jar:6.1.12] at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) [jetty-‐6.1.12.jar:6.1.12] at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) [jetty-‐6.1.12.jar:6.1.12] HELL YEAH Packaging information! (If enabled) Thursday, April 18, 13
doesn’t suck Uses modern Java More granular locks Summarization logback wasn’t an option when they started “Blitz4j is a logging framework built on top of log4j to reduce multithreaded contention and enable highly scalable logging without affecting application performance characteristics. ... Blitz4j makes runtime reconfigurations of log4j pretty easy. Blitz4j also tries to mitigate data loss and provides a way to summarize the log information during log storms.” Thursday, April 18, 13
and Java 6 improvements Log4j 1 and 2 are NOT 100% compatible. Also very good, on par with logback in performance Configurable with XML or JSON Up to 10x faster than log4j 1.2.x Thursday, April 18, 13
which allows any underlying framework to handle logging Allows framework-to-framework bridges Libraries become logging framework-agnostic Developed by log4j’s founder, Ceki Gülcü Thursday, April 18, 13
{}”, user.getId()); 2x slower than If user.getId() is cheap. Otherwise use the if guard for expensive operations. Both avoid .toString() costs Thursday, April 18, 13
you really need is slf4j-api (1.7.5+ preferred) Usually just have to include the proper framework-slf4j jar Can also spawn nasty dependency issues Data must flow in one direction, so choose yours and use dependency reports & exclusions to make it happen Thursday, April 18, 13
Error SLF4J: Found binding in [jar:file:/Users/xorlev/.grails/ivy-cache/org.grails/grails-plugin-log4j/jars/grails-plugin-log4j-2.1.1.jar!/org/slf4j/impl/ StaticLoggerBinder.class] | Error SLF4J: Found binding in [jar:file:/Users/xorlev/.grails/ivy-cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] | Error SLF4J: Found binding in [jar:file:/Users/xorlev/.grails/ivy-cache/org.slf4j/slf4j-nop/jars/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class] StackOverflowException log4j-over-slf4j & slf4j-log4j You aren’t a Java engineer until you’ve debugged SLF4J Thursday, April 18, 13
- %msg%n </pattern> </encoder> </appender> <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> <appender-ref ref="STDOUT" /> </appender> <root level="info"> <appender-ref ref="ASYNC" /> </root> </configuration> See https://github.com/Moocar/logback-gelf for a Graylog example Compose appenders Also works in log4j Thursday, April 18, 13
the SLF4J API makes it easy to log without knowing what your host VM looks like e.x. Tomcat / Storm Log4j2 is still in alpha/beta Thursday, April 18, 13