Mod-log-rotate
From Hexten
If you host a lot of virtual servers on a single Apache box and use the supplied rotatelogs program to rotate the logs you'll notice that your process table is cluttered up with an instance of rotatelogs for each virtual server. With mod_log_rotate the log rotation is handled by the server process so you save a bunch of processes and file descriptors.
Contents |
[edit] Download
There are versions of the module for Apache 1.3.x here and Apache 2.0 here. Make sure you get the correct version for your server.
Windows users can find pre-built binaries at apachelounge.com/download - thanks Steffan.
[edit] Install
Install mod_log_rotate using apxs as follows:
$ apxs -i -a -c mod_log_rotate.c
[edit] Configure
Load and enable mod_log_rotate by adding two lines to your httpd.conf. For Apache 1.3 use
LoadModule log_rotate_module libexec/mod_log_rotate.so
RotateLogs On
and for Apache 2 use
LoadModule log_rotate_module modules/mod_log_rotate.so
RotateLogs On
The LoadModule line may have already been added if you used the apxs -a (activate) option when compiling the module.
If you are using the Apache 1.3 version of the module you will also have to replace any CustomLog, TransferLog, LogFormat and CookieLog directives with the corresponding RotateXXX version. For example
TransferLog logs/access_log
would become
RotateTransferLog logs/access_log
You may need to review the permissions on your log directories. Normally Apache creates log files while it's running as root and then becomes nobody (or whatever user you're running it as) before it starts serving pages. In order to be able to create new log files during rotation the permissions on any log directories need to allow writes by the web server user.
The remainder of the directives provided by mod_log_rotate control the interval and timing of log rotation. The configuration directives may be used globally or per virtual server.
| RotateCustomLog, RotateTransferLog, RotateLogFormat and RotateCookieLog | NOTE: These options are only available for the Apache 1.3 version of the module. Because of architectural differences on Apache 1.3 mod_log_rotate completely replaces the default logging module. That means it must provide its own versions of these logging directives. In order to enable rotated logs you must replace any standard logging directives with these versions throughout your config files. |
| RotateLogs On|Off | Enable / disable automatic log rotation. Note: On Apache 2, once enabled mod_log_rotate takes responsibility for all log output server wide even if RotateLogs Off is subsequently used. That means that the BufferedLogs directive that is implemented by mod_log_config will be ignored. As BufferedLogs isn't document and is flagged as an experimental feature this shouldn't be a problem in production environments. This doesn't apply to the Apache 1.3 version of the module. |
| RotateLogsLocalTime On|Off | Normally the log rotation interval is based on UTC. For example an interval of 86400 (one day) will cause the logs to rotate at UTC 00:00. When this option is on, log rotation is timed relative to the local time. |
| RotateInterval [] | Set the interval in seconds for log rotation. The default is 86400 (one day). The shortest interval that can be specified is 60 seconds. An optional second argument specifies an offset in minutes which is applied to UTC (or local time if RotateLogsLocalTime is on). For example RotateInterval 86400 60 will cause logs to be rotated at 23:00 UTC. |
[edit] Error Logs
Unfortunately Apache error logs are handled in such a way that we can't work the same log rotation magic on them. Like transfer logs they support piped logging though so you can still use rotatelogs for them.
[edit] Bugs
If you find one please mail me.

