【发布时间】:2016-04-01 06:07:45
【问题描述】:
将 JUL 桥接到 SLF4J 的常用指令添加到 pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
添加到logback.xml:
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
添加到 Spring bean:
<bean class="org.slf4j.bridge.SLF4JBridgeHandler" init-method="install"/>
请注意,我不包括:
<bean class="org.slf4j.bridge.SLF4JBridgeHandler"
init-method="removeHandlersForRootLogger"/>
因为remove Tomcat's/JBoss's etc logging registrations。容器注册到 JUL 的一个原因 - 将控制台输出重定向到文件,但我不确定这是否属实。
Ceki(Log4j、SLF4J 和 Logback 的作者)doesn't recommend installingSLF4JBridgeHandler 相乘。但他没有解释为什么……
如果两个 webapp 同时在一个 Tomcat 中注册 SLF4JBridgeHandler.install() 会发生什么?他们有冲突吗?一个人会窃取其他人的所有日志消息吗?
com.sun.jersey.* 的 JAXB-RS 实现使用 JUL 日志记录,我希望每个应用程序重定向日志语句而不是系统 catalina.log
另一个奇怪的建议是将jul-to-slf4j.jar 放入容器的lib/ 目录中,并且不要包含在应用程序中。为什么?
主题参考:
- how do I setup slf4j to handle JUL logging in a HttpServlet?
- jul-to-slf4j for specific classes only
- How to use log4j to see into Jersey
- JUL to SLF4J Bridge
- http://hwellmann.blogspot.com/2012/11/logging-with-slf4j-and-logback-in.html
- Handler error in SLF4JBridgeHandler in tomcat logs
- http://blog.cn-consult.dk/2009/03/bridging-javautillogging-to-slf4j.html
- http://www.slf4j.org/legacy.html
- http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html
- http://logback.qos.ch/manual/configuration.html#LevelChangePropagator
- http://mailman.qos.ch/pipermail/logback-user/2012-August/003385.html
- http://gordondickens.com/wordpress/2012/07/30/enterprise-spring-framework-best-practices-part-3-xml-config/
- https://github.com/gordonad/enterprise-spring-best-practices/blob/master/02-application-architecture/src/main/resources/META-INF/spring/applicationContext-bootstrap.xml
【问题讨论】:
标签: tomcat jaxb slf4j logback java.util.logging