This might be a simple question. How do you rotate Apache logs daily?
Asked
Active
Viewed 1.2k times
3 Answers
9
Put the below lines into /etc/logrotate.d/httpd:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
daily
rotate 7
postrotate
/sbin/service httpd reload > /var/log/httpd/rotate 2>&1 || true
endscript
compress
}
quanta
- 52,423
2
It's perhaps a bit more elegant to use the Apache 'rotatelogs' program, imo.
Here's an example from one of my servers:
# Seo logs, rotated daily, on GMT clock
LogFormat "%h %t %D \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\" %{Host}i" seo
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/seo_log.%Y%m%d 86400" seo
You can also set a GMT offset for localtime, or specify rotation based on filesize.
'man rotatelogs'.
anastrophe
- 5,598