rotatelogs

Piped logging program to rotate Apache logs

For use in to httpd.conf

rotatelogs <[-l] [-f] [-L linkname][-p program][-D][-t][-v][-e][-c] logfile rotationtime|filesize ( B|K|M|G) [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).
-D Creates the parent directories of the path that the log file will be placed in if they do not already exist. This allows strftime(3) formatting to be used in the path and not just the filename.
-v verbose on STDERR containing the result of the configuration parsing and file opens and closes.
-e Echo logs through to stdout. Useful when logs need to be further processed by a further tool in the chain.
-c Create log file for each interval, even if empty.
-t logfile is truncated instead of rotated. This is useful when a log is processed in real time by a command like tail, and there is no need for archived data. No suffix will be added to the filename, format strings containing '%' characters will be respected.
-T All but the initial logfile to be truncated when opened. Useful when the format string contains something that will loop , such as the day of the month.
-L linkname A hard link to be made from the current logfile to the linkname. This can be used to watch the log continuously across rotations using a command like tail -F linkname. If the linkname is not an absolute path, it is relative to rotatelogs' working directory, which is the ServerRoot when rotatelogs is run by the server.
-p program When a new log file is opened program is spawned with the same stdin, stdout, and stderr and environment. .
The filename is the first argument to the program.
If executing after a rotation, the old log file is passed as the second argument.
rotatelogs does not wait for the program to terminate .
-n number-of-files Use a circular list of filenames without timestamps. overwrites log files at startup and during rotation.
With -n 3, the series of log files opened would be "logfile", "logfile.1", "logfile.2", then overwriting "logfile".
when "logfile" is first opened , it will be truncated if -t is also provided, subsequent rotations begin with truncation of the target file.
For size based rotation without -t and existing log files in place, this option may result in unintuitive behavior such as initial log entries being sent to "logfile.1", and entries in "logfile.1" not being preserved even if later "logfile.n" have not yet been used.
rotationtime seconds between log file rotations. The rotation occurs at the beginning of this interval.

examples

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.
filesizex size in megabytes
offset minutes offset from UTC. Default: zero UTC is used.
For example, to use local time in the zone UTC -5 hours, specify -300 , -l is prefered.

EXAMPLES

Create a log where mmmmm/var> is the time at which the log nominally starts (this time will always be a multiple of the rotation time, synchronized with cron .
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"

strftime

%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 `%'