Setup log rotation for Apache access logs error logs using cronolog

If you want Apache log file to be saved on daily basis automatically. Cronolog is one of the best way to do it. Although Apache itself has rotatelogs for rotating activities, rotatelogs are not really creating log file everyday based on the calendar date. Rotatelogs creates and saves log files based on the rotation time or file size limits. For example we set up rotatelogs to rotate logs every 86400 seconds, technically is 24 hours, the start time is whenever you start ratatelogs, not from 00:00:00AM as what people normally assume. For how to setup rotatelogs, you can follow the instruction here: Rotate Apache logs on a daily basis using rotatelogs Cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. cronolog is intended to be used in conjunction with a Web server, such as Apache, to split the access log into daily or monthly logs. If you want your log files start from 0:00 to the exact end of a day 23:59, cronolog can handle that. 1. Install Cronolog. For Debian, Ubuntu, or Linux distributions using apt-get

apt-get install cronolog

For CentOS

yum install cronolog

2. Modify Apache’s configuration file. For access logs, replace the following line

CustomLog logs/access_log combined


CustomLog "cronolog /var/log/httpd/access_log.%Y-%m-%d" combined

For error logs, replace the following line

ErrorLog logs/error_log


ErrorLog "cronolog /var/log/httpd/error_log.%Y-%m-%d"

3. Check configuration syntax. Run the command below to check the configuration syntax.

/usr/sbin/apachectl configtest

Syntax OK

4. Restart Apache. The apachectl graceful command tells Apache that you want to restart the server gracefully without aborting any open connections. It automatically checks the configuration files before initiating the restart to make sure Apache doesn’t die.

/usr/sbin/apachectl graceful

If apachectl graceful doesn’t restart your server, there are a few other things you can try.

  • apachectl restart to restart the server. If the server is not running it is started. This command also runs a configuration test to make sure Apache won’t die when it restarts.
  • apachectl stop to stop the Apache server
  • apachectl start to start the Apache server (will throw an error message if Apache is running)
  • apachectl configtest to test the configuration file syntax.

For cronolog usage details, click here.

Common Windows boot/startup problems fix Rotate Apache logs on a daily basis using rotatelogs