Sha256: edd66008d51168840551433bbe3715be92e316e11005b313afad9f73717e7f55

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

module Timber
  # Holds the log line counts on a per context basis in memory.
  class CurrentLineIndexes
    THREAD_NAMESPACE = :_timber_current_line_counts.freeze

    include Patterns::DelegatedSingleton

    def context_removed(context)
      indexes.delete(context)
    end

    def indexes
      Thread.current[THREAD_NAMESPACE] ||= {}
    end

    def log_line_added(_log_line)
      CurrentContext.valid_stack.each do |context|
        if indexes.key?(context)
          indexes[context] += 1
        else
          indexes[context] = 0
        end
      end
    end

    def reset!
      indexes.clear
    end

    def snapshot
      # No need to cache, this is blown out for each log line
      LineIndexesSnapshot.new(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 lib/timber/current_line_indexes.rb