More logging in Tomcat 5.5+
PDFIf you’re trying to deploy a war under Tomcat and it isn’t going like it should be, the first thing you do is look in the console if you ran it from a console, or the log files in Tomcat’s homefolder otherwise. Now this provides you with some details as to why something went wrong, but there is the chance that de application itself is throwing exceptions unlogged which are caught by Tomcat. Those are not logged by default by Tomcat! To log these as well, you’ll need to utilize log4j.
There are two steps to get logs through log4j in Tomcat. One, add the following log4j.properties to {tomcat.home}commonclasses. Two, add the log4j and commons-logging jars to {tomcat.home}commonlib.
Here’s the content for log4j.properties.
1 2 3 4 5 6 7 | log4j.rootLogger=DEBUG, R log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.home}/logs/tomcat_log4j.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 |
Here are the jars that worked for me in Tomcat 5.5.27:
- commons logging 1.0.3
- log4j 1.2.15
There is one drawback to logging to a specific file though. I recon this is because Tomcat is trailing its own logfile into the console, which we have exempted by using our own logfile. The trouble is that Tomcat creates dynamic log files with a date, so we can’t easily just use that logfle for Tomcat to pickup on. Then again, maybe Tomcat is logging to a dynamic logfile as well as the console… I haven’t explored these possibilities.
For some more indepth information I found this article on Tomcat 5.5 logging, and here some of Apache’s own view on Tomcat logging.
Tags: java • log4j • tomcat