Turn off verbose sql/ActiveRecord for Rails 3.1.1

和自甴很熟 提交于 2019-12-30 01:53:12

问题


Whereas the verbose feature of SQL/ActiveRecord calls is useful most of the time, I would like to turn it off in cases where I have some looping going on.

Is there a way to turn it off?

irb(main):055:0> City.first
  ←[1m←[35mCity Load (1.0ms)←[0m  SELECT `cities`.* FROM `cities` LIMIT 1
=> #<City id: 1, name: "bla bla", state_id: 1, zip: nil, country_id: nil,
created_at: "2011-03-27 14:11:28", updated_at: "2011-08-16 11:14:36", guid: "5PK
fvvz2Gsi">

回答1:


In console:
Disable:

old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil

Enable:

ActiveRecord::Base.logger = old_logger



回答2:


In Rails 4 I've been annoyed by ActiveRecord logging SQL statements in the middle of my specs so I disable it by adding this to config/environments/test.rb:

Rails.application.configure do
  # ... 
  config.log_level = :info
end


来源:https://stackoverflow.com/questions/7966948/turn-off-verbose-sql-activerecord-for-rails-3-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!