Class: Hatchet::StandardFormatter

Inherits:
Object
  • Object
show all
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

#backtrace_limit

Instance Method Summary collapse

Methods included from BacktraceFormatter

#backtrace, #backtrace=

Constructor Details

#initializeStandardFormatter

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, message)
  msg = message.to_s.strip

  if message.ndc.any?
    msg = "#{timestamp} [#{thread_name}] #{format_level(level)} #{context} #{message.ndc.join(' ')} - #{msg}"
  else
    msg = "#{timestamp} [#{thread_name}] #{format_level(level)} #{context} - #{msg}"
  end

  with_backtrace(message, msg)
end