Use SLF4J logging with Spring
Join the DZone community and get the full member experience.
Join For FreeLong story short, Spring uses Commons logging as a logging API, but chances are that you are using SLF4J in your project, so here what you’ll need to do to make Spring use SLF4J instead of commons logging.
1) Remove all commons-logging dependencies
In maven, you’ll have to exclude the commons-logging dependency from each Spring module, e.g.
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <artifactId>commons-logging</artifactId> <groupId>commons-logging</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <artifactId>commons-logging</artifactId> <groupId>commons-logging</groupId> </exclusion> </exclusions> </dependency>
2) Add SLF4J and jcl-over-slf4j
jcl-over-slf4j Will do the binding between Spring and SLF4J.
In this example I use logback as the logging api.
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.7.1</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.0.7</version> </dependency>
Published at DZone with permission of Aurelien Broszniowski, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments