问题
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