Rails 日志过于冗长 [英] Rails log too verbose
本文介绍了Rails 日志过于冗长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止 Rails 日志过多?这是我的 production.log 文件中的一个典型跟踪,很多部分,缓存命中...它在开发中很有用,但我不想在我的生产环境中使用它.
How can I prevent Rails to log too much? Here is a typical trace in my production.log file, many partials, cache hits... It's useful in development but I don't want it in my production environment.
Started GET "/?redirected=true" for 46.193.131.53 at 2012-08-16 18:39:20 +0200
Processing by HomeController#index as HTML
Parameters: {"redirected"=>"true"}
Rendered application/_successfully_connected.html.haml (0.8ms)
Rendered hotspot_infos/_infos.html.haml (0.4ms)
Rendered application/_hotspot_infos.html.haml (1.8ms)
Rendered application/_news.html.haml (0.3ms)
Read fragment views/social-zone-341-directory (0.5ms)
Rendered application/_directory.html.haml (2.5ms)
Rendered application/_meteo.html.haml (1.1ms)
Rendered application/_notifications.html.haml (0.8ms)
Rendered application/_like_button.html.haml (0.3ms)
Rendered application/_navbar.html.haml (4.2ms)
Rendered application/_connection.html.haml (0.5ms)
Rendered application/_gallery.html.haml (0.2ms)
Rendered application/_search_bar.html.haml (0.4ms)
Rendered pictures/_picture_frame.html.haml (0.3ms)
Rendered application/_profile_preview.html.haml (1.4ms)
Rendered application/_profile_block.html.haml (1.7ms)
Rendered application/_menus.html.haml (3.3ms)
Rendered application/_left_pane.html.haml (5.5ms)
Rendered application/_langs.html.haml (0.8ms)
Rendered application/_footer.html.haml (1.9ms)
Rendered application/_flash_modal.html.haml (0.1ms)
Rendered application/_connection_required.js.erb (0.2ms)
Completed 200 OK in 159ms (Views: 25.5ms | ActiveRecord: 88.0ms)
感谢您的帮助
PS:我使用的是 Rails 3.2.6
PS: I'm using Rails 3.2.6
推荐答案
在 Rails 4 中会有一个清理日志的设置:
In Rails 4 there will be a setting to clean up logs:
config.action_view.logger = nil
要在 Rails 3 中实现这一点,您必须对 ActionView 进行猴子补丁:
To achieve that in Rails 3, you have to monkey patch ActionView:
module ActionView
class LogSubscriber < ActiveSupport::LogSubscriber
def logger
@memoized_logger ||= Logger.new('/dev/null')
end
end
end
这篇关于Rails 日志过于冗长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文