Mercurial > hg > Blog
view content/Java/log4j-based-logging-in-tomcat-part2.md @ 102:94bbe517a174
Automated merge with ssh://xanthippe//home/dirk/Projekte/Blog
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Sat, 28 Mar 2020 02:43:15 +0100 |
parents | 4cd9b65e10e4 |
children |
line wrap: on
line source
Title: Log4j based logging in Tomcat 6 - Part 2 Date: 2008-06-15 Tags: logging, log4j, Tomcat Lang: en In my [previous experiment](|filename|./log4j-based-logging-in-tomcat-part1.md) 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](http://hudson.dev.java.net/)) 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](http://www.slf4j.org/). 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: 1. In your Tomcat install dir, create a new folder named ext to hold additional jars. 1. copy `jul-to-slf4j.jar`, `slf4j-api.jar`, `slf4j-log4j12.jar` and `log4j.jar` to the new ext folder 1. also put a `log4j.properties` into the ext folder 1. replace Tomcat's `logging.properties` with a file that contains the following:<br> handlers= org.slf4j.bridge.SLF4JBridgeHandler<br> .level= INFO 1. patch `catalina.sh` to have the `ext` folder and all its jars on the CLASSPATH. 1. restart tomcat et voilĂ ... no more logging to catalina.out