man logrotate
dateformat format_string
Specify the extension for dateext using the notation similar to strftime(3) function. Only %Y %m
%d and %s specifiers are allowed. The default value is -%Y%m%d. Note that also the character sep‐
arating log name from the extension is part of the dateformat string. The system clock must be set
past Sep 9th 2001 for %s to work correctly. Note that the datestamps generated by this format
must be lexically sortable (i.e., first the year, then the month then the day. e.g., 2001/12/01 is
ok, but 01/12/2001 is not, since 01/11/2002 would sort lower while it is later). This is because
when using the rotate option, logrotate sorts all rotated filenames to find out which logfiles are
older and should be removed.
Can anyone please tell me if "dateext" is correct? I want the log
filename to be something like "access.log-2010-12-04".
Insert a dateformat
directive to your configuration file, something like this:
/usr/local/nginx/logs/*.log {
daily
dateext
dateformat -%Y-%m-%d
...
One more thing: Can I do the log rotation every day on a specific time
(e.g. 11 pm)?
By default, logrotate is running via cron at 4 A.M:
/etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
You can move this file to somewhere and rename to logrotate.sh
, then create a new file in /etc/cron.d/
as belows:
0 23 * * * root /path/to/logrotate.sh
I've never seen any apache webserver whose performance was affected by log file size. On some very old servers, apache would just stop working if log file reaches 2GB.
73MB is small.
Deciding to rotate webserver log file daily is convenient (readability, easier to combine with tools like awstats, ...)
Best Answer
There are multiple switches here. Frequency(weekly, monthly etc), size params, -f flag and the cron job frequency. To add to the confusion, it seems the order of operations in the config file also matters..
-f will force a rotation
minsize means the log size should be at least minsize for the frequency rotation to happen. A daily frequency (called daily from cron) will do nothing if size is less than minsize.
maxsize means, in addition to the frequency run, if the size is over maxsize a rotation can happen. For ex. if a config with weekly frequency is called daily, and if the size is bigger than the maxsize, rotation can happen.
size - May be it should not be combined with frequency. Control the frequency from cron.