How to disable the logger in script/console
-
29-09-2019 - |
Question
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?
Solution
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
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow