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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With