ruby-on-rails - logrotate 以错误的方式将日期附加到日志中

标签 ruby-on-rails logging logrotate

我有一个 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 或每周增加则应该轮换。

最佳答案

/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

关于ruby-on-rails - logrotate 以错误的方式将日期附加到日志中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744381/

相关文章:

ruby-on-rails - 要用自己。或者不是..在Rails中

javascript - 更新 Rails Foundation-rails gem 5 到 6,datepicker 不起作用,页面加载时出现 JS 错误

android - onChildClickListener 在 ExapandableListView 中没有响应

logging - 我应该记录网站的 404 错误吗?

linux - Rsyslog 中央日志记录单独的本地日志

ruby-on-rails - 为 Rails 应用设置 logrotate

tomcat - Logrotate 文件名中包含日期的文件

javascript - ruby on Rails 从button_tag调用javascript函数

ruby-on-rails - 使用机架中间件捕获无效的 JSON 解析错误

linux - cron.hourly 不工作