Sha256: 90af9b45769c080742c632e5a765af57928275779d291e914f11ec215cddd6e9

Contents?: true

Size: 797 Bytes

Versions: 19

Compression:

Stored size: 797 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 = {})
        {Timber::Util::Object.try(type, :to_sym) => data}
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
timber-2.0.7 lib/timber/contexts/custom.rb
timber-2.0.6 lib/timber/contexts/custom.rb
timber-2.0.5 lib/timber/contexts/custom.rb
timber-2.0.4 lib/timber/contexts/custom.rb
timber-2.0.3 lib/timber/contexts/custom.rb
timber-2.0.2 lib/timber/contexts/custom.rb
timber-2.0.1 lib/timber/contexts/custom.rb
timber-2.0.0 lib/timber/contexts/custom.rb
timber-1.1.14 lib/timber/contexts/custom.rb
timber-1.1.13 lib/timber/contexts/custom.rb
timber-1.1.12 lib/timber/contexts/custom.rb
timber-1.1.11 lib/timber/contexts/custom.rb
timber-1.1.10 lib/timber/contexts/custom.rb
timber-1.1.9 lib/timber/contexts/custom.rb
timber-1.1.8 lib/timber/contexts/custom.rb
timber-1.1.7 lib/timber/contexts/custom.rb
timber-1.1.6 lib/timber/contexts/custom.rb
timber-1.1.5 lib/timber/contexts/custom.rb
timber-1.1.4 lib/timber/contexts/custom.rb