我试图每天轮换应用程序的日志,但由于某种未知的原因,它不起作用。如果我调试它的 logrotate 定义,它会说它不会旋转它。然而,只有当我强制它旋转时它才起作用。
我在这里缺少什么?
logrotate 定义(/etc/logrotate.d/application)
/tmp/company.0000/application.log {
daily
rotate 7
compress
copytruncate
missingok
extension .log
dateext
dateformat _%Y%m%d
su root valter
create 440 valter valter
}
列出文件夹中的所有内容
valter@eniac:~$ ls -ltha /tmp/company.0000/
total 2,8M
drwxrwxrwx 9 root root 96K Aug 30 17:25 ..
drwxrwxr-x 2 valter valter 4,0K Aug 30 17:25 .
-rw-rw-r-- 1 valter valter 2,7M Aug 30 17:00 application.log
修改文件日期
valter@eniac:~$ sudo touch -m --date="2016-08-01" /tmp/company.0000/application.log
valter@eniac:~$ ls -ltha /tmp/company.0000/
total 2,8M
drwxrwxrwx 9 root root 96K Aug 30 17:25 ..
drwxrwxr-x 2 valter valter 4,0K Aug 30 17:25 .
-rw-rw-r-- 1 valter valter 2,7M Aug 1 00:00 application.log
调试 logrotate 而不修改日志本身
valter@eniac:~$ sudo logrotate -d /etc/logrotate.d/application
reading config file /etc/logrotate.d/application
extension is now .log
Handling 1 logs
rotating pattern: /tmp/company.0000/application.log after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 1000
considering log /tmp/company.0000/application.log
log does not need rotating
switching euid to 0 and egid to 0
强制日志轮转并列出
valter@eniac:~$ sudo logrotate --force /etc/logrotate.d/application
valter@eniac:~$ ls -ltha /tmp/company.0000/
total 264K
drwxrwxr-x 2 valter valter 4,0K Aug 30 17:26 .
-rw-rw-r-- 1 valter valter 0 Aug 30 17:26 application.log
drwxrwxrwx 9 root root 96K Aug 30 17:25 ..
-rw-rw-r-- 1 valter valter 158K Aug 1 00:00 application_20160830.log.gz