url:
http://tomcat.apache.org/faq/logging.html
http://marc.theaimsgroup.com/?l=tomcat-user&m=108330970225012&w=2
Having successfully configuring log4j and after doing some experiments with
Tomcat I've decided to step into the fray!
I will use 2 steps actually. Log4j for Tomcat and for Webapp. This was
tested using TC 5.0.19 on a Windows XP machine... yes, yes, please try to
forgive me now....
Tomcat Log4j Configuration for TC5 (tested on TC 5.0.19)
1. Obtain a recent Log4j jar file, i used log4j-1.2.8.jar
2. Place it in the TC common lib directory (<CATALINA_HOME>\common\lib)
3. Construct a log4j.properties file and place it in the TC common classes
directory (<CATALINA_HOME>\common\classes)
Sample log4j.properties used for my test (also attached):
log4j.rootLogger=ERROR, A1
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
log4j.logger.org.apache=DEBUG
4. Start TC5 and watch the logging kick in, a sample log file is attached.
WARNING: Performance will suffer
Tomcat Log4j for Webapp
The steps for this were stated in an earlier mail, its quite simple to do.
1. Place the log4j-1.2.8.jar in to the web-inf lib directory (/WEB-INF/lib)
1.1 I also placed the commons-logging.jar file in my web-app also as I am
quite confortable with commons logging.
2. Place your log4j.properties file in the web-inf classes directory
(WEB-INF/classes)
3. Configure your log4j.properties file as appropriate for your application.
As one person was enquiring about, i did activate the struts and file upload
logging in my webapp at one time to diagnose a problem, here is the config
i used:
log4j.rootLogger=ERROR, A1
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
# Print only messages of level DEBUG or above in the Apache commons and
struts file upload
log4j.logger.org.apache.commons.httpclient=DEBUG
log4j.logger.org.apache.commons.fileupload=DEBUG
log4j.logger.org.apache.struts.upload=DEBUG
WARNING: There will be a performance impact with the above logging! :)
WARNING: You can also activate TC logging as well from this log4j.properties
file so don't be too general with your package paths, as again turning on to
much logging with affect performance.
4. Instantiate your logging class in whatever way you see fit and run your
webapp and the logging will be activated.
If i've botched up my explanation let me know and I will correct it.
Regards,
Shane.