This might be a simple question. How do you rotate Apache logs daily?
Asked
Active
Viewed 1.2k times
7
-
1Why the down vote? isn't this a valid questions? – Mary Sep 01 '11 at 03:08
-
Mary - I can't speak for the downvoter, but my guess is that the downvote was because this is something that is easily discoverable by a simple Google search, and you showed no evidence that you had tried to research it yourself. – EEAA Sep 01 '11 at 03:46
-
4In her defence, this is what I found by a simple Google search. – Kenzo Mar 02 '14 at 01:43
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
- 51,413
- 19
- 159
- 217
-
See http://serverfault.com/questions/208006/logrotating-files-in-a-directories-and-its-subdirectories if you want to do this for more than one log directory. – SPRBRN May 06 '14 at 14:48
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,488
- 2
- 16
- 16