Class: Timber::Events::Error

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

Overview

Note:

This event should be installed automatically through integrations, such as the Integrations::ActionDispatch::DebugExceptions integration.

The error event is used to track errors and exceptions.

Direct Known Subclasses

Exception

Constant Summary collapse

MAX_MESSAGE_BYTES =
8192.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Error

Returns a new instance of Error.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/timber/events/error.rb', line 15

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

  @error_message = attributes[:error_message] || raise(ArgumentError.new(":error_message is required"))
  @error_message = @error_message.byteslice(0, MAX_MESSAGE_BYTES)

  backtrace = attributes[:backtrace]
  if !backtrace.nil? && backtrace != []
    @backtrace = backtrace[0..9].collect { |line| parse_backtrace_line(line) }
  end
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



13
14
15
# File 'lib/timber/events/error.rb', line 13

def backtrace
  @backtrace
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



13
14
15
# File 'lib/timber/events/error.rb', line 13

def error_message
  @error_message
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/timber/events/error.rb', line 13

def name
  @name
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

Builds a hash representation containing simple objects, suitable for serialization (JSON).



33
34
35
# File 'lib/timber/events/error.rb', line 33

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

#messageObject



37
38
39
# File 'lib/timber/events/error.rb', line 37

def message
  "#{name} (#{error_message})"
end

#to_hashObject Also known as: to_h



27
28
29
# File 'lib/timber/events/error.rb', line 27

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