开发者

How can you hide database output in Rails console?

开发者 https://www.devze.com 2023-04-11 23:25 出处:网络
开发者_开发技巧In newer version of Rails, I\'m guessing from 3 up, database queries are output to the console. This is useful most of the time, but how can you hide it when you do not want to see it?A

开发者_开发技巧In newer version of Rails, I'm guessing from 3 up, database queries are output to the console. This is useful most of the time, but how can you hide it when you do not want to see it?


A better way of doing this is by typing this into the console:

ActiveRecord::Base.logger.level = 1 

as it prevents problems trying use a pointer to a logger that is set to nil (source: Disable Rails SQL logging in console)

To turn it back on

ActiveRecord::Base.logger.level = 0


ActiveRecord::Base.logger = nil

from here


Short answer... In the file development.rb change or add the value of config.log_level so that there's a line like

config.log_level = :info


From a friend of mine:

your_query; nil


In Rails 3.2, setting

config.logger.level = Logger::INFO

worked fine for me for turning off SQL output.


I see you already got your needed answer although I would like to advise the 'quiet assets' gem to you, most of the log data will be asset compiling and inclusions, this gem will remove that and still output the queries and data behavior.

Have fun

0

精彩评论

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

关注公众号