Skip to content

Serverconfigs

Mario Trojan edited this page Jan 29, 2024 · 6 revisions

Logrotate + Tomcat

Default situation

With the default configuration under Ubuntu 20.04, the following log files are written into /var/log/tomcat9:

  • catalina.out
  • catalina.<date>.log
  • localhost_access_log.<date>.log
  • localhost.<date>.log

Tomcat does not cleanup old files, but logrotate does. There is a configuration in /etc/logrotate.d/tomcat9, but this will only affect catalina.out by default.

Necessary changes

Part 1: Prevent tomcat9 from writing dates into filenames

Go to /etc/tomcat9/server.xml

Replace default values: <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" />

By this: <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="combined" rotatable="false" prefix="access_log" />

Part 2: Use logrotate to manage all kinds of files

In /etc/logrotate.d/tomcat9: Add the new filename schema to the first line: /var/log/tomcat9/catalina.out { => /var/log/tomcat9/catalina.out /var/log/tomcat9/access_log {

Note: These settings are still experimental and will be rolled out on the servers as soon as they are tested on our development machines.

Clone this wiki locally