Are there technical reasons to prefer using logback instead of log4j?

You should use SLF4J+Logback for logging.

It provides neat features like parametrized messages and (in contrast to commons-logging) a Mapped Diagnostic Context (MDC, javadoc, documentation).

Using SLF4J makes the logging backend exchangeable in a quite elegant way.

Additionally, SLF4J supports bridging of other logging frameworks to the actual SLF4J implementation you’ll be using so logging events from third party software will show up in your unified logs – with the exception of java.util.logging that can’t be bridged the same way that other logging frameworks are.

Bridging jul is explained in the javadocs of SLF4JBridgeHandler.

I’ve had a very good experience using the SLF4J+Logback combination in several projects and LOG4J development has pretty much stalled.

SLF4J has the following remaining downsides:

  • It does not support varargs to stay compatible with Java < 1.5
  • It does not support using both parametrized message and an exception at the same time.
  • It does not contain support for a Nested Diagnostic Context (NDC, javadoc) which LOG4J has.

Leave a Comment