Skip to content

Instantly share code, notes, and snippets.

@jahfer
Last active November 26, 2019 14:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahfer/9901fe8d8bcf32277985a9d8b894755e to your computer and use it in GitHub Desktop.
Save jahfer/9901fe8d8bcf32277985a9d8b894755e to your computer and use it in GitHub Desktop.
Small tweak to output Active Record logs inside of a test with the stacktrace attached
module MyLogSubscriber
def sql(*args)
trace = caller
Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer { |line| not line =~ /^(components)\// }
puts Rails.backtrace_cleaner.clean(trace)
super
puts "---------------"
end
end
::ActiveRecord::LogSubscriber.prepend(MyLogSubscriber)
ActiveRecord::Base.logger = Logger.new(STDOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment