3.9. Rotating Logs on the First of the Month
Problem
You want to close the previous month’s logs and open new ones on the first of each month.
Solution
The Apache distribution doesn’t come with a script that does this, but there is a free program that provides this and many other useful features. It is called Cronolog, and may be obtained from http://cronolog.org.
Obtain and install Cronolog, and then place the following in your configuration file:
CustomLog "|/usr/bin/cronolog /www/logs/access%Y%m.log" combined
Discussion
Cronolog has been around for a long time, and provides many of the features that people wished were available in the standard rotatelogs utility. Over the years, rotatelogs has improved, but Cronolog has a number of other useful features that are of interest to sites with rapidly growing logfiles.
One of these is the ability to automatically rotate logfiles by day, week, month, or year, based on the format of the filename specified in the CustomLog directive.
In the example given, the logfile is rotated at the start of a
new month, because the logfile name given contains only the year and
month variables (%Y and %m, respectively).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access