Orr Siloni
Orr Siloni

Reputation: 1308

Setting error log filename in apache to include current date

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?

Upvotes: 4

Views: 8114

Answers (3)

Ingo
Ingo

Reputation: 5381

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.

Upvotes: 0

drAlberT
drAlberT

Reputation: 23268

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

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272427

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.

Upvotes: 1

Related Questions