Bind the library with SLF4J
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 logging framework:
Binding Jar | Logging framework |
---|---|
slf4j-log4j12-1.7.12.jar | log4j version 1.2 |
slf4j-jdk14-1.7.12.jar |
java.util.logging (built in Java logging framework) |
slf4j-nop-1.7.12.jar |
NOP, silently discards all logging |
slf4j-simple-1.7.12.jar |
Simple implementation, which outputs all events to System.err |
slf4j-jcl-1.7.12.jar | Jakarta Commons Logging |
slf4j-android-1.7.12.jar | Android logging |
external implementations | Support for other logging frameworks, for example logback |
If no SLF4J binding is found in your application classpath, SLF4J defaults to a no-operation implementation displaying the following output in the console:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
If you want to use a specific logging framework in your application, you must include the specific logging library as well as the corresponding binding library in your classpath. SLF4J automatically detects the binding library and calls the corresponding underlying logging framework, so you only have to care for the upper layer.