Apache daily logrotate
I want to create daily logs, but there's a small problem. Logs aren't being created for each day, rather they contain the previous log files. Here's my current setup, how can I change it so it only create a log file for each day?
I edit the following file : /etc/logrotate.d/httpd
I'm using a control panel called Zadmin so I included its log path as a second dir.
I'm using CentOS 6.5 64 bit.
/var/log/httpd/*log /var/sentora/logs/domains/zadmin/*.log {
missingok
rotate 4000000
daily
notifempty
sharedscripts
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
Following on to Brian's answer, I'm a big fan of cronolog, which does pretty much exactly what you're going for:
CustomLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%Y-%m-%d-access.log" combined
ErrorLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%Y-%m-%d-error.log"
yum install cronolog
will get you cronolog on Cent6.
Apache lets you pipe log files to another program which can then handle rotation without having to reload/restart Apache. Apache even provides a program to do this.
ErrorLog "|bin/rotatelogs -l -f /var/log/apache2/errlogfile.%Y.%m.%d.log 86400" common
CustomLog "|bin/rotatelogs -l -f /var/log/apache2/logfile.%Y.%m.%d.log 86400" common
Try running logrotate
manually to look for errors: logrotate -d /etc/logrotate.d/httpd
. The manual says "-d Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file."
This is what we're using successfully:
/var/log/httpd/*log {
daily
dateext
dateformate -%d-%m-%Y
missingok
nocompress
rotate 30
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}