Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Rails from Action View logging in production

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
like image 219
Phani Avatar asked Oct 20 '12 03:10

Phani


2 Answers

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!

like image 102
Thiago Jackiw Avatar answered Sep 18 '22 14:09

Thiago Jackiw


You can directly turn off action_view logger.

Rails.application.configure do
  config.action_view.logger = nil
end
like image 38
swordray Avatar answered Sep 21 '22 14:09

swordray