class Logging::Layouts::Parseable

Public Instance Methods

format_obj(obj) click to toggle source

Public: Take a given object and convert it into a format suitable for inclusion as a log message. The conversion allows the object to be more easily expressed in YAML or JSON form.

If the object is an Exception, then this method will return a Hash containing the exception class name, message, and backtrace (if any).

If the object is a string, wrap it in a hash.

obj - The Object to format

Returns the formatted Object.

# File lib/napa/logger/parseable.rb, line 20
def format_obj(obj)
  case obj
  when Exception
    h = { class: obj.class.name,
          message: obj.message }
    h[:backtrace] = obj.backtrace if @backtrace && !obj.backtrace.nil?
    h
  when Time
    iso8601_format(obj)
  when String
    { text: obj }
  else
    obj
  end
end