How to automatically rotate catalina.out daily or when it becomes bigger than 5M
1. Create this file/etc/logrotate.d/tomcat
2. Copy the following contents into the above file
/var/log/tomcat/catalina.out { copytruncate daily rotate 7 compress missingok size 5M }
About the above configuration:
- Make sure that the path /var/log/tomcat/catalina.out above is adjusted to point to your tomcat’s catalina.out
- daily - rotates the catalina.out daily
- rotate – keeps at most 7 log files
- compress – compressesthe rotated files
- size – rotates if the size of catalina.out is bigger than 5M
- Every night the cron daemon runs jobs listed in the /etc/cron.daily/ directory
- This triggers the /etc/cron.daily/logrotate file which is generally shipped with linux installations. It runs the command “/usr/sbin/logrotate /etc/logrotate.conf“
- The /etc/logrotate.confincludes all scripts in the/etc/logrotate.d/ directory.
- This triggers the /etc/logrotate.d/tomcat file that you wrote in the previous step.
- Run logrotate manually
/usr/sbin/logrotate /etc/logrotate.conf
- More logrotate options
man logrotate