Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
Why the down vote? isn't this a valid questions? –  Mary Sep 1 '11 at 3: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 1 '11 at 3:46
2  
In her defence, this is what I found by a simple Google search. –  Kenzo Mar 2 at 1:43

3 Answers 3

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
}
share|improve this answer
    
See serverfault.com/questions/208006/… if you want to do this for more than one log directory. –  SPRBRN May 6 at 14:48

On a Linux system you would usually setup logrotate.

You could also use something like cronolog.

share|improve this answer

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'.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.