在控制台中禁用Rails SQL日志记录 [英] Disable Rails SQL logging in console
问题描述
当我在控制台中执行命令时,是否有禁用SQL查询记录的方法?理想情况下,如果我可以禁用它,并在控制台中使用命令重新启用它将是巨大的。
Is there a way to disable SQL query logging when I'm executing commands in the console? Ideally, it would be great if I can just disable it and re-enable it with a command in the console.
我试图调试的东西,并使用puts 打印出一些相关数据。但是,sql查询输出很难阅读。
I'm trying to debug something and using "puts" to print out some relevant data. However, the sql query output is making it hard to read.
编辑:
我发现了另一个解决方案,因为设置logger为nil有时会引发错误,如果除了我的代码之外的东西试图调用logger.warn
I found another solution, since setting the logger to nil sometimes raised an error, if something other than my code tried to call logger.warn
而不是设置记录器到 nil
,您可以将记录器的级别设置为 1
。
Instead of setting the logger to nil
you can set the level of the logger to 1
.
ActiveRecord::Base.logger.level = 1 # or Logger::INFO
推荐答案
将其关闭:
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
on:
ActiveRecord::Base.logger = old_logger
这篇关于在控制台中禁用Rails SQL日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!