Social Media

Apache Log Rotation on Windows

Thie example uses Apache 2.4, 64-bit version from apachehaus, and the rotatelogs.exe contained in this project –

Unzip the apache download and go to the bin folder, and confirm there is a rotatelogs.exe file. Install the server as either a service, or start from the bin folder, and confirm it works.

Now lets configure rotatelogs.exe for an initial test of every 10s –

 # If you prefer a logfile with access, agent, and referer information
 # (Combined Logfile Format) you can use the following directive.
 # CustomLog "logs/access_log" combined
 CustomLog "|C:/httpd-2.4/bin/rotatelogs.exe -l C:/httpd-2.4/logs/accesslog.%Y-%m-%d-%H-%M-%S.log 10" combined

The file names use the strftime format –

Restarting the The log directory then shows files with names like –


So lets change it to a daily rotate – or 60*60*24s = 86400s –

CustomLog "|C:/httpd-2.4/bin/rotatelogs.exe -l C:/httpd-2.4/logs/accesslog.%Y-%m-%d.log 86400" combined

The final change is to the error log – we dont need to rotate this daily as its smaller than the access_log, but we can use rotatelogs to rotate on file size, in this case 10MB –

ErrorLog "logs/error_log"

Becomes –

ErrorLog "|C:/httpd-2.4/bin/rotatelogs.exe -l C:/httpd-2.4/logs/error_log.%Y-%m-%d.log 10MB"


  • Starts an extra external process – rotatelogs.exe – for each log
  • Piping on windows is a bit ropy
  • You cant configure monthly as an interval


mod_log_rotate –

This is a Apache Shared Object – so operates the same as rotatelogs, but within the apache processes

Example Usage –

LoadModule log_rotate_module modules/
RotateLogs On
CustomLog logs/access-%Y%m%d-%H%M%S.log common

To rotate the logs monthly the advice is to use LogRotateWin, a windows version of the unix command logrotate ( –

LogRotateWin –

This operates as a daily task, and processes the configuration file. To rotate monthly you can use the following

C:\httpd-2.4\logs\access_log {
 dateformat -%d-%m-%Y
 rotate 30

References –

About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: