Apache log rotation
10 02 2008If you are using a bog standard Linux setup you are probably using Logrotate to do a daily rotate of your logs. This works really well although I have come across a couple of gotchas before such as Apache writing to the .1 file instead of the new log file (I'm guessing the reload didn't work).
I now personally use a piped log via. cronolog which fixes the above problem and has the added advantage of being able to rotate logs whenever you like without having to do anything to Apache.
One setup I have worked on generated over 2GB of access log files per day per server using Apache 2.0.x, this meant that with a daily log rotation Apache would die soon after it hit 2GB. I suggested the use of cronolog, and with this we did:
CustomLog "|/usr/sbin/cronolog -e /var/log/httpd/access_log_%Y-%m-%d-%H.log" combined ErrorLog "|/usr/sbin/cronolog -e /var/log/httpd/error_log_%Y-%m-%d-%H.log"
So every hour this will automagically create a log file in the form access_log_2008_02_10_08.log for all accesses today 8AM - 9AM. This also makes it easier to debug using the error logs as it makes them a lot smaller so you can find an access at a certain time stamp quickly
You can even have cronolog split into separate dated folders:
ErrorLog "|/usr/sbin/cronolog -e /var/log/httpd/%Y/%m/%d/error_log_%H.log"
Will produce logs in folders such as /var/log/httpd/2008/02/08/error_log_08.log for an 8AM - 9AM log.
I shall follow this up later with a simple way of expiring old logs.
Categories : Apache
Trackbacks : 2 Trackbacks »




Tracked: Feb 10, 15:07
Tracked: Feb 24, 19:44