introductioninstalling redhatunix commandsediting filesssh
sitemapapacheftptcp/ipmisc-notesresources

back  main  next
rotating apache log files with cronolog

You need to rotate apache's log files. Whether you rotate them daily, weekly, mothly etc. depends on how much traffic your site gets and the amount of data that you log. You can rotate apache log files a few different ways that I know of. See the apache documentation site and read the section on "Log Files" for details. I personally like a program called cronolog because t's highly configurable.

files needed
cronolog http://www.cronolog.org/download

installation instructions
Download the cronolog source code and:
# tar -zxvf cronolog-x.xx.tar.gz
This will decompress the archive and create a new directory "cronolog-x.xx".
Now cd into that directory.
# cd cronolog-x.xx
Now configure and install cronolog.
# ./configure
# make
# make install
This will install cronlog with the default options "/usr/local/sbin/cronolog"

using cronolog
You need to edit apache's config file to "pipe" the log files through cronolog. Using your favorite text editor open your "httpd.conf" file. locate the line that pertains to your main servers log files for a single hosted server or your individually set up log files if you are running more than one virtual host and modify to match example below.

unmodified example
CustomLog /usr/local/apache/logs/access.log combined
modified to use cronolog
CustomLog "|/usr/local/sbin/cronolog /logs/%m-%d-%Y-access.log" combined

The above example shows how to pipe your log files through cronolog. Using the variables "%m %d and %Y" will rotate the logs every day and name the file "01-10-2002-access.log" if it were Jan 10, 2002.

customizing cronolog
You can have cronolog rotate logs every day, week, month etc. You can put the logs into different folders that are named after the year, month, day etc by using the date variables in directory paths instead of file names.

named folder example
CustomLog "|/usr/local/sbin/cronolog /logs/%Y/%m/%d-access.log" combined

This will create "/logs/2002/01/10-access.log" for a log generated on Jan 10, 2002. Every month a new folder corresponding to that month will be created with access logs stamped with the day of the month at the beginning of the filename. Of course it will create a new folder for corresponding year changes as well.

If you only want to rotate logs once a month you can exclude using the "%d" day value

monthly rotation example
CustomLog "|/usr/local/sbin/cronolog /logs/%Y/%m-access.log" combined

This will create /logs/2002/01-access.log for a log generated in the month of Jan, 2002 etc.

reference material: http://www.cronolog.org   http://httpd.apache.org/docs
# man cronolog