Class: Lumberjack::EcsDevice::MessageExceptionFormatter

Inherits:
Object
  • Object
show all
Includes:
ExceptionHash
Defined in:
lib/lumberjack_ecs_device.rb

Overview

Formatter to format a messge as an error if it is an exception.

Instance Method Summary collapse

Constructor Details

#initialize(device = nil) ⇒ MessageExceptionFormatter

Returns a new instance of MessageExceptionFormatter.



30
31
32
# File 'lib/lumberjack_ecs_device.rb', line 30

def initialize(device = nil)
  @device = device
end

Instance Method Details

#call(object) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lumberjack_ecs_device.rb', line 34

def call(object)
  if object.is_a?(Exception)
    {
      "message" => object.inspect,
      "error" => exception_hash(object, @device)
    }
  elsif object.is_a?(Hash)
    {"message" => object}
  elsif object.nil?
    {"message" => nil}
  else
    message = object.to_s
    max_message_length = @device.max_message_length
    if max_message_length && message.length > max_message_length
      message = message[0, max_message_length]
    end
    {"message" => message}
  end
end