Configuring Log4j in Tomcat


Tomcat 6.0 uses Commons Logging throughout its internal code allowing the developer to choose a logging configuration. If we want to collect the detailed logging of tocat then we need to configure the external logging api like log4j with the tomcat. Following are the steps given for configuring log4j with tomcat.


1. Create a file called log4j.properties with the following content and save it into $CATALINA_HOME/lib. The sample file is as follows:-



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. Copy the latest log4j jar in the lib folder of the tomcat.


3.Build the commons-logging additional component using the extras.xml Ant build script which is part of teh Tomcat source bundle.


4. Replace /bin/tomcat-juli.jar with output/extras/tomcat-juli.jar.


5. Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib.


6. Restart Tomcat

                    

Copyright © 2012 VisualBuilder. All rights reserved