旋转异常日志的logrotate问题

问题描述 投票:0回答:1

我有一个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扩展名。

centos logrotate
1个回答
0
投票

logrotate不会压缩最后创建的日志

你有/etc/logrotate.conf中定义的“delaycompress”吗?每logrotate man

delaycompress

将先前日志文件的压缩推迟到下一个循环周期。


它还增加了.1.gz扩展名

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

扩展分机

具有ext扩展名的日志文件可以在旋转后保留它。

© www.soinside.com 2019 - 2024. All rights reserved.