Ruby-on-rails 如何在 Rails 控制台中隐藏数据库输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7724188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can you hide database output in Rails console?
提问by Roger Ertesvag
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?
在较新版本的 Rails 中,我猜从 3 起,数据库查询将输出到控制台。这在大多数情况下很有用,但是当您不想看到它时,如何隐藏它?
回答by Aaron B. Russell
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)
因为它可以防止尝试使用指向设置为 nil 的记录器的指针时出现问题(来源:在控制台中禁用 Rails SQL 日志记录)
To turn it back on
重新打开它
ActiveRecord::Base.logger.level = 0
回答by madth3
Short answer...
In the file development.rb change or add the value of config.log_levelso that there's a line like
简短回答...在文件 development.rb 中更改或添加的值,config.log_level以便有一行
config.log_level = :info
回答by tatiCarvalho
From a friend of mine:
来自我的一个朋友:
your_query; nil
回答by brokenbeatnik
In Rails 3.2, setting
在 Rails 3.2 中,设置
config.logger.level = Logger::INFO
worked fine for me for turning off SQL output.
关闭 SQL 输出对我来说效果很好。
回答by dennis
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.
我看到你已经得到了你需要的答案,尽管我想向你推荐“安静资产”gem,大多数日志数据将是资产编译和包含,这个 gem 将删除它并仍然输出查询和数据行为。
Have fun
玩得开心

