Sha256: 1d8f7a20f884eb699f63319de275061fe12b8c15acf4ccf55d3ddbd845b85e3d

Contents?: true

Size: 736 Bytes

Versions: 2

Compression:

Stored size: 736 Bytes

Contents

module Timber
  # Base class for `Timber::Events::*`
  # @private
  class Event
    attr_reader :message, :metadata
    def initialize(message, metadata)
      @message = message || ""
      @metadata = metadata || {}
    end

    # This ensures that Timber events get logged as messages if they are passed to
    # the standard ::Logger.
    #
    # See: https://github.com/ruby/ruby/blob/f6e77b9d3555c1fbaa8aab1cdc0bd6bde95f62c6/lib/logger.rb#L615
    def inspect
      message
    end

    def to_json(options = {})
      metadata.to_json(options)
    end

    def to_hash
      metadata
    end
    alias to_h to_hash

    def to_msgpack(*args)
      metadata.to_msgpack(*args)
    end

    def to_s
      message
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-3.0.1 lib/timber/event.rb
timber-3.0.0 lib/timber/event.rb