Class: Logfoo::StderrExceptionHanlder
- Inherits:
-
Object
- Object
- Logfoo::StderrExceptionHanlder
- Defined in:
- lib/logfoo/exception_handlers/stderr_exception_handler.rb
Constant Summary collapse
- BACKTRACE_LINE =
"\t%s\n".freeze
- EXCEPTION_LINE =
"%s: %s\n".freeze
Instance Method Summary collapse
- #call(entry) ⇒ Object
- #format(entry) ⇒ Object
-
#initialize(appender = nil) ⇒ StderrExceptionHanlder
constructor
A new instance of StderrExceptionHanlder.
Constructor Details
#initialize(appender = nil) ⇒ StderrExceptionHanlder
Returns a new instance of StderrExceptionHanlder.
7 8 9 |
# File 'lib/logfoo/exception_handlers/stderr_exception_handler.rb', line 7 def initialize(appender = nil) @appender = appender || IoAppender.new(STDERR) end |
Instance Method Details
#call(entry) ⇒ Object
11 12 13 |
# File 'lib/logfoo/exception_handlers/stderr_exception_handler.rb', line 11 def call(entry) @appender.write format(entry) end |
#format(entry) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/logfoo/exception_handlers/stderr_exception_handler.rb', line 15 def format(entry) values = [] values << (EXCEPTION_LINE % [entry.exception.class, entry.exception.]) if entry.exception.backtrace.is_a?(Array) values << entry.exception.backtrace.map{|l| BACKTRACE_LINE % l }.join end values.join end |