rotatelogs - Piped logging program to rotate Apache logs

For use in to httpd.conf

rotatelogs [ -l ] [ -f ] logfile rotationtime|filesizeM [ offset ]

Program for use with Apache's piped logfile feature, supports rotation based on a time inte val or maximum size of the log.

-l use local time rather than GMT as the base for the interval or strftime formatting with size-based rotation.
in an environment which changes the GMT offset (such as for BST or DST) this can lead to unpredictable results!
-f force logfile to be opened immediately,
instead of waiting for the first entry to be read (for non-busy sites, there may be a substantial delay between when the server is started and when the first request is handled, meaning that the associated logfile does not "exist" until then, which causes problems from some automated logging tools).
rotationtime seconds between log file rotations. The rotation occurs at the beginning of this interval.


3600, at the beginning of every hour; (60*60)
86400, every night at midnight. 24*60*60
If no data is logged during an interval, no file will be created.
filesizeM size in megabytes (suffixed by M to distinguish size from a time.
offset minutes offset from UTC. Default: zero UTC is used.
For example, to use local time in the zone UTC -5 hours, specify -300 . use of -l is prefered.


Create a log where nnnn is the time at which the log nominally starts (this time will always be a multiple of the rotation time, synchronized with cron scripts with it).
At the end of each rotation time ( 24 * 60 * 60 =86400 here after 24 hours) start a new log.
CustomLog "|bin/rotatelogs /var/logs/logfile 86400" common

Create a new log file every day at midnight
CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common

Rotate the logfile when it reaches a 5 megabytes.
CustomLog "|bin/rotatelogs /var/logs/logfile 5M" common

Rotate the error logfile whenever it reaches a 5 megabytes
ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M"


%c date and time
%xdate %Xtime
%Y 4-digit year %y 2-digit year
%m 2-digit month %B month %b 3-character month %j 3-digit day of year
%d 2-digit day
%H2-digit hour (00-24 ) %I2-digit hour (00-12)
%M2-digit minute
%S2-digit second
%pam/pm of 12 hour clock %Ztime zone
%U2-digit week of year
week starts on Sunday
%W2-digit week of year
week starts on Monday
%w1-digit weekday
week starts on Sunday
%A weekday %a 3-character weekday
%%literal `%'