Usual instruction to bridge JUL to SLF4J is adding to pom.xml
:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
adding to logback.xml
:
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
adding to Spring beans:
<bean class="org.slf4j.bridge.SLF4JBridgeHandler" init-method="install"/>
Note that I am don't include:
<bean class="org.slf4j.bridge.SLF4JBridgeHandler"
init-method="removeHandlersForRootLogger"/>
because that remove Tomcat's/JBoss's etc logging registrations. One reason for containers to register to JUL - to redirect console output to file, but I am not sure if that true.
Ceki (author of Log4j, SLF4J and Logback) doesn't recommend installing SLF4JBridgeHandler
multiply times. But he didn't explain why...
What does happen if two webapp register SLF4JBridgeHandler.install()
simultaneously in single Tomcat? Do they conflict? Do one steal all log messages from other?
JAXB-RS implementation from com.sun.jersey.*
uses JUL logging and I want redirect log statements per application instead of system catalina.log
Another strange recommendation is to put jul-to-slf4j.jar
into lib/
dir of container and do not include with application. Why?
REFERENCE ON THE TOPIC:
- 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