Mithilfe des mod_log_rotate können auch mit Apache tägliche Logs erstellt werden. Dazu wird die Direktive „CustomLog“ um strftime()-Kompatible Parameter erweitert.

Das Modul stellt folgende Direktiven zur Verfügung (Auszug aus der Doku):

  • RotateLogs On|Off:
    Enable / disable automatic log rotation. 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.
  • Rotate LogsLocalTime 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.

Die zugehörigen Einträge in der httpd.conf:

LoadModule log_rotate_module modules/mod_log_rotate.so

Um tägliche Logs welche um 00:00 lokaler Zeit gewechselt werden zu erzeugen wird die CustomLog-Direktive folgendermaßen angepasst:

<IfModule log_rotate_module>
  CustomLog "logs/access_%Y%m%d.log" combined
  RotateLogs On
  RotateLogsLocalTime On
</IfModule>

Quellen: