Class: ActiveSupport::BacktraceCleaner

### Home Classes Methods

### In Files

- lib/active_support/backtrace_cleaner.rb

### Parent

Object

### Methods

- ::new
- #add_filter
- #add_silencer
- #clean
- #remove_filters!
- #remove_silencers!

### Class/Module Index

Quicksearch

- ActiveSupport
- ActiveSupport::Autoload
- ActiveSupport::BacktraceCleaner
- ActiveSupport::Base64
- ActiveSupport::BasicObject
- ActiveSupport::Benchmarkable
- ActiveSupport::BufferedLogger
- ActiveSupport::BufferedLogger::Severity
- ActiveSupport::Cache
- ActiveSupport::Cache::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::NullStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Configurable::Configuration
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::ClassCache
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::FileWatcher
- ActiveSupport::FileWatcher::Backend
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- ActiveSupport::JSON::Encoding
- ActiveSupport::JSON::Encoding::CircularReferenceError
- ActiveSupport::JSON::Encoding::Encoder
- ActiveSupport::JSON::Variable
- ActiveSupport::LogSubscriber
- ActiveSupport::LogSubscriber::TestHelper
- ActiveSupport::LogSubscriber::TestHelper::MockLogger
- ActiveSupport::Memoizable
- ActiveSupport::Memoizable::InstanceMethods
- ActiveSupport::MessageEncryptor
- ActiveSupport::MessageEncryptor::InvalidMessage
- ActiveSupport::MessageVerifier
- ActiveSupport::MessageVerifier::InvalidSignature
- ActiveSupport::Multibyte
- ActiveSupport::Multibyte::Chars
- ActiveSupport::Multibyte::EncodingError
- ActiveSupport::Multibyte::Unicode
- ActiveSupport::Multibyte::Unicode::Codepoint
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- ActiveSupport::Notifications
- ActiveSupport::Notifications::Event
- ActiveSupport::Notifications::Fanout
- ActiveSupport::Notifications::Instrumenter
- ActiveSupport::OrderedHash
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SafeBuffer::SafeConcatError
- ActiveSupport::StringInquirer
- ActiveSupport::TaggedLogging
- ActiveSupport::TestCase
- ActiveSupport::Testing
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::Declarative
- ActiveSupport::Testing::Isolation
- ActiveSupport::Testing::Isolation::Forking
- ActiveSupport::Testing::Isolation::MiniTest
- ActiveSupport::Testing::Isolation::Subprocess
- ActiveSupport::Testing::Isolation::TestUnit
- ActiveSupport::Testing::Pending
- ActiveSupport::Testing::Performance
- ActiveSupport::Testing::Performance::Benchmarker
- ActiveSupport::Testing::Performance::ForClassicTestUnit
- ActiveSupport::Testing::Performance::ForMiniTest
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Amount
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit
- ActiveSupport::Testing::Performance::Metrics::GcRuns
- ActiveSupport::Testing::Performance::Metrics::GcTime
- ActiveSupport::Testing::Performance::Metrics::Memory
- ActiveSupport::Testing::Performance::Metrics::Objects
- ActiveSupport::Testing::Performance::Metrics::ProcessTime
- ActiveSupport::Testing::Performance::Metrics::Time
- ActiveSupport::Testing::Performance::Metrics::UserTime
- ActiveSupport::Testing::Performance::Metrics::WallTime
- ActiveSupport::Testing::Performance::Performer
- ActiveSupport::Testing::Performance::Profiler
- ActiveSupport::Testing::ProxyTestResult
- ActiveSupport::Testing::RemoteError
- ActiveSupport::Testing::SetupAndTeardown
- ActiveSupport::Testing::SetupAndTeardown::ClassMethods
- ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit
- ActiveSupport::Testing::SetupAndTeardown::ForMiniTest
- ActiveSupport::TimeWithZone
- ActiveSupport::TimeZone
- ActiveSupport::XmlMini
- ActiveSupport::XmlMini_LibXMLSAX
- ActiveSupport::XmlMini_LibXMLSAX::HashBuilder
- ActiveSupport::XmlMini_NokogiriSAX
- ActiveSupport::XmlMini_NokogiriSAX::HashBuilder
- Test
- Test::Unit
- Test::Unit::Collector
- Test::Unit::Collector::ObjectSpace
- Object
- Object::HashWithIndifferentAccess
- Object::MissingSourceFile
- ERB
- ERB::Util
- I18n
- I18n::Railtie
- LoadError
- LoadError
- Logger
- Logger::SimpleFormatter
- Array
- Base64
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- QualifiedConstUtils
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass
- URI

No matching classes.

# ActiveSupport::BacktraceCleaner

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.

#### Example:

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

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.

### Public Class Methods

new() click to toggle source

    # File lib/active_support/backtrace_cleaner.rb, line 25
    def initialize
      @filters, @silencers = [], []
    end

### Public Instance Methods

add_filter(&block) click to toggle source

Adds a filter from the block provided. Each line in the backtrace will be mapped against this filter.

Example:

    # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
    backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }

    # File lib/active_support/backtrace_cleaner.rb, line 49
    def add_filter(&block)
      @filters << block
    end

add_silencer(&block) click to toggle source

Adds a silencer from the block provided. If the silencer returns true for a given line, it will be excluded from the clean backtrace.

Example:

    # Will reject all lines that include the word "mongrel", like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
    backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }

    # File lib/active_support/backtrace_cleaner.rb, line 60
    def add_silencer(&block)
      @silencers << block
    end

clean(backtrace, kind = :silent) click to toggle source

Returns the backtrace after all filters and silencers have been run against it. Filters run first, then silencers.

    # File lib/active_support/backtrace_cleaner.rb, line 30
    def clean(backtrace, kind = :silent)
      filtered = filter(backtrace)

      case kind
      when :silent
        silence(filtered)
      when :noise
        noise(filtered)
      else
        filtered
      end
    end

remove_filters!() click to toggle source

    # File lib/active_support/backtrace_cleaner.rb, line 70
    def remove_filters!
      @filters = []
    end

remove_silencers!() click to toggle source

Will remove all silencers, but leave in the filters. This is useful if your context of debugging suddenly expands as you suspect a bug in one of the libraries you use.

    # File lib/active_support/backtrace_cleaner.rb, line 66
    def remove_silencers!
      @silencers = []
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.