Posted: 2015-03-15 00:15:00
By default, access requests, errors, and some other segmented data, is written into separate log files, which are not rotated by Apache.
These log files grow in size as new log data is appended with each additional access request made. And it’s left to the user to (once in a while) stop Apache, and rotate (i.e., rename) or delete the log files, so everything starts from size-zero again.
Rotating logs is important because once log file sizes reach the 500MB to 1GB range, this can create issues for: Apache (e.g., slow downs), for file editors/readers (such as Notepad), and also for some statistics/analytic programs (such as AWStats).
The standard logging configuration can usually be found in each website’s HTTP and SSL VirtualHost files:
ErrorLog "C:/WampDeveloper/Logs/Websites/www.example.com/http.errorlog.txt" CustomLog "C:/WampDeveloper/Logs/Websites/www.example.com/http.accesslog.txt" combinedtrueout_host CustomLog "C:/WampDeveloper/Logs/Websites/www.example.com/http.deflatelog.txt" deflate
The last part of each line is the name of the log format definition to use. WampDeveloper Pro's log format characteristics are more advanced than the "common" LogFormat, and the definitions are located in configuration file:
Each line simply creates the specified file, and appends data to it (there is no rotation).
To automatically rotate a website's access.log (and other log files such as the error.log) every 24 hours (daily), Apache's included rotatelogs.exe tool can be used...
With rotatelogs.exe, instead of writing to log files directly, Apache will "pipe" the log data into specific rotatelogs processes. And these rotatelogs processes will keep track of the elapsed time and/or growing file size - and once the specified limit is reached - will rotate their assigned log files (and start new log files).
Replace the standard logging configuration with:
ErrorLog "|bin/rotatelogs.exe -l C:/WampDeveloper/Logs/Websites/www.example.com/http.errorlog.%Y-%m-%d.txt 86400" CustomLog "|bin/rotatelogs.exe -l C:/WampDeveloper/Logs/Websites/www.example.com/http.accesslog.%Y-%m-%d.txt 86400" combinedtrueout_host CustomLog "|bin/rotatelogs.exe -l C:/WampDeveloper/Logs/Websites/www.example.com/http.deflatelog.%Y-%m-%d.txt 86400" deflate
If you are not using WampDeveloper Pro, but some other WAMP server, replace the LogFormat part (end part) of the access.log CustomLog line with "common".
This will create daily log files:
1. RotateLogs will start 2 processes per log file. With at least 3 log files per VirtualHost (access.log, error.log, deflate.log), and 2 VirtualHosts per website, this can add 12 "rotatelogs.exe" processes to your system for each website that you set up RotateLogs with.
You should only use RotateLogs on your high traffic website, and perhaps only for the access.log file, as otherwise your might run out of memory due "problems when running many piped logger processes on Windows".
2. RotateLogs limits are not exact... It will not make a new log file exactly at midnight, and it can also go over whatever the set file size limit is - due to the way these limits are handled.
3. RotateLogs will only create a log file after the first request is made.
4. Some older Apache versions came with a buggy RotateLogs implementation that would not die after Apache restarted.
5. Apache start error (in error.log):
(OS 2)The system cannot find the file specified. AH00104: unable to start piped log program 'bin/rotatelogs -l C:/WampDeveloper/Logs/Websites/www.example.com/http.accesslog.%Y-%m-%d.txt 86400'
The standard documentation and examples for RotateLogs are no longer correct... On Windows, and with Apache 2.4, you have to specify the full file name of rotatelogs: rotatelogs.exe...
CustomLog "|bin/rotatelogs.exe ...
This is not a problem for the above instructions, but is something that you should be aware of for older ones.