简体   繁体   English

Rails 6.1 开发环境不打印查询触发器代码行,详细激活

[英]Rails 6.1 development environment not printing query trigger code line with verbose active

I have both lines:我有两条线:

  # Highlight code that triggered database queries in logs.
  config.active_record.verbose_query_logs = true
  ActiveRecord::Base.verbose_query_logs = true

in my config/environments/development/rb在我的config/environments/development/rb

But in my development log the sql queries are logged like:但在我的开发日志中,sql 查询记录如下:

2022-08-10 08:35:18.536410 D [74:puma srv tp 004] (0.006ms) ActiveRecord -- Model Load -- { :sql => "SELECT ....", :binds => { .... }, :allocations => 1, :cached => true }

I have an N+1 queries issue to fix, but the information about which line in the code triggered the query is missing, so this is not helping me much.我有一个 N+1 查询问题要修复,但缺少关于代码中哪一行触发查询的信息,所以这对我没有多大帮助。

I tried also using active-record-query-trace gem, with configuration:我还尝试使用带有配置的 active-record-query-trace gem:

if Rails.env.development?
  ActiveRecordQueryTrace.enabled = true
  ActiveRecordQueryTrace.level = :full
  ActiveRecordQueryTrace.colorize = true           # No colorization (default)
  ActiveRecordQueryTrace.colorize = :light_purple
  # Optional: other gem config options go here
end

but I see no changes at all in how queries are logged.但我发现查询的记录方式完全没有变化。

How can I enable the logging of the line triggering the query?如何启用触发查询的行的日志记录?

Thanks谢谢

If you want to know the reference point that made a DB query I used to use a gem called Marginalia.如果您想知道进行数据库查询的参考点,我曾经使用名为 Marginalia 的 gem。 I use it in Rails 6 and it does exactaly what you are looking for.我在 Rails 6 中使用它,它完全符合您的要求。

From what I am reading Rails 7 includes this feature as a native feature (which is quite awesome I might add).从我正在阅读的内容来看,Rails 7 包含此功能作为本机功能(我可能会添加这非常棒)。

I found a link that talks about this: Rails 7 includes Marginalia我找到了一个讨论这个的链接: Rails 7 includes Marginalia

Their example says:他们的例子说:

# config/application.rb

module Saeloun
  class Application < Rails::Application
     config.active_record.query_log_tags_enabled = true
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM