by
back

Disable Action View Logger in production for Ruby on Rails

If you use many partials in your Ruby on Rails views, then the logfiles of your application might become flooded with logging of these partials.

In Rails 4 you can easily disable action view logging in the production environment

config/environments/production.rb

config.action_view.logger = nil

If you need a solution for your old Ruby on Rails 3 project, you need to monkey patch Rails:

config/initilizer/disable_logging.rb

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


comments powered by Disqus