gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:33:44 24 4
gpt4 key购买 nike

我有一个 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/

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