Disable Rails SQL logging in console Disable Rails SQL logging in console ruby-on-rails ruby-on-rails

Disable Rails SQL logging in console


To turn it off:

old_logger = ActiveRecord::Base.loggerActiveRecord::Base.logger = nil

To turn it back on:

ActiveRecord::Base.logger = old_logger


Here's a variation I consider somewhat cleaner, that still allows potential other logging from AR. In config/environments/development.rb :

config.after_initialize do  ActiveRecord::Base.logger = Rails.logger.clone  ActiveRecord::Base.logger.level = Logger::INFOend


This might not be a suitable solution for the console, but Rails has a method for this problem: Logger#silence

ActiveRecord::Base.logger.silence do  # the stuff you want to be silencedend