9.15.2006
Tomcat Logging in 15 Seconds
I had a good amount of trouble to get Tomcat logging the way I wanted to. Although I can't say for sure, by default it seemed to log errors anywhere from the console to at least three different types of logs in tomcat/logs. In any case, what I wanted was to get all of the logs in one place - since that's sort of the point of logs.
Here is the 15-second version of how to get Tomcat to log just about everything to one file:
Here is the 15-second version of how to get Tomcat to log just about everything to one file:
- Download commons-logging and put the commons-logging-1.1.jar file into your tomcat common/lib.
- Download log4j and put the log4j-1.2.13.jar file into your tomcat common/lib.
- (from Geoff Mottram) Save the following to a file log4j.properties in your tomcat common/classes. The only thing you should need to change is the line log4j.appender.R.File, to point to the file location you want.
#
# Configures Log4j as the Tomcat system logger
#
#
# Configure the logger to output info level messages into a rolling log file.
#
log4j.rootLogger=INFO, R
#
# To continue using the "catalina.out" file (which grows forever),
# comment out the above line and uncomment the next.
#
#log4j.rootLogger=ERROR, A1
#
# Configuration for standard output ("catalina.out").
#
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#
# Print the date in ISO 8601 format
#
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#
# Configuration for a rolling log file ("tomcat.log").
#
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern='.'yyyy-MM-dd
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
log4j.appender.R.File=/usr/local/tomcat/logs/tomcat.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
#
# Print the date in ISO 8601 format
#
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#
# Application logging options
#
#log4j.logger.org.apache=DEBUG
#log4j.logger.org.apache=INFO
#log4j.logger.org.apache.struts=DEBUG
#log4j.logger.org.apache.struts=INFO
