Chapter 23 Logging in Tomcat
Tomcat uses Common Logging which supports a number of popular logging implementations. Common Logging allows developers to choose a logging configuration. Tomcat with the use of Common Logging can log hierarchically across various log levels without needing to rely on a particular logging implementation.
log4j
To build a cross-context detailed logging from within Tomcat’s code, use the simple log4j configuration. Follow these steps to setup a file named tomcat.log which has an internal Tomcat logging output to it:
1. Create a file called log4j.properties with the following content and save it into $CATALINA_HOME/lib.
log4j.rootLogger=debug, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/tomcat.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.org.apache.catalina=DEBUG, R
2. Download Log4J (v1.2 or later).
3. Save the log4j jar in $CATALINA_HOME/lib.
4. Build the commons-logging additional component using the extras.xml Ant build script.
5. Replace $CATALINA_HOME/bin/tomcat-juli.jar with output/extras/tomcat-juli.jar.
6. Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib.
7. Restart Tomcat.
java.util.logging
Tomcat replaces the default LogManager implementation with JULI. JULI supports per-web-application logging and configuration mechanisms of the standard JDK java.util.logging.
JULI is enabled by default and includes per classloader configuration. Logging can be configured at two layers, in the JDK’s logging.properties file and in each classloader using a logging.properties file.


