简体   繁体   English

在Rails开发模式下记录日志?

[英]Log rotation in Rails DEVELOPMENT mode?

For a Rails 3.1 (will be 3.2 very soon), I have exceptionally verbose logs that have a lot of additional worker information spewing forth into them. 对于Rails 3.1(很快就会是3.2),我有非常详细的日志,其中有大量额外的工作人员信息涌入其中。

I routinely end up with multigigabyte development.log files. 我经常以multigigabyte development.log文件结束。 I've seen some various chatter around about rotating production logs, however I've not found anything that seems applicable to development.log rotation. 我已经看到有关旋转生产日志的各种各样的讨论,但是我没有发现任何看起来适用于development.log轮换的内容。

How do you rotate your development.log at every 100.megabytes or so? 你如何在每100.megabytes左右轮换你的development.log OR WHAT I WOULD PREFER is to actually truncate the head of the file so that only the most recent items remain in the log, up to 100MB of the most recent entries. 或者我想要的是实际截断文件的头部,以便只有最新的项目保留在日志中,最多100MB的最新条目。

I have played with this a little and am thinking more and more than nothing quite like this exists at present and that perhaps I should implement something that will use the ruby File.truncate somehow, however I'm not sure of the efficacy of this yet on the tail end of the file as of yet. 我已经玩过这个了,并且我正在考虑的事情比目前存在的更多,并且我可能应该实现一些将以某种方式使用ruby File.truncate东西,但是我不确定它的功效到目前为止在文件的尾部。

You can actually tell the Ruby Logger class to rotate the files in the constructor: 您实际上可以告诉Ruby Logger类在构造函数中旋转文件:

http://corelib.rubyonrails.org/classes/Logger.html#M000163 http://corelib.rubyonrails.org/classes/Logger.html#M000163

Example: 例:

Logger.new(name, shift_age = 7, shift_size = 1048576)

In one of my enrivornment files I have the following line: 在我的一个enrivornment文件中,我有以下行:

config.logger = Logger.new("#{RAILS_ROOT}/log/#{ENV['RAILS_ENV']}.log", 10, 1048576)

This keeps the last 10 logfiles which are rotated every 1 MB. 这将保留最后10个每1 MB旋转的日志文件。

On OSX i would use newsyslog 在OSX上我会使用newsyslog

/etc/newsyslog.conf /etc/newsyslog.conf

On a Linux OS: logrotate 在Linux OS上:logrotate

logrotate 日志轮播

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM