ActiveRecord SQL queries not getting logged

旧巷老猫 提交于 2021-02-10 12:01:21

问题


I have been facing a weird problem for some time, wherein ActiveRecord queries are not getting logged in the terminal, or in the Rails console (using ActiveRecord::Base.logger = Logger.new(STDOUT)).

This is the exception that I get:

Could not log "sql.active_record" event. NameError: undefined 
local variable or method `s' 
for # ActiveSupport::Notifications::Event:0x007f9ae02a60c0.

I tried out a few things, including reinstalling Rails, but to no avail.

Apart from wondering why this is happening, I’m unable to check the actual SQL queries fired against the database as a result.


回答1:


I ran into something similar a ways back.

I was able to fix it by adding

# config/environments/development.rb
config.logger = Logger.new(STDOUT)

and

# config/environment.rb
# To prevent log buffering
$stdout.sync = true



回答2:


This problem was due to a stray (and accidental) 's' being inserted in the instrumenter.rb file. Removing the character helped me fix the problem. I'm not sure about why reinstalling rails did not help me though.



来源:https://stackoverflow.com/questions/17865288/activerecord-sql-queries-not-getting-logged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!