SLF4J

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and log4j. SLF4J allows the end-user to plug in the desired logging framework at deployment time. Note that SLF4J-enabling your library/application implies the addition of only a single mandatory dependency, namely slf4j-api-1.7.13.jar..

Before you start using SLF4J, we highly recommend that you read the two-page SLF4J user manual.

Note that SLF4J-enabling your library implies the addition of only a single mandatory dependency, namely slf4j-api.jar. If no binding is found on the class path, then SLF4J will default to a no-operation implementation.

In case you wish to migrate your Java source files to SLF4J, consider our migrator tool which can migrate your project to use the SLF4J API in just a few minutes.

In case an externally-maintained component you depend on uses a logging API other than SLF4J, such as commons logging, log4j or java.util.logging, have a look at SLF4J's binary-support for legacy APIs.


Many Projects are using SLF4J currently..

Binding with a logging framework at deployment time

As mentioned previously, SLF4J supports various logging frameworks. The SLF4J distribution ships with several jar files referred to as "SLF4J bindings", with each binding corresponding to a supported framework.

  • slf4j-simple-1.7.13.jar: Binding for Simple implementation, which outputs all events to System.err. Only messages of level INFO and higher are printed. This binding may be useful in the context of small applications.
  • slf4j-log4j12-1.7.13.jar: Binding forlog4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.
  • slf4j-jdk14-1.7.13.jar: Binding for java.util.logging, also referred to as JDK 1.4 logging
  • slf4j-nop-1.7.13.jar: Binding for NOP, silently discarding all logging.
  • slf4j-jcl-1.7.13.jar: Binding for Jakarta Commons Logging. This binding will delegate all SLF4J logging to JCL.
  • logback-classic-1.0.13.jar (requires logback-core-1.0.13.jar): Native implementation There are also SLF4J bindings external to the SLF4J project, e.g. logback which implements SLF4J natively. Logback's ch.qos.logback.classic.Logger class is a direct implementation of SLF4J's org.slf4j.Logger interface. Thus, using SLF4J in conjunction with logback involves strictly zero memory and computational overhead.

If you are providing an Java library for large end users consumption, it's good idea to set your project to depend on slf4j-api only, and then let your user choose any logger implementation at their development or runtime environment. As end users, they may quickly select one of option above and take advatage of their own favorite logging implementation features.

More About SLF4J

     »  SLF4J binding with simple (slf4j-simple)

     »  SLF4J binding with Log4j (slf4j-log4j)

     »  SLF4J binding with JDK14 (slf4j-jdk14)

     »  SLF4J binding with Logback