logrotate:消息“日志已经轮换”的含义

logrotate:消息“日志已经轮换”的含义

如果我运行 logrotate log does not need rotating (log has been already rotated),日志文件不会轮换。这是为什么?

我的日志轮换配置:

/var/log/capp/*.log {
    missingok
    rotate 90
    daily
    notifempty
    compress
    delaycompress
}

在运行 logrotate 之前我删除了以下行

"/var/log/capp/server.log" 2019-4-1-7:0:0

从文件/var/lib/logrotate/logrotate.status

logrotate输出:

/> logrotate -v /etc/logrotate.d/capp 
reading config file /etc/logrotate.d/capp
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/capp/*.log  after 1 days (90 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/capp/server.log
  log does not need rotating (log has been already rotated)

并且日志文件没有轮换:

/> ls -la  /var/log/capp/server.log*
-rw-r--r-- 1 capp capp 272962507  1. Apr 07:00 /var/log/capp/server.log

答案1

可能是 logrotate 只会在第二次运行时才开始轮换日志文件。似乎如果/var/lib/logrotate/logrotate.statuslogrotate 中没有该文件的条目,则不会轮换该文件。所以我的诀窍是将行更改/var/lib/logrotate/logrotate.status

"/var/log/capp/server.log" 2019-4-1-7:0:0

"/var/log/capp/server.log" 2019-3-31-7:0:0

...然后 logrotate 开始旋转server.log文件

相关内容