如何防止 Rails 在生产中使用 Action View 登录 [英] How to prevent Rails from Action View logging in production
问题描述
在 rails 3.2.0 中,是否可以关闭 rails 日志以渲染视图ActionView:: 生产环境中的 LogSubscriber.
In rails 3.2.0,is it possible to turn off rails logging for rendering of views in ActionView:: LogSubscriber in production environment.
目前我发现抑制的唯一方法是猴子修补它并增加日志级别以通过以下方式进行调试.有没有更好的方法来做到这一点或任何配置?
Currently only way i found to supress is to monkey patch it and increase the log level to debug in the below way. Is there a better way to do this or any configuration?
module ActionView
class LogSubscriber
def render_template(event)
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
message << (" (%.1fms)" % event.duration)
debug(message)
end
alias :render_partial :render_template
alias :render_collection :render_template
end
end
推荐答案
ActionView 使用 ActiveSupport::Notifications 和 ActiveSupport::LogSubscriber 检测其事件并将其从日志中静音,就像在您的环境文件中包含以下内容一样简单:
ActionView uses ActiveSupport::Notifications and ActiveSupport::LogSubscriber to instrument its events, and to silence it from the logs is as simple as including the following in your environment file:
%w{render_template render_partial render_collection}.each do |event|
ActiveSupport::Notifications.unsubscribe "#{event}.action_view"
end
干杯!
这篇关于如何防止 Rails 在生产中使用 Action View 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!