Class: Logtail::Events::Error

Inherits:
Logtail::Event show all
Defined in:
lib/logtail/events/error.rb

Direct Known Subclasses

Exception

Instance Attribute Summary collapse

Attributes inherited from Logtail::Event

#metadata

Instance Method Summary collapse

Methods inherited from Logtail::Event

#inspect, #to_json, #to_msgpack, #to_s

Constructor Details

#initialize(attributes) ⇒ Error

Returns a new instance of Error.



10
11
12
13
14
15
16
17
# File 'lib/logtail/events/error.rb', line 10

def initialize(attributes)
  @name = attributes[:name]
  @error_message = attributes[:error_message]

  if attributes[:backtrace]
    @backtrace_json = attributes[:backtrace].to_json
  end
end

Instance Attribute Details

#backtrace_jsonObject (readonly)

Returns the value of attribute backtrace_json.



8
9
10
# File 'lib/logtail/events/error.rb', line 8

def backtrace_json
  @backtrace_json
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



8
9
10
# File 'lib/logtail/events/error.rb', line 8

def error_message
  @error_message
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/logtail/events/error.rb', line 8

def name
  @name
end

Instance Method Details

#messageObject



19
20
21
22
23
24
25
26
27
# File 'lib/logtail/events/error.rb', line 19

def message
  message = "#{name}"

  if !error_message.nil?
    message << " (#{error_message})"
  end

  message
end

#to_hashObject



29
30
31
32
33
34
35
36
37
# File 'lib/logtail/events/error.rb', line 29

def to_hash
  {
    error: {
      name: name,
      message: error_message,
      backtrace_json: backtrace_json
    }
  }
end