Sha256: a77c1bc9f4649a66cd330b58961b370a65d09ac2877708c48e21bb0933316e5d

Contents?: true

Size: 680 Bytes

Versions: 23

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

module Lumberjack
  # A context is used to store tags that are then added to all log entries within a block.
  class Context
    attr_reader :tags

    def initialize(parent_context = nil)
      @tags = {}
      @tags.merge!(parent_context.tags) if parent_context
    end

    # Set tags on the context.
    def tag(tags)
      tags.each do |key, value|
        @tags[key.to_s] = value
      end
    end

    # Get a context tag.
    def [](key)
      @tags[key.to_s]
    end

    # Set a context tag.
    def []=(key, value)
      @tags[key.to_s] = value
    end

    # Clear all the context data.
    def reset
      @tags.clear
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
lumberjack-1.2.0 lib/lumberjack/context.rb
lumberjack-1.1.1 lib/lumberjack/context.rb
lumberjack-1.1.0 lib/lumberjack/context.rb