gpt4 book ai didi

centos - 旋转异常日志的 logrotate 问题

转载 作者:行者123 更新时间:2023-12-04 19:42:12 26 4
gpt4 key购买 nike

我对 logrotate 有疑问。应用程序本身会产生以下日志:
xxx.log
并在 23:59 应用程序将日志更改为:
xxx.log.2019-01-05
等等。现在我在日志目录中得到以下信息:

xxx.log
xxx.log.2019-01-01
xxx.log.2019-01-02

等等

我需要做的是要轮换在 23:59 创建的日志,而不是触摸 xxx.log。文件本身。

我尝试使用以下 logrotate 规则:
/var/log/xxx/xxx/xxx.log.* {
daily
missingok
rotate 30
compress
notifempty
copytruncate
nosharedscripts
prerotate
bash -c "[[ ! $1 =~ *.gz ]]"
endscript
}

但首先 logrotate 不会压缩最后创建的日志,它还会为之前压缩的文件添加 .1.gz 扩展名。

最佳答案

logrotate does not compress the log that was created last


您是否在/etc/logrotate.conf 中定义了“delaycompress”?根据 logrotate man :

delaycompress

Postpone compression of the previous log file to the next rotation cycle.



it also adds .1.gz extension


当您在上述手册页中时,您应该查看“扩展”选项的作用:

extension ext

Log files with ext extension can keep it after the rotation.

关于centos - 旋转异常日志的 logrotate 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54107644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com