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

BACKTRACE_JSON_MAX_BYTES =
8192.freeze
MESSAGE_MAX_BYTES =
8192.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Error

Returns a new instance of Error.



16
17
18
19
20
21
# File 'lib/timber/events/error.rb', line 16

def initialize(attributes)
  normalizer = Util::AttributeNormalizer.new(attributes)
  @name = normalizer.fetch!(:name, :string)
  @error_message = normalizer.fetch(:error_message, :string, :limit => MESSAGE_MAX_BYTES)
  @backtrace = normalizer.fetch(:backtrace, :array)
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



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

def backtrace
  @backtrace
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



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

def error_message
  @error_message
end

#nameObject (readonly)

Returns the value of attribute name.



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

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
40
41
42
43
44
45
# File 'lib/timber/events/error.rb', line 37

def message
  message = "#{name}"

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

  message
end

#to_hashObject Also known as: to_h



23
24
25
26
27
28
29
# File 'lib/timber/events/error.rb', line 23

def to_hash
  @to_hash ||= Util::NonNilHashBuilder.build do |h|
    h.add(:name, name)
    h.add(:message, error_message)
    h.add(:backtrace_json, backtrace, :json_encode => true, :limit => BACKTRACE_JSON_MAX_BYTES)
  end
end