Sha256: 26e075cf2c101921b9d3a7d1183ff36a4613259319117b7db08c4b9bd20b6d21

Contents?: true

Size: 762 Bytes

Versions: 13

Compression:

Stored size: 762 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
      @keyspace = :custom

      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 as_json(_options = {})
        {type => data}
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timber-1.1.2 lib/timber/contexts/custom.rb
timber-1.1.1 lib/timber/contexts/custom.rb
timber-1.1.0 lib/timber/contexts/custom.rb
timber-1.0.13 lib/timber/contexts/custom.rb
timber-1.0.12 lib/timber/contexts/custom.rb
timber-1.0.11 lib/timber/contexts/custom.rb
timber-1.0.10 lib/timber/contexts/custom.rb
timber-1.0.9 lib/timber/contexts/custom.rb
timber-1.0.8 lib/timber/contexts/custom.rb
timber-1.0.7 lib/timber/contexts/custom.rb
timber-1.0.6 lib/timber/contexts/custom.rb
timber-1.0.5 lib/timber/contexts/custom.rb
timber-1.0.4 lib/timber/contexts/custom.rb