How to: Apache logs on a daily basis without logrotate

Updated . Posted . Visible to the public.

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

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.

Arne Hartherz
Last edit
Arne Hartherz
Keywords
httpd, configuration, timestamped, filename
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-04-20 11:20)