5

My tomcat logs currently has a mix of log messages in different formats. So I am trying to set up SLF4J using JUL-to-SLF4J bridge.

I was initially getting log messages like

May 23, 2013 7:57:17 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 23, 2013 7:57:17 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.29
2013-05-23 19:57:47,224 [localhost-startStop-1] Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
2013-05-23 19:57:47,246 [localhost-startStop-1] Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]

I followed a blog from here.. http://hwellmann.blogspot.com/2012/11/logging-with-slf4j-and-logback-in.html

Am using the following jars for SLF4J: jul-to-slf4j-1.7.5.jar, slf4j-api-1.7.5.jar

and in logging.properties

handlers = org.slf4j.bridge.SLF4JBridgeHandler

I am currently not getting mixed messages but on start of tomcat. It is not printing the tomcat format, but it throws Handler error

Below is a snippet of the logs

Handler error
java.lang.ClassNotFoundException: org.slf4j.bridge.SLF4JBridgeHandler
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:521)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:464)
    at org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:288)
    at java.util.logging.LogManager$2.run(LogManager.java:278)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:276)
    at java.util.logging.LogManager.getLogManager(LogManager.java:259)
    at java.util.logging.Logger.<init>(Logger.java:245)
    at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:1104)
    at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:1101)
    at java.util.logging.LogManager$1.run(LogManager.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.logging.LogManager.<clinit>(LogManager.java:176)
    at java.util.logging.Logger.getLogger(Logger.java:307)
    at com.sun.jmx.remote.util.ClassLogger.<init>(ClassLogger.java:55)
    at sun.management.jmxremote.ConnectorBootstrap.<clinit>(ConnectorBootstrap.java:739)
    at sun.management.Agent.startAgent(Agent.java:147)
    at sun.management.Agent.startAgent(Agent.java:289)
***startInternal() called
***startInternal() JoranConfigurator

I have been on this problem for days, tried a lot of combinations, but couldnt find any luck with it.

Thanks in Advance!

4

1 回答 1

3

只需为 Linux 创建或编辑 CATALINA_HOME/bin/setenv.sh:

CLASSPATH=$CATALINA_HOME/bin/jul-to-slf4j-1.7.5.jar:\  
$CATALINA_HOME/bin/slf4j-api-1.7.5.jar

或用于 Windows 的 CATALINA_HOME\bin\setenv.bat:

set CLASSPATH=%CATALINA_HOME%\bin\jul-to-slf4j-1.7.5.jar;^
%CATALINA_HOME%\bin\slf4j-api-1.7.5.jar
于 2013-09-28T16:36:49.673 回答