Friday, August 29, 2008

Using cronolog with Apache and AWStats

I've been meaning to do this for a long time, I've just never gotten around to it. My access_log file for Apache is currently somewhere around 638mb, and starts somewhere around 2 1/2 years ago. I've always wanted to name my log files with the year and month, I've just never gotten around to it. Today Phil Windley made mention of cronolog in his UTOSC presentation, and my first thought was, "hey, I've been meaning to do that!"

Installation was easy:

yum install cronolog

Then a quick change to my httpd.conf file:

ErrorLog "|/usr/sbin/cronolog /path/to/error_log_%Y-%m"
CustomLog "|/usr/sbin/cronolog /path/to/access_log_%Y-%m" combined

The %Y will give you a four-digit year, %m will give you a two-digit month. Restart Apache, make sure everything works. Then edit your awstats.*.conf file:


Slightly different date syntax, but you get most of it: %YYYY is a four-digit year, %MM is a two-digit month. AWStats also includes a -n after the date code, which refers to the number of hours back to go. %YYYY-2 would mean whatever the year was two hours ago.

Guess what? That's it! If you're like me, and you want small log files sorted by date, this is the way to go. Apache doesn't do it by itself, and in retrospect it's probably pretty trivial to set something up, but cronolog is already there, and setting it up is even more trivial. AWStats already has support for date-stamped files built-in, so it's just as easy to set it up.

Have fun with that one.

1 comment:

  1. Another way to do this:

    ErrorLog "|/usr/sbin/cronolog -S /path/to/error_log /path/to/%Y/%m/%d-error_log"
    CustomLog "|/usr/sbin/cronolog -S /path/to/access_log /path/to/%Y/%m/%d-access_log" Combined

    This will setup a symlink called access_log and error_log which each points to the most recent logfile and gets rotated automatically.


Comments for posts over 14 days are moderated