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
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/context.rb
lumberjack-1.2.8 lib/lumberjack/context.rb
lumberjack-1.2.7 lib/lumberjack/context.rb
lumberjack-1.2.6 lib/lumberjack/context.rb
lumberjack-1.2.5 lib/lumberjack/context.rb
lumberjack-1.2.4 lib/lumberjack/context.rb
lumberjack-1.2.3 lib/lumberjack/context.rb
lumberjack-1.2.2 lib/lumberjack/context.rb
lumberjack-1.2.1 lib/lumberjack/context.rb