Sha256: 4388666871bc06c44e9ff124a26a68de59d2d030b6d166254e766b4157b48c24
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
require "timber/event" require "timber/util" module Timber module Events # The error event is used to track errors and exceptions. # # @note This event should be installed automatically through integrations, # such as the {Integrations::ActionDispatch::DebugExceptions} integration. class Error < Timber::Event BACKTRACE_JSON_MAX_BYTES = 8192.freeze MESSAGE_MAX_BYTES = 8192.freeze attr_reader :name, :error_message, :backtrace 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 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 alias to_h to_hash # Builds a hash representation containing simple objects, suitable for serialization (JSON). def as_json(_options = {}) {:error => to_hash} end def message message = "#{name}" if !error_message.nil? message << " (#{error_message})" end message end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
timber-2.6.2 | lib/timber/events/error.rb |
timber-2.6.1 | lib/timber/events/error.rb |
timber-2.6.0 | lib/timber/events/error.rb |
timber-2.6.0.pre.beta2 | lib/timber/events/error.rb |