4

I'm trying to have apache create a new error log file every day, based on the current date. The default error log filename is something like this: ErrorLog "/logs/error.log"

and I want it to be something like: ErrorLog "/logs/error_$year$month$day.log"

Any ideas?

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212
Orr Siloni
  • 1,268
  • 10
  • 21

3 Answers3

1

Take a look at Cronolog

cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened. cronolog is intended to be used in conjunction with a Web server, such as Apache, to split the access log into daily or monthly logs.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • Thanks, I'll try this approach. I read meanwhile in the apache.org docs that this probably is the way to go. – Orr Siloni Jul 16 '09 at 13:22
0

My approach would be to configure logrotate for apache to rotate apache's logs once per day then ..

For a Custom log having date information on every log line instead:

%...{format}t:  The time, in the form given by format, which should
                be in strftime(3) format. (potentially localized)

You have to use the strftime (man 3 strftime) formatting rules:

%F or its equivalent without dashes %Y%m%d

So:

# CustomLog with explicit format string
CustomLog my_log "%{%Y%m%d}t %h %l %u %t \"%r\" %>s %b"

Where %{%Y%m%d}t does the job

drAlberT
  • 22,059
  • 5
  • 34
  • 40
  • Does this timestamp the filename, or the actual message logged ? – Brian Agnew Jul 16 '09 at 11:07
  • Sorry, my answer is not on topic ... I misunderstood ... My approach would be to configure logrotate for apache to rotate apache's logs once per day then ... sorry again – drAlberT Jul 16 '09 at 11:11
  • Not a problem. I just wanted to clarify, however. You might want to edit your answer re. your logrotate answer, though – Brian Agnew Jul 16 '09 at 11:13
0

Change to this in your httpd.conf

ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M"

This configuration will rotate the error logfile whenever it reaches a size of 5 megabytes, and the suffix to the logfile name will be created of the form errorlog.YYYY-mm-dd-HH_MM_SS.

Ingo
  • 5,239
  • 1
  • 30
  • 24