3.8. Rotating Logfiles at a Particular Time
Problem
You want to automatically roll over the Apache logs at specific times without having to shut down and restart the server.
Solution
Use CustomLog and the rotatelogs program:
CustomLog "|/path/to/rotatelogs/path/to/logs/access_log.%Y-%m-%d 86400" combined
Discussion
The rotatelogs script is designed to use an Apache feature called piped logging, which is just a fancy name for sending log output to another program rather than to a file. By inserting the rotatelogs script between the Web server and the actual logfiles on disk, you can avoid having to restart the server to create new files; the script automatically opens a new file at the designated time and starts writing to it.
The first argument to the rotatelogs script is the base name of the
file to which records should be logged. If it contains one or more
% characters, it will be treated as a strftime(3) format string; otherwise, the
rollover time (in seconds since 1 January 1970), in the form of a
10-digit number, will be appended to the base name. For example, a
base name of foo would result in
logfile names like foo.1020297600, whereas a base name of
foo.%Y-%m-%d would cause the logfiles to be named
something like foo.2002-04-29.
The second argument is the interval (in seconds) between rollovers. Rollovers will occur whenever the system time is a multiple of this value. For instance, a 24-hour day contains 86,400 seconds; if you specify a rollover interval of 86400, a new logfile ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access