我应该在哪里查找 /var/log/mail.log 的 logrotate 配置文件

我应该在哪里查找 /var/log/mail.log 的 logrotate 配置文件

我想更改mail.log轮换文件的后缀以包含日期,例如

/var/log/mail.log.20180920

我读到问题应该/etc/cron.weekly/sysklogd更改,但我没有这样的文件。我想重写默认值,但是,这里面提到了邮政为此编写一个新配置。因此,我发现由于此日志文件是由 syslog 创建的,因此它列在 中/etc/logrotate.d/rsyslog,因此我将该文件更改为以下内容以包含日期后缀:

/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
}

我还从 /var/lib/logrotate/status 中删除了 rsyslog 和 mail.log 的条目,以强制日志在今天轮换,然后我运行: logrotate /etc/logrotate.conf --debug,但在输出中我得到:

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

因此,我logrotate -f /etc/logrotate.conf强制它轮换日志,日志中的条目/var/lib/logrotate/status会得到更新。文件/var/log/maill.log已生成,但我期望看到一个mail.log.20181020文件,为什么它没有生成该文件?

谢谢

答案1

来自man logrotate:,接近尾声

FILES

   /var/lib/logrotate/status  Default state file.
   /etc/logrotate.conf        Configuration options.

答案2

/etc/logrotate.conf可以设置以下指令:

   dateext
          Archive old versions of log files adding a date extension like YYYYMMDD instead of simply adding a  number.
          The extension may be configured using the dateformat and dateyesterday options.

   dateformat format_string
          Specify  the  extension for dateext using the notation similar to strftime(3) function. Only %Y %m %d %H %M
          %S %V and %s specifiers are allowed.  The default value is -%Y%m%d except hourly, which uses  -%Y%m%d%H  as
          default value.  Note that also the character separating log name from the extension is part of the datefor‐
          mat string. The system clock must be set past Sep 9th 2001 for %s to work correctly.  Note that  the  date‐
          stamps  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 log‐
          files are older and should be removed.

   dateyesterday
          Use yesterday's instead of today's date to create the dateext extension, so that the rotated log file has a
          date in its name that is the same as the timestamps within it.

更多信息请访问这里或使用man logrotate

相关内容