SLF4J (Simple Logging Facade for Java) is a logging library that aims to provide the simplest yet powerful facade for various logging systems in Java.
| Simple Logging Facade for Java | |
|---|---|
| Type of | |
| Developer | |
| Written on | |
| operating system | |
| Hardware platform | |
| Latest version | |
| License | |
| Site | |
SLF4J provides a simple, generic interface for logging systems that is implementation-independent.
An implementation can be selected and configured without changing the application code. Slf4J seamlessly integrates with the following implementations:
- NOP - an implementation that does not perform any actions
- Simple - using standard output for logs
- Java Logging API - logging system included in the JDK
- Log4J is one of the most famous logging systems for java
- JCL is a framework that also provides an adapter for logging
- LogBack is a logging system that is a development of log4j and is specifically designed for use with slf4j
In addition, SLF4J provides the ability to integrate components that are dependent on other logging systems (Log4J, JCL), substituting implementations that direct the logs of these systems to SLF4J.
Usage Example
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
class MyClass {
private Logger log = LoggerFactory . getLogger ( MyClass . class ); // 1. Declare a logger variable
...
log . debug ( "..." ); // 2. Output the string to debug
...
log . info ( "Some object: {}" , object ); // 3. We print in info a line with the argument substituted into it
...
log . error ( "Error during some job !!" , e ); // 4. We print an error in error, along with an exception
}
Notes
- ↑ The slf4j Open Source Project on Open Hub: Languages Page - 2006.
- ↑ Release 1.7.7 - 2014.