Class: Lumberjack::Formatter::ExceptionFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::ExceptionFormatter
- Defined in:
- lib/lumberjack/formatter/exception_formatter.rb
Overview
Format an exception including the backtrace. You can specify an object that responds to call as a backtrace cleaner. The exception backtrace will be passed to this object and the returned array is what will be logged. You can use this to clean out superfluous lines.
Instance Attribute Summary collapse
-
#backtrace_cleaner ⇒ #call?
An object that responds to
calland takes an array of strings (the backtrace) and returns an array of strings.
Instance Method Summary collapse
-
#call(exception) ⇒ String
Format an exception with its message and backtrace.
-
#initialize(backtrace_cleaner = nil) ⇒ ExceptionFormatter
constructor
A new instance of ExceptionFormatter.
Constructor Details
#initialize(backtrace_cleaner = nil) ⇒ ExceptionFormatter
Returns a new instance of ExceptionFormatter.
20 21 22 |
# File 'lib/lumberjack/formatter/exception_formatter.rb', line 20 def initialize(backtrace_cleaner = nil) self.backtrace_cleaner = backtrace_cleaner end |
Instance Attribute Details
#backtrace_cleaner ⇒ #call?
Returns An object that responds to call and takes an array of strings (the backtrace) and returns an array of strings.
15 16 17 |
# File 'lib/lumberjack/formatter/exception_formatter.rb', line 15 def backtrace_cleaner @backtrace_cleaner end |
Instance Method Details
#call(exception) ⇒ String
Format an exception with its message and backtrace.
28 29 30 31 32 33 34 35 36 |
# File 'lib/lumberjack/formatter/exception_formatter.rb', line 28 def call(exception) = +"#{exception.class.name}: #{exception.}" trace = exception.backtrace if trace trace = clean_backtrace(trace) << "#{Lumberjack::LINE_SEPARATOR} #{trace.join("#{Lumberjack::LINE_SEPARATOR} ")}" end end |