Web Server Performance: Rotate Apache Access Logs on Windows
Apache web access logs provide vital information about visits, visitors and requests served by Apache web server. Each request is logged by the web server so the log file size can increase at high speed. If the log file size is small it is easy for apache to append lines. On other hand as the size of file grows, web server require more server resources to maintain logs.
If the access log file size reaches to around 4GB on windows machine, apache will be very slow to respond and will hurt the web application performance badly. You should keep checking log file size regularly to make sure its within acceptable range. Access log file is normally found in logs/access.log under the apache installation.
Apache provides built in functionality to rotate these logs on daily basis so it does not grow much and create performance issues to server. If we set it up, new file will be created for each day. Following is method to setup log rotation on Windows with WAMP, Apache 2.2.11.
Log rotation can be done at two levels, one server level and second on virtual host level. To do a server level log rotation you will need to modify /conf/httpd.conf file under apache installation. To do a virtual host level rotation will need to modify file \conf\extra\httpd-vhosts.conf file.
For server level log rotation open file /conf/httpd.conf and find line like
CustomLog "C:/Program Files/wamp/logs/access.log" common
The line defines the log file. Now we will define log rotation in following manner
CustomLog "|bin/rotatelogs.exe C:/Program Files/wamp/logs/access_%y-%m-%d.log 86400" common
here |bin/rotatelogs.exe tells that logs should be sent to rotatelogs.exe program which is located under apache installation in bin folder (make sure the exe file exists and have permissions).
The C:/Program Files/wamp/logs/access_%y-%m-%d.log tells the location of new log files. Here %y is year, %m is month and %d is day so the file name remains unique. 86400 is time span defined in seconds after which new file is generated, in this case its 24 hours (24x60x60) means log should rotate daily.
Be sure that you user have permission to write a file on given location (C:\ in this case). Also be sure that there is no space in file path given as it will create issues in creating new file.
After making the changes save file and restart apache. Now check if new file is created properly on access any web pages on this server. The new file should be created with name like “access_10-08-18.log” assuming that today is (Aug, 18 2010).
If you have to do same thing for a particular virtual host than you should add following line in <VirtualHost xxxxxxxx> definition.CustomLog "|bin/rotatelogs.exe C:/Program Files/wamp/logs/access_%y-%m-%d.log 86400"
This should help improving performance of the web server as it has to write to a small file, secondly it is easy to download and analyze small logs as compared to huge files.
[...] move. The site was opening the file and writing to it with each use. A quick web search uncovered http://www.infotales.com/web-server-performance-rotate-apache-access-logs-on-windows/ and the solution to my problem. We now have daily log files, much smaller and easier to edit or [...]
Great tutorial, thanks!
Good tutorial.
If you happen to be on a windows 2008 server do not use a path like this
#CustomLog “|bin/rotatelogs.exe C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/access_%y-%m-%d.log 86400″ combined
Your error.log will contain errors for every attempted write.
The tutorial stated “Also be sure that there is no space in file path given as it will create issues in creating new file.” but contained “C:/Program Files/” in the example so I had some confusion about what I could do.
Setting a log path with no spaces gave me the desired results.