This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.2.1! |
Logging
Since Spring Framework 5.0, Spring comes with its own Commons Logging bridge implemented
in the spring-jcl
module. The implementation checks for the presence of the Log4j 2.x
API and the SLF4J 1.7 API in the classpath and uses the first one of those found as the
logging implementation, falling back to the Java platform’s core logging facilities (also
known as JUL or java.util.logging
) if neither Log4j 2.x nor SLF4J is available.
Put Log4j 2.x or Logback (or another SLF4J provider) in your classpath, without any extra bridges, and let the framework auto-adapt to your choice. For further information see the Spring Boot Logging Reference Documentation.
Spring’s Commons Logging variant is only meant to be used for infrastructure logging purposes in the core framework and in extensions. For logging needs within application code, prefer direct use of Log4j 2.x, SLF4J, or JUL. |
A Log
implementation may be retrieved via org.apache.commons.logging.LogFactory
as in
the following example.
-
Java
-
Kotlin
public class MyBean {
private final Log log = LogFactory.getLog(getClass());
// ...
}
class MyBean {
private val log = LogFactory.getLog(javaClass)
// ...
}