Class: Timber::Events::Exception

Inherits:
Timber::Event
  • Object
show all
Defined in:
lib/timber/events/exception.rb

Overview

Note:

This event should be installed automatically through probes, such as the Probes::ActionDispatchDebugExceptions probe.

The exception event is used to track exceptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Exception

Returns a new instance of Exception.



10
11
12
13
14
# File 'lib/timber/events/exception.rb', line 10

def initialize(attributes)
  @name = attributes[:name] || raise(ArgumentError.new(":name is required"))
  @exception_message = attributes[:exception_message] || raise(ArgumentError.new(":exception_message is required"))
  @backtrace = attributes[:backtrace]
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def backtrace
  @backtrace
end

#exception_messageObject (readonly)

Returns the value of attribute exception_message.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def exception_message
  @exception_message
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def name
  @name
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



21
22
23
# File 'lib/timber/events/exception.rb', line 21

def as_json(_options = {})
  {:exception => to_hash}
end

#messageObject



25
26
27
28
29
30
31
32
# File 'lib/timber/events/exception.rb', line 25

def message
  message = "#{name} (#{exception_message}):"
  if backtrace.is_a?(Array) && backtrace.length > 0
    message << "\n\n"
    message << backtrace.join("\n")
  end
  message
end

#to_hashObject Also known as: to_h



16
17
18
# File 'lib/timber/events/exception.rb', line 16

def to_hash
  {name: name, message: exception_message, backtrace: backtrace}
end