Sha256: 98aeb0791872081be0ae1cff61721c09fdd911d0b1b615d8d6d1210b995d2068

Contents?: true

Size: 523 Bytes

Versions: 3

Compression:

Stored size: 523 Bytes

Contents

module Semlogr
  module Context
    class LogContext
      def self.current
        Thread.current[:semlogr_log_context] ||= []
      end

      def self.push_property(**properties)
        LogContext.current << properties

        yield if block_given?
      ensure
        LogContext.current.pop
      end

      def self.get_property(key)
        LogContext.current
          .reverse_each do |properties|
            return properties[key] if properties.key?(key)
          end

        nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
semlogr-0.2.3 lib/semlogr/context/log_context.rb
semlogr-0.2.2 lib/semlogr/context/log_context.rb
semlogr-0.2.1 lib/semlogr/context/log_context.rb