Log4J Configuration on Tomcat
How to turn on logging , lower logging level for a particular package
We use a log4j.properties file to configure logging on tomcat. Of course the log4j jar must be on the web applications classpath somewhere. Our jar is at CATALINA_HOME/webapps/ourcontext/WEB-INF/lib/log4j-1.2.12.jar
This is done on Linux through setting environment variable
CATALINA_OPTS=-Dlog4j.configuration=file:$CATALINA_HOME/conf/log4j.properties
export CATALINA_OPTS
On windows in the tomcat manager application under the java tab on the java options:
-Dlog4j.configuration=file:C:\opt\tomcat\conf\log4j.properties

The log4j.properties file
----------------------------------------
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE
log4j.rootCategory=INFO, CONSOLE, LOGFILE
#to enable package based logging on c3p0
log4j.logger.com.mchange.v2.c3p0=TRACE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=TRACE
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=logs/catalina.out
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.Threshold=TRACE
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
----------------------------------------end file
Note the log4j.appender.LOGFILE.Threshold must be as low as the lowest level you want to display, if it is higher then the statements will be filtered out.
