Tuesday, October 18, 2011

Rotate Access logs in Apache

Rotatelogs is a simple program for use in conjunction with Apache's piped log file feature. It supports rotation based on a time interval or maximum size of the log.
Using the module mod_log_rotate, the log rotation is handled by the server process so you save on the process count and file descriptors.
Download the mod_log_rotate.dll  or  mod_log_rotate.so files  in the following URL if your apache not having the modules.
Rename it as mod_log_rotate.dll  and place the file in Modules Directory (D:\IBMHTTPServer\modules)

To load this module, modify your httpd.conf:
LoadModule log_rotate_module modules/mod_log_rotate.so
#or if using the DLL version
LoadModule log_rotate_module modules/mod_log_rotate.dll
#Add the following line to use the module

RotateLogs On
RotateLogsLocalTime On
RotateInterval 86400
CustomLog logs/access_%Y-%m-%d-%H_%M_%S.log combined
The directive for your individual sites custom logs, will not change:
CustomLog " access_%Y-%m-%d-%H_%M_%S.log "  combined
Your log file will be in the format: ex.log.1140048000
The numeral is the number of seconds since: 01-01-1970

To translate that number into a date, the equation is: 01-01-1970 + 1140048000 seconds.
mod_log_rotate directives
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 <interval> [<offset>]
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.




No comments:

Post a Comment