Log4j based logging in Tomcat 6 - Part 2
15.06.2008 by Dirk OlmesIn my previous experiment I got Tomcat to log through commons-logging by following the Tomcat instructions.
While this works well for webapps that use commons-logging or log4j directly, webapps using JDK logging (e.g. Hudson) still clutter catalina.out. I remembered an approach that Holger was researching earlier: replace the standard JDK logging that comes preconfigured with Tomcat with a logger that pipes everything through slf4j.
Holger’s comment on the earlier blog post got me curious and I sat down and re-did his solution, this time using slf4j’s JCL bridge. The net effect is that all logging in Tomcat is done through slf4j (and thus through log4j). The only log messages that show up in catalina.out are those printed to System.out by the webapps but I think that’s negligible.
Just do the following easy steps to apply the logging Judo to Tomcat:
- In your Tomcat install dir, create a new folder named ext to hold additional jars.
- copy
jul-to-slf4j.jar
,slf4j-api.jar
,slf4j-log4j12.jar
andlog4j.jar
to the new ext folder - also put a
log4j.properties
into the ext folder - replace Tomcat’s
logging.properties
with a file that contains the following:
handlers= org.slf4j.bridge.SLF4JBridgeHandler
.level= INFO - patch
catalina.sh
to have theext
folder and all its jars on the CLASSPATH. - restart tomcat et voilĂ … no more logging to catalina.out
Comments
There are no comments yet.