Embracing the Messiness in Search of Epic Solutions

Rotating Log Files on Apache HTTP Server

Posted

in

PROBLEM

Consider the following log configuration:-

ErrorLog "D:/logs/apache/error.log"

<IfModule log_config_module>
    ...
    CustomLog "D:/logs/apache/access.log" common
</IfModule>

At some point of time, both error.log and access.log are going to get insanely large.

SOLUTION

To fix this, the logs can be piped (by using |) to Apache HTTP Server’s built-in program called rotatelogs to rotate the log files. For example, the following configuration will create a daily rolling file appender for error.log and access.log.

ErrorLog "|D:/apps/apache/bin/rotatelogs.exe -l D:/logs/apache/error-%Y-%m-%d.log 86400"

<IfModule log_config_module>
    ...
    CustomLog "|D:/apps/apache/bin/rotatelogs.exe -l D:/logs/apache/access-%Y-%m-%d.log 86400" common
</IfModule>

Comments

Leave a Reply