禁用 Rails SQL 日志的方法? [英] Way to disable Rails SQL logs?
本文介绍了禁用 Rails SQL 日志的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了更改日志级别之外,有没有办法在 Rails 中禁用 SQL 日志?我有一些 logger.debug 语句,我想在我的 ActiveRecord 模型中打印出来,但我想隐藏 SQL 语句.
Is there a way to disable SQL logs in Rails, other than changing the log level? I've got some logger.debug statements that I'd like to print out in my ActiveRecord models, but I want to hide the SQL statements.
推荐答案
您可以对其进行 moneky-patch,将其放在一个文件中,例如 config/initializers/disable_ar_logging.rb
:
You can moneky-patch it, put this in a file such as config/initializers/disable_ar_logging.rb
:
class ActiveRecord::ConnectionAdapters::AbstractAdapter
def log_info(*args); end
end
这篇关于禁用 Rails SQL 日志的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文