Read more

How to: Apache logs on a daily basis without logrotate

Arne Hartherz
April 20, 2011Software engineer at makandra GmbH

If you want to have a new log file every day automatically, but avoid using logrotate, the CustomLog directive is your friend:

CustomLog "|/usr/sbin/rotatelogs /opt/www/awesome-project/log/access.%Y-%m-%d.log 86400" combined
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Adding that to your site's vhost will create log files that include the current date in their name, like access.2011-04-20.log, without any need to restart the web server every night (like logrotate does).

The last argument above is the rotation time in seconds -- here being 86400 (= 60 * 60 * 24) which causes a new log file each day at midnight. If you want to switch to new logs more frequently adjust accordingly, e.g. "... access.%Y-%m-%d_%H-%M.log 60" to have one log file for each minute.

When unsure, run "which rotatelogs" to check where the rotatelogs binary lives.


If you still want to have your old logs gzipped and cleaned up you should be able to configure logrotate to do this for you.

Also, this can be a solution for heavily loaded sites to avoid disk I/O due to log generation: Put your logfiles into a ram drive (/dev/shm on Debian/Ubuntu) and write them to the filesystem every few minutes with a custom shell script. Be advised that in that time frame a server crash (or reboot, if not taken care of) means that those in-memory log files are lost.

Posted by Arne Hartherz to makandra dev (2011-04-20 13:20)