I'm running Apache 2.2 on CentOS 6.5 and what I'd like to do is have Apache's current access log file be:
/var/log/httpd/access_log
And each day at midnight, that file is renamed like so (assume 2014-09-22
is the date that just passed):
/var/log/httpd/access_log.2014-09-22
...and a new log file (access_log
) is created at that instant, and Apache continues logging to it. How can I do this? I've got this CustomLog
directive set up already:
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log.%Y-%m-%d 86400" combined
But this causes the current (active) logfile to be named access_log.2014-09-22
if today is 2014-09-22.
I can think of a hacky solution, where I have a script that runs just after midnight and sets /var/log/httpd/access_log
to be a symlink to whatever the current day's logfile is. (It would be based on date, so even if it's a low-traffic server and the new logfile didn't exist yet, the symlink would be correct and would function as soon as any requests hit the server). But it seems like there must be a more elegant way to do this. Is there some way to tell rotate logs to use one filename for the current log, and a different filename for the rotated logs? Failing that, is there some other clean way to do what I want?
EDIT: Restarting Apache each day is not an option.