Apache log rotation on Windows

Tags: 

The Apache web server, or more correctly Apache HTTP Server, is a wonderful program for serving web pages to the world. It can be a bit tricky to set up, however, especially if you want to run it on Windows as many of the configuration examples you'll find online are for UNIX rather than Windows.

One particularly tricky thing to get working correctly is log rotation, where instead of saving all of your site traffic logs into one file it can split it up by day, month, etc. As mentioned, this is tricky because you would assume that the program you use to do this would work with the regular Windows directory names, e.g. "C:\inetpub\logs", but it doesn't.

So.... what you actually have to do is something like this:

ErrorLog "|D:/Apache2/bin/rotatelogs.exe D:/Logs/error_%Y%m%d.log 3600"

Note that I'm using the forward-slash (UNIX-style) directory separator instead of the backslash (Windows-style) directory separator. That seems to be the trick that got it to work for me.

On that note, there appears to be a bug in the rotatelogs.exe program on Windows. When you configure the rotation to use any time fields (hour, minutes, seconds) they are given "0"'s instead of the the real values, so you end up with e.g. error_20060912_184405.log instead of error_20060912_000000.log. I've not been able to find any official record of this, nor does the documentation have any mention, but as I've found other people experiencing this problem I'm going to assume that it is a bug and live with per-day log files.