Sha256: 03a08219089d90176b9606783dd6634a9c477639e0f0568b93a7e11dd9507e85

Contents?: true

Size: 708 Bytes

Versions: 15

Compression:

Stored size: 708 Bytes

Contents

module Timber
  module Contexts
    # Custom contexts allow you to add application specific context not covered elsewhere.
    #
    # @example Adding a context
    #   logger.with_context(build: {version: "1.0.0"}) 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 = {})
        {Timber::Util::Object.try(type, :to_sym) => data}
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
timber-2.0.24 lib/timber/contexts/custom.rb
timber-2.0.23 lib/timber/contexts/custom.rb
timber-2.0.22 lib/timber/contexts/custom.rb
timber-2.0.21 lib/timber/contexts/custom.rb
timber-2.0.20 lib/timber/contexts/custom.rb
timber-2.0.19 lib/timber/contexts/custom.rb
timber-2.0.17 lib/timber/contexts/custom.rb
timber-2.0.16 lib/timber/contexts/custom.rb
timber-2.0.15 lib/timber/contexts/custom.rb
timber-2.0.14 lib/timber/contexts/custom.rb
timber-2.0.12 lib/timber/contexts/custom.rb
timber-2.0.11 lib/timber/contexts/custom.rb
timber-2.0.10 lib/timber/contexts/custom.rb
timber-2.0.9 lib/timber/contexts/custom.rb
timber-2.0.8 lib/timber/contexts/custom.rb