How to prevent Rails from Action View logging in production

流过昼夜 提交于 2019-12-01 05:08:02

问题


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

回答1:


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

Cheers!



来源:https://stackoverflow.com/questions/12984984/how-to-prevent-rails-from-action-view-logging-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!