Skip to content

Instantly share code, notes, and snippets.

@firstrow
Created January 5, 2017 15:52
Show Gist options
  • Save firstrow/48fffcd7c0aa7e71b3b964dc684b3b9f to your computer and use it in GitHub Desktop.
Save firstrow/48fffcd7c0aa7e71b3b964dc684b3b9f to your computer and use it in GitHub Desktop.
Log active record SQL call line
module LogQuerySource
def debug(*args, &block)
return unless super
backtrace = Rails.backtrace_cleaner.clean caller
# logger.debug(backtrace)
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