Apache Tomcat – Logs rotate
To do log rotation for Apache, we can use a tool called logrotate.
Install in your machine if the command is not available. (install with #yum install logrotate).
Once you have the logrotate available in your Linux OS you can do the following:
1. Create a configuration file in the following path: /etc/logrotate.d/ . For example: /etc/logrotate.d/tomcat
2. Insert the following to the above file:
/<apache-location>/tomcat/logs/catalina.out { copytruncate daily rotate 7 compress missingok size 100M }
The following parameters are used for:
copytruncate – truncates the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one.
daily – rotate the log every day.
rotate – how many rotation logs to keep.
compress – If this value is written the log will be compressed.
missingok – If the log file is missing, go on to the next one without issuing an error message.
size #M – specify the size of the file before rotation.
You can run the rotation by adding a cron task.
For example, define it on the /etc/cron.hourly/, or
run this task manually by running /usr/sbin/logrotate /etc/logrotate.conf
Note: There is a very small time slice between copying the file and truncating it, so some logging data might be lost.
Categories: Apache, Linux, Middleware, Tomcat