Rotating Log Files on Apache HTTP Server

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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s