views:

384

answers:

2

Hi, 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?

A: 

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
Thanks, I'll try this approach. I read meanwhile in the apache.org docs that this probably is the way to go.
Orr Siloni
A: 

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

AlberT
Does this timestamp the filename, or the actual message logged ?
Brian Agnew
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
AlberT
Not a problem. I just wanted to clarify, however. You might want to edit your answer re. your logrotate answer, though
Brian Agnew
Thanks for answering.
Orr Siloni