Ruby on Rails生产日志轮换 [英] Ruby on Rails production log rotation
问题描述
在Ruby on Rails生产应用程序上启用日志轮转的最佳方法是什么?
What is the best way to enable log rotation on a Ruby on Rails production app?
是通过在托管服务器上使用logrotate还是在从应用程序初始化记录器时使用一组选项?
Is it by using logrotate on the hosting server or is there a set of options to use when initialising logger from the app?
推荐答案
选项1:syslog + logrotate
您可以配置滑轨,以使用系统日志工具.
Option 1: syslog + logrotate
You can configure rails, to use the systems log tools.
config/environments/production.rb 中的示例.
# Use a different logger for distributed setups
config.logger = SyslogLogger.new
这样,您登录到syslog,并可以使用默认的logrotate工具旋转日志.
That way, you log to syslog, and can use default logrotate tools to rotate the logs.
另一种选择是简单地配置logrotate以拾取rails留下的日志.
例如,在Ubuntu和Debian上,该文件位于名为/etc/logrotate.d/rails_example_com
的文件中.
Another option is to simply configure logrotate to pick up the logs left by rails.
On Ubuntu and Debian that would be, for example, in a file called /etc/logrotate.d/rails_example_com
.
/path/to/rails.example.com/tmp/log/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
copytruncate
}
按照下面的建议,建议在Rails中使用copytruncate
,以避免必须重新启动Rails应用程序.
As per suggestions below, in Rails it is advised to use copytruncate
, to avoid having to restart the Rails app.
删除了共享脚本/结尾脚本",因为此处未使用它们,并且根据注释会导致问题.并按照注释建议删除了create 640 root adm
.
removed "sharedscripts/endscript" since they are not used here and cause problems according to comment. And removed create 640 root adm
as per comment suggested.
这篇关于Ruby on Rails生产日志轮换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!