开发者

How to disable the logger in script/console

开发者 https://www.devze.com 2023-01-24 03:04 出处:网络
In my .irbrc file I require \'logger\' to allow me to see the SQL executed when querying ActiveRecords all while in the 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号