How to disable the logger in script/console
In my .irbrc file I require 'logger' to allow me to see the SQL executed when querying ActiveRecords all while in the script/console.
My question开发者_开发百科 is, how do I temporarily turn off the logger so it doesn't display the SQL just for a few ActiveRecord queries?
To toggle logging in script/console here's what I use:
def show_log
change_log(STDOUT)
end
def hide_log
change_log(nil)
end
def change_log(stream, colorize=true)
ActiveRecord::Base.logger = ::Logger.new(stream)
ActiveRecord::Base.clear_all_connections!
ActiveRecord::Base.colorize_logging = colorize
end
you can turn off your logger by running in production mode or by adjusting your logger file in development.rb
environment file in your config directory if you are in fact running in development on your localhost.
精彩评论