Class: Hatchet::SimpleFormatter
- Inherits:
-
Object
- Object
- Hatchet::SimpleFormatter
- Includes:
- BacktraceFormatter, ThreadNameFormatter
- Defined in:
- lib/hatchet/simple_formatter.rb
Overview
Public: Simple formatter class. Outputs messages with just level, context, and message.
Instance Attribute Summary collapse
-
#thread_context ⇒ Object
Public: Gets or sets whether the context of the thread (pid and thread ID) should be included into the output messages.
Attributes included from BacktraceFormatter
Instance Method Summary collapse
-
#format(level, context, message) ⇒ Object
Public: Returns the formatted message.
-
#initialize ⇒ SimpleFormatter
constructor
Public: Initialize a new instance.
Methods included from BacktraceFormatter
Constructor Details
#initialize ⇒ SimpleFormatter
Public: Initialize a new instance.
19 20 21 |
# File 'lib/hatchet/simple_formatter.rb', line 19 def initialize @backtrace = true end |
Instance Attribute Details
#thread_context ⇒ Object
Public: Gets or sets whether the context of the thread (pid and thread ID) should be included into the output messages.
15 16 17 |
# File 'lib/hatchet/simple_formatter.rb', line 15 def thread_context @thread_context end |
Instance Method Details
#format(level, context, message) ⇒ Object
Public: Returns the formatted message.
level - The severity of the log message. context - The context of the log message. message - The message provided by the log caller.
Returns messages in the format:
[THREAD] - LEVEL - CONTEXT - MESSAGE
BACKTRACE
The backtrace is only present if the message contains an error and the presence of the context of the thread context is managed via the #thread_context attribute.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hatchet/simple_formatter.rb', line 38 def format(level, context, ) msg = .to_s.strip thread = thread_context ? "[#{thread_name}] - " : nil if .ndc.any? msg = "#{thread}#{level.to_s.upcase} - #{context} #{.ndc.join(' ')} - #{msg}" else msg = "#{thread}#{level.to_s.upcase} - #{context} - #{msg}" end with_backtrace(, msg) end |