I would like to change the suffix of mail.log
rotated files to include the date, such as
/var/log/mail.log.20180920
I read from this question that /etc/cron.weekly/sysklogd
should be changed, but I don't have such a file. I would like to rewrite the defaults, however, it is mentioned in this post to write a new config for that.
So I found that because this log file is created by syslog, it's listed in the /etc/logrotate.d/rsyslog
, so I changed this file to the following to include the date suffix:
/var/log/syslog
{
rotate 400
daily
missingok
notifempty
delaycompress
compress
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
rotate 400
hourly
dateext
dateformat .%Y%m%d
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
I also delete the entries for rsyslog and mail.log from /var/lib/logrotate/status to force the log to rotate for today, then I run :
logrotate /etc/logrotate.conf --debug
, but in the output I get:
rotating pattern:
/var/log/mail.log
hourly (400 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/mail.log
log does not need rotating
so, I do logrotate -f /etc/logrotate.conf
to force it to rotate the log, the entries in the /var/lib/logrotate/status
gets updated. The file /var/log/maill.log
is generated, but what I expect is to see a mail.log.20181020
file, why it does not generate that?
Thank you
From
man logrotate
:, near the endIn the
/etc/logrotate.conf
you can set following directives:Further information can be found here or with
man logrotate
.