Configure Log rotation of Tomcat

Create a configuration file for Tomcat logs in the /etc/logrotate.d/

/path/to/tomcat/logs/catalina.out {
copytruncate
daily
rotate 7
compress
missingok
size 100M
}

This configuration rotates catalina.out daily, keeps up to 7 rotated logs (rotate 7), compresses rotated logs (compress), ignores missing log files (missingok), and uses copytruncate to handle the log rotation without interrupting the logging process.

There is no need to set up a crontab schedule for the jobs in /etc/logrotate.d because they are already setup to execute every night in the cron daemon /etc/cron.daily.

  • /etc/cron.daily/ invokes the /etc/cron.daily/logrotate file, which executes the command /usr/sbin/logrotate /etc/logrotate.conf.
  • The /etc/logrotate.conf file includes all scripts from the /etc/logrotate.d/ directory. This runs the /etc/logrotate.d/tomcat file you created in the previous step.

    Test by launching log rotate manually

     /usr/sbin/logrotate /etc/logrotate.conf 

    Above log rotation happens on daily basis.