SLF4J作为SpringFramework Logger [英] SLF4J as SpringFramework Logger

查看:121
本文介绍了SLF4J作为SpringFramework Logger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的一个项目中,我们使用SLF4J + logback进行日志记录. 是否可以将spring-framework配置为使用SLF4J而不是默认的log4j?

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默认使用apache commons日志记录(不是log4J),但是它只是一个包装器.您需要提供一个日志记录包以使其连接.多数人似乎建议使用另一种称为SLF4J的包装器替换apache commons,并将其连接到Log4J记录器.如果您认为这是登录Spring的一种真正方法,那么这里的说明应该对您有用:

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

有一种更简单的方法.我只是将logging.properties文件添加到WEB-INF类,并配置一些spring记录器和处理程序.基本的logging.properties文件位于此处: https ://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_java.util.logging_(默认)

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)

将每次出现的"manager"替换为"spring",将这两行添加到logging.properties示例中的任意位置:org.springframework.level = FINE org.springframework.handlers = 3spring.org.apache.juli.FileHandler

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

并删除以下内容: org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] .level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] .handlers = \ 3manager.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将在您的JDK中找到java.util.logging包,并且您将在$ CATALINA_BASE/conf下拥有spring框架日志(或者如果您不部署在tomcat中,请替换.properties中的路径文件).

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).

这篇关于SLF4J作为SpringFramework Logger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆