Reputation: 5787
In one of our projects we are using SLF4J + logback for logging. Is it possible to configure spring-framework to use SLF4J instead of its default log4j?
Upvotes: 0
Views: 556
Reputation: 1010
Spring uses apache commons logging by default (not log4J), but its just a wrapper. You need to provide a logging package for it to connect to. Most people seem to recommend replacing apache commons with a different wrapper called SLF4J, and connecting it to the Log4J logger. If you feel that is the one true way to log in spring, the instructions here should work for you: http://spring.io/blog/2009/12/04/logging-dependencies-in-spring
There's an easier way. I just add a logging.properties file to WEB-INF classes, and configure some spring loggers and handlers. A basic logging.properties file is here: https://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_java.util.logging_(default)
Replace every occurrence of the word "manager" with "spring", add these two lines anywhere in the logging.properties example: org.springframework.level=FINE org.springframework.handlers=3spring.org.apache.juli.FileHandler
And delete these ones: org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \ 3manager.org.apache.juli.FileHandler
Apache commons will find the java.util.logging package in your JDK, and you'll have the spring framework logs under $CATALINA_BASE/conf (or if you're not deploying in tomcat, replace the path in the .properties file).
Upvotes: 1