Class: Hatchet::StandardFormatter
- Inherits:
-
Object
- Object
- Hatchet::StandardFormatter
- Includes:
- BacktraceFormatter, ThreadNameFormatter
- Defined in:
- lib/hatchet/standard_formatter.rb
Overview
Public: Standard formatter class. Outputs messages in the TTCC of log4j.
Instance Attribute Summary
Attributes included from BacktraceFormatter
Instance Method Summary collapse
-
#format(level, context, message) ⇒ Object
Public: Returns the formatted message.
-
#initialize ⇒ StandardFormatter
constructor
Public: Creates a new instance.
Methods included from BacktraceFormatter
Constructor Details
#initialize ⇒ StandardFormatter
Public: Creates a new instance.
13 14 15 16 17 18 |
# File 'lib/hatchet/standard_formatter.rb', line 13 def initialize @backtrace = true @secs = 0 @millis = -1 @level_cache = {} 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:
%Y-%m-%d %H:%M:%S.%L [THREAD] LEVEL CONTEXT - MESSAGE
BACKTRACE
The backtrace is only present if the message contains an error.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hatchet/standard_formatter.rb', line 33 def format(level, context, ) msg = .to_s.strip if .ndc.any? msg = "#{} [#{thread_name}] #{format_level(level)} #{context} #{.ndc.join(' ')} - #{msg}" else msg = "#{} [#{thread_name}] #{format_level(level)} #{context} - #{msg}" end with_backtrace(, msg) end |