logrotate以错误的方式将日期附加到日志中

时间:2016-08-03 12:58:40

标签: ruby-on-rails logging logrotate

我有一个rails应用程序,我已经为日志设置了logrotate。 日志类似于production.log目录中的sidekiq.logcron.log/home/username/myapp/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或每周,它应该被轮换。

1 个答案:

答案 0 :(得分:0)

/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