Apache log rotation

10 02 2008

If 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.


Bookmark Apache log rotation  at del.icio.us Digg Apache log rotation

Trackbacks


10 02 2008
Apache log rotation - part 2
In part 1 of my article on Apache log rotation I talked about the advantages of using cronolog compared to logrotate.  The disadvantage to this is the cronolog has no archive compression or expiry built in, so I created a bash script to be run on as a dai
Weblog: LinuxJedi's /dev/null
Tracked: Feb 10, 15:07
24 02 2008
Apache log secrets
Previously I have shown my preferred methods of rotating log files here and here.  But Apache has a couple hidden gotchas and enhancements that can be made relating to logs.Firstly the logs are not in true chronological order, the time stamps are at the s
Weblog: LinuxJedi's /dev/null
Tracked: Feb 24, 19:44

Comments

Display comments as (Linear | Threaded)
No comments

Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA