Type:
Class

Backtraces often include many lines that are not relevant for the context under review. This makes it hard to find the signal amongst the backtrace noise, and adds debugging time. With a BacktraceCleaner, filters and silencers are used to remove the noisy lines, so that only the most relevant lines remain.

Filters are used to modify lines of data, while silencers are used to remove lines entirely. The typical filter use case is to remove lengthy path information from the start of each line, and view file paths relevant to the app directory instead of the file system root. The typical silencer use case is to exclude the output of a noisy library from the backtrace, so that you can focus on the rest.

bc = BacktraceCleaner.new
bc.add_filter   { |line| line.gsub(Rails.root, '') } # strip the Rails.root prefix
bc.add_silencer { |line| line =~ /mongrel|rubygems/ } # skip any lines from mongrel or rubygems
bc.clean(exception.backtrace) # perform the cleanup

To reconfigure an existing BacktraceCleaner (like the default one in Rails) and show as much data as possible, you can always call BacktraceCleaner#remove_silencers!, which will restore the backtrace to a pristine state. If you need to reconfigure an existing BacktraceCleaner so that it does not filter or modify the paths of any lines of the backtrace, you can call BacktraceCleaner#remove_filters! These two methods will give you a completely untouched backtrace.

Inspired by the Quiet Backtrace gem by Thoughtbot.

add_filter

add_filter(&block) Instance Public methods Adds a filter from the block

2015-06-20 00:00:00
filter

filter(backtrace, kind = :silent) Instance Public methods Alias for:

2015-06-20 00:00:00
add_silencer

add_silencer(&block) Instance Public methods Adds a silencer from the block

2015-06-20 00:00:00
remove_filters!

remove_filters!() Instance Public methods Removes all filters, but leaves in

2015-06-20 00:00:00
new

new() Class Public methods

2015-06-20 00:00:00
clean

clean(backtrace, kind = :silent) Instance Public methods Returns the backtrace

2015-06-20 00:00:00
remove_silencers!

remove_silencers!() Instance Public methods Will remove all silencers, but leave

2015-06-20 00:00:00