Last active
November 26, 2019 14:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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