cronolog.pl

Cronolog rocks. It's an elegant alternative for logrotate and it's ilk. It's small app that takes a log file name template as an argument on the command-line and logfile data on STDIN. Cronolog then outputs the log data to a log file with the given name template. The template is a subset of the C strftime() format tokens. But I'm peculiar and even cronolog's meager installation needs are too much hassle for me, so I whipped up a copy in a couple dozen lines of Perl that can be cut and pasted into a new server. It supports an even smaller subset of tokens (those resulting from Perl's localtime()) and a couple features I preferred (like gzipping on closing the log file).

Typical use requires that you pipe the output into cronolog:

# stdout_log_producing_app | /usr/bin/chronolog.pl /var/log/stdout_log_producing_app.%Y%M%D.log

Which would produce log files such as "stdout_log_producing_app.20060930.log". I use it with lighttpd (which also rocks), to handle automatic log rotation (from lighttpd.conf):

$HTTP["host"] =~ "(^|.)bartgrantham.com$" {
    accesslog.filename          = "| /usr/bin/cronolog.pl /www/log/%Y%M%D.bartgrantham.com.access.log" }

One note: cronolog.pl determines if it needs to close the current log file and open a new one on each new line of log, so if an entire time period passes where the log file name would change, but there's no log data for that time period, no log file will be created. This may catch users off guard who are used to seeing log files for every single day (week, hour, whatever), blank or not.

Simple, but very effective. You can check it out HERE.