Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 986
Coderama Avatar asked Nov 05 '10 02:11

Coderama


2 Answers

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
like image 161
cldwalker Avatar answered Nov 07 '22 22:11

cldwalker


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.

like image 33
thenengah Avatar answered Nov 08 '22 00:11

thenengah