Below is information that will assist in configuring log retention for Tomcat.
Specific versions of Tomcat are required to configure the logging as per the directions in this guide.
- For version 8.5.x, you require 8.5.16 or newer
- For version 8.0.x, you require 8.0.45 or newer
- For version 7.0.x, you require 7.0.79 or newer
Source: https://bz.apache.org/bugzilla/show_bug.cgi?id=61105
The environment variable CATALINA_OUT
can be set to the destination you want the stdout
/stderr
to be written to. This logging doesn't appear to be needed if you also have catalina logging in the default logging configuration (see next section) - as the logs are duplicated. If you want to turn off the logging, you can set CATALINA_OUT
to /dev/null
.
This can be done by editing bin/setenv.sh
and adding the following to it. If it doesn't exist, create it.
export CATALINA_OUT="/dev/null"
The default logging properties are configured in conf/logging.properties
.
By adding maxDays
property you can limit the maximum number of days the logs are retained.
As an example, you would do the following to change the retention to 14 days:
Before:
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
After:
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.maxDays = 14
The server access logs are configured in conf/server.xml
.
You can add a maxDays
property to the org.apache.catalina.valves.AccessLogValve
configuration to limit the maximum number of days the log is retained.
As an example, you can do the following to change the retention to 7 days:
Before:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
After:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" maxDays="7"
pattern="%h %l %u %t "%r" %s %b" />