Best way to rotate Apache log files

ApacheLoggingWebserverApache2apache2.4

Apache Problem Overview


I've got an Apache server that has one access log file that is topping 600MB. This makes it really hard to search the file or parse it.
What software or modules for Apache are available that will make a daily copy of my access file to make it more manageable?

Apache Solutions


Solution 1 - Apache

Have you looked at logrotate - this is probably the simplest, most widely available and well understood method of achieving this. It is highly configurable and will probably do 90% of what you need.

Solution 2 - Apache

I'm a big fan of Cronolog. Just install and pipe your logs through it. For daily log rotation, something like this would work:

ErrorLog  "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/error.log"
CustomLog "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/access.log" combined

Pretty handy, and once installed, easier (in my experience) than logrotate.

Solution 3 - Apache

The actual command for Windows, which is quite difficult to find online is:

CustomLog '|" "*Apache-Path/bin/rotatelogs.exe" 
    "**Apache-Path*/logs/backup/internet_access_%d-%m-%y.log" 86400' combined

Where the "internet_access" bit is the name you choose for your files, the 86400 is the number of seconds in one day. You need to change the Apache-Path to the relevant directory you've installed Apache to.

Solution 4 - Apache

logrotate

logrotate is probably the best solution. Use the file /etc/logrotate.conf to change the settings for all your logs. You van change weekly to daily so the logs are rotated every day. Also, you might want to add compress so the archives are compressed. If you don't care about the old logs, you can set rotate rotate 4 to something lower.

Solution 5 - Apache

CustomLog "|bin/rotatelogs /var/logs/logfile 5M" common

This configuration will rotate the logfile whenever it reaches a size of 5 megabytes.

ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M" 

This Would Be Best Way to Redirect Apache logs. No need to compile mod with httpd.

Solution 6 - Apache

rotatelog.exe or cronolog.exe on windows os. They are used in pipe command in http.conf Mod_log_rotate additional module for apache ONLY for access log rotation Logrotate ONLY for unix os.

Solution 7 - Apache

I have a module that does this for you without the need for external pipes etc :

http://www.poptart.org/bin/view/Poptart/ModAutorotate

I've tried to add it to the Apache modules collection but that seems to have been broken for a while now.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScott GottreuView Question on Stackoverflow
Solution 1 - Apacheserg10View Answer on Stackoverflow
Solution 2 - ApacheBrianView Answer on Stackoverflow
Solution 3 - ApachealimackView Answer on Stackoverflow
Solution 4 - ApacheEric HogueView Answer on Stackoverflow
Solution 5 - ApacheBipinView Answer on Stackoverflow
Solution 6 - ApachefabienView Answer on Stackoverflow
Solution 7 - ApacheJake ScottView Answer on Stackoverflow