UnixServerAdmin

Server Administration & Management

How to rotate tomcat logs

# cat /etc/logrotate.d/tomcat

/usr/local/tomcat/logs/catalina.out {
compress
copytruncate
create 644 root root
rotate 30
size 1024M
}

/usr/local/tomcat/logs/localhost.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1024M
}

/usr/local/tomcat/logs/localhost.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 128M
}

/usr/local/tomcat/logs/host-manager.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1M
}

/usr/local/tomcat/logs/catalina.*.log {
compress
copytruncate
create 644 root root
rotate 30
size 1M
}

/usr/local/tomcat/logs/localhost_access_log.*.txt {
compress
copytruncate
create 644 root root
rotate 30
size 24M
}

daily :- rotates the catalina.out daily
rotate 7 :- keeps at most 7 log files
compress :- compresses the rotated files
size 10M :- rotates if the size of catalina.out is bigger than 10M
copytruncate :- Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one, It can be used when some program can not be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

January 17, 2012 Posted by | Tips & Tricks, Tomcat | , , | 1 Comment