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 »

  1. Why you used “create” after “copytruncate”?
    An what you will do in next year?

    Comment by Kirill | June 26, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: