Skip to content

Instantly share code, notes, and snippets.

@lindskogen
Created November 21, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindskogen/e8b3760dfe45c6e9333bb8d1404dd169 to your computer and use it in GitHub Desktop.
Save lindskogen/e8b3760dfe45c6e9333bb8d1404dd169 to your computer and use it in GitHub Desktop.
ActiveRecordLogSubscriber
# 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