Skip to content

Instantly share code, notes, and snippets.

@bobishh
Created June 14, 2017 09:49
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 bobishh/d2f0a4250506a7fc8013b429a33194d1 to your computer and use it in GitHub Desktop.
Save bobishh/d2f0a4250506a7fc8013b429a33194d1 to your computer and use it in GitHub Desktop.
Initializer which shows which line generated SQL
# coding: utf-8
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