In 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:

  1. In your Tomcat install dir, create a new folder named ext to hold additional jars.
  2. copy jul-to-slf4j.jar, slf4j-api.jar, slf4j-log4j12.jar and log4j.jar to the new ext folder
  3. also put a log4j.properties into the ext folder
  4. replace Tomcat’s logging.properties with a file that contains the following:
    handlers= org.slf4j.bridge.SLF4JBridgeHandler
    .level= INFO
  5. patch catalina.sh to have the ext folder and all its jars on the CLASSPATH.
  6. restart tomcat et voilà … no more logging to catalina.out

Log4j based logging in Tomcat 6

14.06.2008 by Dirk Olmes

My favourite annoyance in Tomcat is its logging to the ever-growing, never-rotated catalina.out.

The Tomcat logging setup instructions already contain a description what to do to make Tomcat log through log4. This is definitely a step in the right direction. Tomcat’s logging is properly separated from each webapp …

read more

Log4j and logger additivity

18.02.2008 by Dirk Olmes

Sometimes you want to write more than one logfile using logj4. This is possible by defining multiple appenders and specifying an appender for a certain logger like this:

log4j.appender.A1=org.apache.log4j.ConsoleAppender
....
log4j.appender.A2=org.apache.log4j.FileAppender
....

log4j.rootLogger=DEBUG, A1
log4j.logger.foo=DEBUG …
read more