httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Ford <>
Subject suggestion for automatic log file rotation
Date Sat, 23 Nov 1996 18:37:01 GMT
I know that this is too late now for 1.2, but I have been asked by a
couple of my clients whether there was any way of automatically
logging errors and accesses to log files with names that include
elements of the date and time.  My idea is that if the log file name
does not start with a "|", and looks like an strftime string, then
strftime should be used to format the file name and a new file should
be used when strftime would generate a different string.  For example,
today the directive:

  ErrorLog "logs/errors-%Y%m%d.log"

would log to "logs/errors-19961123.log" and at midnight the file would
be closed and the new file "logs/errors-19961124.log" would be used.
This functionality would obviate the need for the external
"rotatelogs" program.

The approach I am considering is on parsing the TransferLog or
ErrorLog directive to check for strftime % specifiers and to note the
smallest time element used.  For each separate log file there should
be two new fields; one giving the next time at which a new log file
should be opened and the other storing the interval between log file
changes.  When logging a message the current time is first compared
with the next time field and if the current time is later than that
time then the current log file is closed, a new log file opened and a
new next time calculated.  The message is then written to the file.  
(the next time field should be initialized to zero so that the first
message written causes the log file to be opened).

There are a number of potential problems:

* strftime strings could generate file names containing spaces (user's

* generated log files could require new directories to be created
  (again the user's problem -- if s/he wants logs stored in
  directories by month or year, then s/he will have to ensure that the
  directories are created in time).

* the period between the start times of successive log files is not
  necessarily constant (this just has to be taken into account when the
  smallest strftime specifier refers to the month or year, although
  leap seconds and changes to and from daylight saving time could
  throw things out).

Looking at the code the main implementation problem seems to be coping
with multiple virtual hosts that use the same log file.

My question is what do people think of the suggestion?

Andrew Ford                             Email:
Independent Software Consultant         WWW:
"Brittany", Wells Road,                 Tel:    +44 1452 770836
Eastcombe, Stroud, GL6 7EE, GB          Fax:    +44 1452 770835

View raw message