How can I disable logging in Ruby on Rails on a per-action basis?

archbishop picture archbishop · Feb 4, 2010 · Viewed 24.8k times · Source

I have a Rails application which has an action which is invoked frequently enough to be inconvenient when I am developing, as it results in a lot of extra log output I don't care about. How can I get rails not to log anything (controller, action, parameters, complection time, etc.) for just this one action? I'd like to conditionalize it on RAILS_ENV as well, so logs in production are complete.

Thanks!

Answer

Josh Delsman picture Josh Delsman · Feb 6, 2010

You can silence the Rails logger object:

def action
  Rails.logger.silence do
    # Things within this block will not be logged...
  end
end