Sha256: 9881bc2b0e3eb867b0e8c027f9013cf80f585e9ad975e1bb55d07ace7b66bf57

Contents?: true

Size: 781 Bytes

Versions: 5

Compression:

Stored size: 781 Bytes

Contents

module Timber
  module Contexts
    # Custom contexts allow you to add application specific context not covered elsewhere.
    #
    # @example Adding a context
    #   custom_context = Timber::Contexts::Custom.new(type: :keyspace, data: %{my: "data"})
    #   Timber::CurrentContext.with(custom_context) do
    #     # ... anything logged here will have the context ...
    #   end
    class Custom < Context
      attr_reader :type, :data

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

      def keyspace
        :custom
      end

      def as_json(_options = {})
        {type => data}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
timber-1.0.3 lib/timber/contexts/custom.rb
timberio-1.0.3 lib/timber/contexts/custom.rb
timberio-1.0.2 lib/timber/contexts/custom.rb
timberio-1.0.1 lib/timber/contexts/custom.rb
timberio-1.0.0 lib/timber/contexts/custom.rb