Simple Logging Facility for Java ( SLF4J ) provides the Java logging API via a simple facade pattern. The underlying backend logging is determined at runtime by adding the desired bindings to the classpath and possibly the Java Java logutj.logging, log4j logging, logback or standard minilog packets.
Separation of client APIs from backend logging reduces coupling between applications and certain recording frameworks. This can simplify integration with existing code or third parties or to transmit code to other projects that have made backend logging options.
SLF4J was created by Ceki GÃÆ'ülcÃÆ'ü as a more reliable alternative to the Jakarta Commons Logging framework. Research in 2013 on 10,000 GitHub projects found that Java's most popular library is SLF4J, with 30.7% of projects using it.
Video SLF4J
Similarities and differences with log4j 1.x
- Five of the six log4j logging levels used (ERROR, WARN, INFO, DEBUG, TRACE). FATAL has been dropped on the grounds that within the logging framework is not a place to decide when the application should be stopped and therefore there is no difference between ERROR and FATAL from the logger point of view. Additionally, the SLF4J marker offers a more general method for logging tagging reports. For example, an ERROR level log statement can be tagged with a "FATAL" marker.
- Logger events are generated through
LoggerFactory
, which is very similar in log4j. As an example, - In Logger , overloaded logging methods with forms that accept one, two or more values. The appearance of simple patterns
{}
in the log messages is replaced alternately with values. It's easy to use but provides performance benefits when its value has an expensivetoString ()
method. When logging is disabled at a given level, the logging framework does not need to evaluate the string representation of the values, or build log message strings that are never actually logged. In the following example, the string concatenation method andtoString ()
for thecount
oruserAccountList
values ââare only performed when DEBUG is enabled.
- A similar method is in Logger for
isDebugEnabled ()
etc. to allow more complex logging calls wrapped so they are disabled when the appropriate level is disabled, avoid unnecessary processing. - Unlike log4j, SLF4J offers a recording method that accepts markers. This is a special object that enriches log messages. Currently, logback is the only framework that utilizes bookmarks.
Maps SLF4J
Similarities and differences with log4j 2.x
Apache log4j 2.x supports all the features of slf4j.
See also
- Java recording framework
References
External links
- Official website
Source of the article : Wikipedia