www.LinuxHowtos.org

edit this article

rotating apache logfiles with cronolog

When your webserver has a couple of hits per day your logfile will increase to a limit when it becomes difficult to handle.

You can use a lot of ways to rotate your logfile automatically.

One of this possibilities is cronolog.

First, you have to install cronolog with the install tool for your distribution, which is quite painless.

Now you have to configure the apache logfile. Normally you already have a line like
CustomLog /some/path/transfer.log" combined

all you have to do is change the line to a line similar to this:
CustomLog "|/path/to/cronolog /some/path/transfer-%Y-%m-%d.log" combined

This would create a logfile for each day in the given path. A description of the % template is at the website for cronolog.
The files will be named after the template you give, if you want to have somewhere else or a different template for the filename, adjust it to your liking.

there is just one problem...


Normally you have a program to generate stats from your logfile. Now they are unable to find the logfile, because the name changes every once in a while.
But luckily, the cronolog has the feature to create a symlink to the current logfile. That way there is a static filename to the most recent log file.

Just make sure, you run the stats tool before the log gets rotated.
But you will loose the info between the last run and the new logfile. This can be corrected if you run the stats tool after the rotation on the last logfile once.

cronolog does provide a symlink there, too.
CustomLog "|/usr/sbin/cronolog -S /some/path/transfer.log -P /some/path/transfer.log.old
/some/path/transfer-%Y-%m-%d.log" combined

(line splitted for readability, it is one line)

All you have to change is the crontab for your stats tool to normally use the transfer.log and run once after the rotation on transfer.log.old
an example for awstats:
/path/to/awstats.pl -config=www.yourdomain.com -logfile /some/path/transfer.log.old


rate this article:
current rating: average rating: 1.1 (178 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back