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?

- 1,339
- 1
- 13
- 28

- 3,586
- 4
- 28
- 34
-
7Lucky you - the one I'm facing is 2.4 GIGABYTES :( – Bobby Jack Oct 15 '08 at 10:56
-
You could indicate whether you are really looking for an Apache module, or something that depends on the employed OS, such as logrotate or cron (already mentioned in the answers). That could help in replying to this - in my opinion - simple question. – Kariem Jan 14 '09 at 14:12
-
114GB here! Just over one year of entries. – Liam Aug 13 '10 at 09:37
-
I don't care about the logs and only want them to not grow unlimited: on WIN i used this to have max 7x15 mb logs. CustomLog "|bin/rotatelogs.exe -l logs/access.%A.log 15M" common – Tilo Feb 18 '14 at 18:48
-
scratch that, according to Bug 51081 https://issues.apache.org/bugzilla/show_bug.cgi?id=51081 rotatelogs will not overwrite – Tilo Feb 18 '14 at 19:12
-
23 GB here, on an old server... this should be a built-in feature – Micha Mazaheri Jul 15 '14 at 10:19
7 Answers
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.
-
16
-
1The downside to `logrotate` is that the logfile will continue to get written to the old filename until the process restarts. – MarkHu Jul 13 '15 at 19:00
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.

- 170,088
- 45
- 397
- 571

- 707
- 8
- 12
-
2when I used cronolog i encountered some issues when the log file reached 2GB of data. At that point there was no more logging and apache stalled until i removed/renamed the file. Since then I'm using logrotate and all is fine :) – maxgalbu Dec 13 '13 at 16:09
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.
-
Instead of dealing with trying to wrap quotes around the paths, I ended up shortening them, such as "c:/Progra~1/..." Also, it took awhile, but I eventually realized that I needed forward slashes in the paths. – Pedro Mar 10 '11 at 23:36
-
1Don't use backslashes in the path, it won't work! Alternatively, you can use [mod_log_rotate](http://www.sitebuddy.com/mod_log_rotate). Using this mod prevents also cmd.exe issues under Windows. – s106mo Jul 06 '11 at 16:32
-
1I did had some issues in Apache2.4 (Windows 8) for implementing log rotation. But fixed as below. In httpd.conf file add the following line ServerRoot "c:/Apache24" # Apache installation path #CustomLog "|bin/rotatelogs logs/access.log.%Y-%m-%d 86400" common # This above does not work, but when added .exe, it worked. CustomLog "|bin/rotatelogs.exe logs/access.log.%Y-%m-%d 86400" common – user292049 Sep 17 '14 at 15:17
-
Note that the `-n 4` "circular logs" option might not work as expected unless you add the `-L basename` option. – MarkHu Jul 13 '15 at 19:02
-
@alimack Can you give exact command for configuration rotatelog because am getting `unable to open log error` while i trying to start apache server. – Dharani Dharan Nov 24 '15 at 08:21
-
Unable to open file sounds like permissions - create a blank file with the correct name and check the write permissions. – alimack Jun 01 '16 at 11:05
-
This is good enough to me `ErrorLog '| "bin/rotatelogs.exe" "logs/error_%Y%m%d-%H%M%S.log" 10M'` – Abbas Apr 05 '18 at 09:11
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.

- 1
- 1

- 8,800
- 4
- 26
- 21
-
1I'm intrigued - what are the differences between this and the apache-supplied 'rotatelogs'? And why doesn't the apache manual mention logrotate (yet it does refer to cronolog)? – Bobby Jack Oct 15 '08 at 11:06
-
2Just an assumption: this could be because logrotate is not available on all system Apache is running. I have only used it on Linux installations, where it is used to rollover all of the system logs, and of course Apache's log files. – Kariem Jan 14 '09 at 14:20
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.
-
2Is there some rotatelogs option to delete old files or to overwrite them? – Tobia Sep 12 '14 at 08:32
-
-
1Not with date log names, I had to switch to indexed log names (`rotatelogs.exe -n 3 filepath 1M`) – Tobia Sep 27 '18 at 06:24
-
Using `rotatelogs -t ... 100M`, I find that the logfile is overwritten each time instead of appended to. Is there any way to make `rotatelogs` append to an existing log file? – not2savvy Sep 21 '22 at 07:42
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.

- 52,876
- 38
- 145
- 202

- 11
- 1
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.

- 1
- 1