SLF4J over Spring

 SLF4J is a cleaner dependency and more efficient at runtime than commons-logging because it uses

compile-time bindings instead of runtime discovery of the other logging frameworks it integrates.

 

So to use SLF4J with Spring you need to replace the commons-logging dependency with the SLF4J-JCL bridge in all the Spring jars that it appear. Once you have done that then logging calls from within Spring will be translated into logging calls to the SLF4J API

 

pom.xml example:

 

<!-- Spring artifacts -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>${spring.version}</version>
  <exclusions>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>
…

<!-- Logging Artifacts -->
<dependency>
  <artifactId>slf4j-api</artifactId>
  <groupId>org.slf4j</groupId>
  <version>${slf4j.version}</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>${slf4j.version}</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>${slf4j.version}</version>
</dependency>

 

In this example i bind slf4j to  log4j. 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com