7

This might be a simple question. How do you rotate Apache logs daily?

Mary
  • 81
  • 1
  • 1
  • 2
  • 1
    Why 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
  • 4
    In her defence, this is what I found by a simple Google search. – Kenzo Mar 02 '14 at 01:43

3 Answers3

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
  • 50,327
  • 19
  • 152
  • 213
  • 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
4

On a Linux system you would usually setup logrotate.

You could also use something like cronolog.

Zoredache
  • 128,755
  • 40
  • 271
  • 413
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,388
  • 2
  • 15
  • 16