class Hatchet::SimpleFormatter

Public: Simple formatter class. Outputs messages with just level, context, and message.

Attributes

thread_context[RW]

Public: Gets or sets whether the context of the thread (pid and thread ID) should be included into the output messages.

Public Class Methods

new() click to toggle source

Public: Initialize a new instance.

# File lib/hatchet/simple_formatter.rb, line 18
def initialize
  @backtrace = true
end

Public Instance Methods

format(level, context, message) click to toggle source

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.

# File lib/hatchet/simple_formatter.rb, line 37
def format(level, context, message)
  msg = message.to_s.strip
  thread = thread_context ? "[#{thread_name}] - " : nil

  if message.ndc.any?
    msg = "#{thread}#{level.to_s.upcase} - #{context} #{message.ndc.join(' ')} - #{msg}"
  else
    msg = "#{thread}#{level.to_s.upcase} - #{context} - #{msg}"
  end

  with_backtrace(message, msg)
end