Sha256: 5ada5ead18957a8d02afcb964e27f211e997cfd4e23d2c12c43be58c63b0abdf

Contents?: true

Size: 924 Bytes

Versions: 1

Compression:

Stored size: 924 Bytes

Contents

module Timber
  module Contexts
    class Exception < Context
      ROOT_KEY = :exception.freeze
      VERSION = 1.freeze

      attr_reader :exception

      def initialize(exception)
        # Initialize should be as fast as possible since it is executed inline.
        # Hence the lazy methods below.
        @exception = exception
        super()
      end

      def backtrace
        # only the first 5 lines to save on space
        @backtrace ||= exception.backtrace[0..4]
      end

      def name
        @name ||= exception.class.name
      end

      def message
        @message ||= exception.message
      end

      private
        def json_payload
          @json_payload ||= Macros::DeepMerger.merge({
            # order is relevant for logfmt styling
            :name => name,
            :message => message,
            :backtrace => backtrace
          }, super).freeze
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 lib/timber/contexts/exception.rb