Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.