Lets assume that we want to manage the limit of the log file of Tomcat Application Server

1. Make sure you have installed logrotate package

2. Create a file /etc/logrotate.d/tomcat with the following contents

/var/log/tomcat/catalina.out {
rotate 7
size 5M

Configuration Explantation

/var/log/tomcat/catalina.out is the path of the log file
daily is when to do this action
rotate 7 is to keep at most 7 history log files 
compress  is if you want to compress the old log files
size 5M rotates if the size of catalina.out is bigger than 5M

How it works

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.conf includes all scripts in the /etc/logrotate.d/ directory.
This triggers the /etc/logrotate.d/tomcat file that you wrote in the previous step.


By admin