Created
November 21, 2016 13:31
-
-
Save lindskogen/e8b3760dfe45c6e9333bb8d1404dd169 to your computer and use it in GitHub Desktop.
ActiveRecordLogSubscriber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Drop this into config/initializers to print line number of each query called by ActiveRecord | |
module LogQuerySource | |
def debug(*args, &block) | |
return unless super | |
backtrace = Rails.backtrace_cleaner.clean caller | |
relevant_caller_line = backtrace.detect do |caller_line| | |
!caller_line.include?('/initializers/') | |
end | |
if relevant_caller_line | |
logger.debug(" ↳ #{ relevant_caller_line.sub("#{ Rails.root }/", '') }") | |
end | |
end | |
end | |
ActiveRecord::LogSubscriber.send :prepend, LogQuerySource |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment