问题描述
在我们的一个项目中,我们正在使用SLF4J + logback进行记录. 是否可以配置Spring-Framework使用SLF4J而不是其默认log4j?
推荐答案
Spring使用Apache Commons记录默认情况下(而不是Log4J),而只是包装器.您需要提供一个记录包,以便它可以连接到.大多数人似乎建议使用名为SLF4J的不同包装器代替Apache Commons,并将其连接到Log4J Logger.如果您觉得这是登录春季的一种真正方法,则此处的说明应该适合您: http://spring.io/blog/2009/12/04/logging-depperencies-in-spring
有一种更简单的方法.我只是在Web-Inf类中添加一个logging.properties文件,并配置一些春季记录器和处理程序.基本的logging.properties文件在这里:html#using.java.util.util.util.logging_(defeat_defte_(deffault) ://tomcat.apache.org/tomcat-6.0-doc/logging.html#used_java.util.util.logging_(默认)
用" spring"替换每个单词"经理"一词,在登录中添加以下两行. org.springframework.handlers = 3spring.org.apache.juli.filehandler
并删除这些: org.apache.catalina.core.containerbase.[catalina].[localhost].[/manager] .level = info org.apache.catalina.core.containerbase.[catalina].[localhost].[/manager]. 3manager.org.apache.juli.filehandler
apache commons将在JDK中找到Java.util.logging包,并且您将在$ catalina_base/conf下使用弹簧框架日志(或者如果您不在tomcat中部署,请替换.properties中的路径文件).
问题描述
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?
推荐答案
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).