【问题标题】:logrotate appending the date to logs in wrong waylogrotate 以错误的方式将日期附加到日志中
【发布时间】:2016-12-09 05:19:11
【问题描述】:

我有一个 rails 应用程序,并且我已经为日志设置了 logrotate。 日志类似于目录/home/username/myapp/log/ 中的production.logsidekiq.logcron.log。我希望旋转的日志应该命名为production.log-server-1-2016-08-02-1470119678.gz。这种类型的文件也存在,但还有一个文件名为 production.log-server-1-2016-08-02-1470119678.gz-server-1-2016-08-03-1470206339-server-1-2016-08-03-1470225672.gz

以下是我的 logrotate 配置

/etc/logrotate.d/myapp

/home/user/myapp/log/*.log {
    weekly
    size 10M
    missingok
    rotate 7
    compress
    delaycompress
    copytruncate
    #create 0640 ubuntu ubuntu
    su ubuntu ubuntu
    sharedscripts
    prerotate

    endscript
    postrotate

    endscript
}

/etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
daily
size 10M
# use the syslog group by default, since this is the owning group
# of /var/log/syslog.
su root syslog

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext
dateformat -server-1-%Y-%m-%d-%s

# uncomment this if you want your log files compressed
compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    missingok
    weekly
    size 500K
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    weekly
    size 500K
    create 0660 root utmp
    rotate 1
}

# system-specific logs may be configured here

有什么帮助吗?基本上我希望日志文件应该命名为production.log-server-1-date-month-year-time.gz,如果文件大小增加超过 10mb 或每周,它应该被轮换。

【问题讨论】:

    标签: ruby-on-rails logging logrotate


    【解决方案1】:

    /etc/logrotate.d/myapp在myapp配置下添加dateext和date

    /home/user/myapp/log/*.log {
        weekly
        size 10M
        missingok
        rotate 7
        compress
        dateext
        dateformat -server-1-%Y-%m-%d-%s
        delaycompress
        copytruncate
        #create 0640 ubuntu ubuntu
        su ubuntu ubuntu
        sharedscripts
        prerotate
    
        endscript
        postrotate
    
        endscript
    }
    

    /etc/logrotate.conf 文件中,您可以删除以下配置。

    # use date as a suffix of the rotated file
    dateext
    dateformat -server-1-%Y-%m-%d-%s
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 2013-08-31
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      相关资源
      最近更新 更多