Tomcat log cutting (logrotate) is described in detail
- 2020-05-30 21:42:15
- OfStack
Tomcat log cutting
logrotate is a powerful system software, it has a 1 set of complete operating mode on the log file, such as: dump, mail and compression, etc., and the default logrotate added to cron (. / etc cron daily/logrotate) as a daily task execution. With logrotate automatically, I don't want to write my own log cutting scripts anymore.
Tomcat log catalina.out log cut as follows
# ls -lh /usr/local/tomcat/logs/catalina.out
-rw-r--r-- 1 www www 14M Aug 28 15:55 /usr/local/tomcat/logs/catalina.out
Configure logrotate to catalina.out log cutting
# cat /etc/logrotate.d/tomcat
/usr/local/tomcat/logs/catalina.out {
daily
rotate 5
missingok
dateext
compress
notifempty
copytruncate
}
Details of parameters:
Immediately truncate the log:
# logrotate --force /etc/logrotate.d/tomcat
The effect is as follows:
# ls -lh /usr/local/tomcat/logs/catalina.out*
-rw-r--r-- 1 www www 0 Aug 28 16:00 /usr/local/tomcat/logs/catalina.out
-rw-r--r-- 1 www www 1.1M Aug 28 16:00 /usr/local/tomcat/logs/catalina.out-20150828.gz
Thank you for reading, I hope to help you, thank you for your support of this site!