How to configure Tomcat 5.0.x to use Java Logging
If you are using Java Logging
and a version of Tomcat
previous to Tomcat 5.5
, you have to use the deprecated Logger
declarations in your server.xml
or context.xml
files. The are deprecated in Tomcat 5.0
and have actually been removed in Tomcat 5.5
.
This is used to achieve separate log files for separate virtual hosts/web applications for example in your server.xml
you may have…
This will log the myapp.timestamp.log
file with all the contents of the webapp myapp
.
If you are using log4j
you can simply omit this and use the log4j.properties
(or log4j.xml
file) within your webapp to specify what the logging levels are and where to log to etc.
Java Logging
lacks this functionality. The Java Logging
configuration file logging.properies
is a JVM-wide properties file, and therefore traditionally you would have to use the Logger feature to get separate log file per webapp.
In Tomcat 5.5
Apache introduced juli
which is an implementation of the java logger that addresses the shortcomings of the logging.properties
file. i.e. with Tomcat 5.5
and above you can have a logging.properties
file within your webapp.
Now if you are tied to Tomcat 5.0
for your deploys you can actually add juli
logging to Tomcat 5.0
quite easily, here’s what you do…
Firstly download the Tomcat 5.5
core binary distribution.
From this apache-tomcat-5.5.36.zip
file extract the following two files…
apache-tomcat-5.5.36/bin/tomcat-juli.jar
intojakarta-tomcat-5.0.28/bin
andapache-tomcat-5.5.36/conf/logging.properties
intojakarta-tomcat-5.0.28/conf
Next we need to edit our catalina startup script to tell Java Logging
about the juli logging jar and properties file.
If you are using a flavour of linux/unix edit jakarta-tomcat-5.0.28/bin/catalina.sh
and under the cygwin section add the following…
and then after the classpath section add…
If you are using windows edit jakarta-tomcat-5.0.28/bin/catalina.bat
and after the setenv.bat section add…
and then after the classpath section add…
Et voilà that’s it!
All you need now in your webapp is add your own specific logging.properties
file to the WEB-INF/classes
directory of the war, an example of which…