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?

0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

3 Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.