The Perfect Logrotate Config

December 6, 2011

One of the first things I do when setting up a new server somewhere is get all those damn log files rotating. Here’s the logrotate.conf block I use:

</p> <p>in /etc/logrotate.conf</p> <p>/path/to/any/log/file/*.log {<br /> daily<br /> dateext<br /> missingok<br /> rotate 365<br /> compress<br /> delaycompress<br /> notifempty<br /> copytruncate<br /> }</p> <p>

This is a slight modification of this configuration. Check out his explanation for all of the params.

The one I added that I think is essential is dateext, which appends dates instead of incrementing digits to the end of the log files, like so:

<br /> -rw-r--r-- 1 britg britg 64M 2011-10-24 06:49 production.log-20111024.gz<br /> -rw-r--r-- 1 britg britg 62M 2011-10-25 06:52 production.log-20111025.gz<br /> -rw-r--r-- 1 britg britg 56M 2011-10-26 06:29 production.log-20111026.gz<br /> -rw-r--r-- 1 britg britg 56M 2011-10-27 06:51 production.log-20111027.gz<br /> -rw-r--r-- 1 britg britg 57M 2011-10-28 06:51 production.log-20111028.gz<br />

Which, in my opinion, is much more parseable by our puny human brains.