Skip to content

Instantly share code, notes, and snippets.

@jmurphyau
Last active January 18, 2019 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmurphyau/743c6d712f800640a35b0f4558f4dbd9 to your computer and use it in GitHub Desktop.
Save jmurphyau/743c6d712f800640a35b0f4558f4dbd9 to your computer and use it in GitHub Desktop.
tomcat-log-retention.md

Tomcat Log Retention

Below is information that will assist in configuring log retention for Tomcat.

Version Requirements

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

Turning Off catalina.out

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"

Default Logging Properties

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

Server Access Logs

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 &quot;%r&quot; %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 &quot;%r&quot; %s %b" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment