Skip to content
Andrew Byrd edited this page May 22, 2013 · 3 revisions

When working with logging in OTP or in Java in general, you may see many different names: Log4j, SLF4J, java.util.logging (JUL), jakarta.commons.logging (JCL), and Logback.

Log4J was the pio­neering frame­work that intro­duced con­fig­urable log­ging, before the Java standard library even had java.util.logging (JUL). SLF4J is a standardized API, which wraps many other logging implementations such as JCL, JUL, and Log4j. There are modules to connect SLF4J to those underlying logger implementations.

In its own code, OTP always calls the generic SLF4J API, but some of our dependencies are using other loggers. For example, Jersey uses JUL and Spring uses JCL. We need to reroute all these other logger calls to SLF4J if we want all the messages end up in the same place. OTP currently connects the SLF4J API to the Log4J logger implementation, then reroutes all logger calls by external dependencies to SLF4J. This way both OTP internal logging calls and dependency logging calls all end up at Log4J via SLF4J. Note that unlike all the other loggers, JUL cannot be rewritten to make use of SLF4J log levels because it is part of the Java standard library. Wiring JUL to SLF4J entails setting the JUL to a very fine logging level and doing the filtering at SLF4J, which can be wasteful.

In OTP, you are talking to the SLF4J API when you do something like:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class X {
    private static Logger LOG = LoggerFactory.getLogger(X.class);
    LOG.info("This is a message: {}", y);
    ...

Logback is the successor to Log4J. It speaks SLF4J natively, so it allows us to avoid some direct dependencies and wiring steps (the SLF4J API module and the SLF4J-Log4J wiring).

Add logback to POMs with:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.0.13</version>
</dependency>

References:

  1. A blog post on the various logging frameworks: http://mike.vanvendeloo.net/2011/05/06/logging-which-framework-to-choose-log4j-commons-logging-logback-slf4j
  2. Bridging Legacy APIs to SLF4J: http://slf4j.org/legacy.html
  3. Reasons to switch to Logback: http://logback.qos.ch/reasonsToSwitch.html
  4. JUL to SLF4J performance concerns: http://www.slf4j.org/legacy.html#jul-to-slf4j
  5. Logback Eclipse plugin for viewing/filtering logs: http://logback.qos.ch/beagle/index.html

The documentation on this wiki is outdated and should not be used

unless you are intentionally working with legacy versions of OpenTripPlanner. Please consult the current documentation at readthedocs

Clone this wiki locally