SLF4J
   HOME

TheInfoList



OR:

Simple Logging Facade for Java (SLF4J) provides a
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
logging
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
by means of a simple
facade pattern The facade pattern (also spelled ''façade'') is a software-design pattern commonly used in object-oriented programming. Analogous to a facade in architecture, a facade is an object that serves as a front-facing interface masking more complex und ...
. The underlying logging backend is determined at runtime by adding the desired binding to the classpath and may be the standard Sun Java logging package java.util.logging,
Log4j Apache Log4j is a Java-based logging utility originally written by Ceki Gülcü. It is part of the Apache Logging Services, a project of the Apache Software Foundation. Log4j is one of several Java logging frameworks. Gülcü has since c ...
, Reload4j, Logback or tinylog. The separation of the client API from the logging backend reduces the coupling between an application and any particular logging framework. This can make it easier to integrate with existing or third-party code or to deliver code into other projects that have already made a choice of logging backend. SLF4J was created by Ceki Gülcü as a more reliable alternative to Jakarta Commons Logging framework. Research in 2013 on 10,000 GitHub projects found that the most popular Java library is SLF4J, along with
JUnit JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated ...
, with 30.7% of projects using it. In January 2021, it was ranked as the second most popular project according to mvnrepository.


Similarities and differences with log4j 1.x

*Five of log4j's six logging levels are used (ERROR, WARN, INFO, DEBUG, TRACE). FATAL has been dropped on the basis that inside the logging framework is not the place to decide when an application should terminate and therefore there is no difference between ERROR and FATAL from the logger's point of view. In addition, SLF4J markers offer a more general method for tagging log statements. For example, any log statement of level ERROR can be tagged with the "FATAL" marker. *Logger instances are created via the LoggerFactory, which is very similar in log4j. For example, private static final Logger LOG = LoggerFactory.getLogger(Wombat.class); *In ''Logger'', the logging methods are overloaded with forms that accept one, two or more values. Occurrences of the simple pattern in the log message are replaced in turn with the values. This is simple to use yet provides a performance benefit when the values have expensive toString() methods. When logging is disabled at the given level, the logging framework does not need to evaluate the string representation of the values, or construct a log message string that is never actually logged. In the following example, string concatenation and toString() method for the values count or userAccountList are performed only when DEBUG is enabled. LOG.debug("There are now " + count + " user accounts: " + userAccountList); // slower LOG.debug("There are now user accounts: ", count, userAccountList); // faster *Similar methods exist in ''Logger'' for isDebugEnabled() etc. to allow more complex logging calls to be wrapped so that they are disabled when the corresponding level is disabled, avoiding unnecessary processing. *Unlike
log4j Apache Log4j is a Java-based logging utility originally written by Ceki Gülcü. It is part of the Apache Logging Services, a project of the Apache Software Foundation. Log4j is one of several Java logging frameworks. Gülcü has since c ...
, SLF4J offers logging methods that accept markers. These are special objects that enrich the log messages. At present time, logback is the only framework which makes use of markers.


Similarities and differences with log4j 2.x

Apache log4j 2.x supports all slf4j features.Apache log4j 2.x slf4j Binding
/ref>


Version history


Version 2

Version 2 was released on 08/20/2022, for which there is
2.0.3 version release
Requires
Java 8 The Java (programming language), Java language has undergone several changes since Java Development Kit, JDK 1.0 as well as numerous additions of class (computer science), classes and packages to the standard library (computer science), li ...
or later. Significant feature additions: * Version 2.0.0 adds support for lambda syntax and uses a Fluent API. * Support for lambda syntax in passing messages to be logged. * Fluent API.


Version 1

Version details can be foun
in the manual
Significant versions include: * Version 1.7.36 releases are reproducible. * Version 1.7.35 slf4j-log4j12 module is replaced by slf4j-reload4j. * Version 1.7.33 adds support for reload4j via the slf4j-reload4j module. It is the latest stable release. Se

product page. * Version 1.7.5 yielded significant improvement in logger retrieval times. * Version 1.7.0 added support fo

requiring support for
Java 5 The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community P ...
or later. * Version 1.6 brought a no-operation implementation used by default if no binding found. * Version 1.1 releases in Maven repositorie
began 2006-09


See also

*
Java logging framework A Java logging framework is a computer data logging package for the Java platform. This article covers general purpose logging frameworks. Logging refers to the recording of activity by an application and is a common issue for development teams. ...


References


External links

* {{DEFAULTSORT:Slf4j Java (programming language) Software using the MIT license Free software programmed in Java (programming language) Log file formats