Sha256: de67ba4f77a16363a13273495238305501ff5138b4e195efcad54385cfdad68f

Contents?: true

Size: 797 Bytes

Versions: 9

Compression:

Stored size: 797 Bytes

Contents

module LogjamAgent
  module LoggingAttributes

    extend self

    def attributes=(attributes)
      Thread.current.thread_variable_set(:__logjam_agent_logging_attributes__, attributes)
    end

    def attributes
      Thread.current.thread_variable_get(:__logjam_agent_logging_attributes__) ||
        Thread.current.thread_variable_set(:__logjam_agent_logging_attributes__, [])
    end

    def set_attribute(name, value)
      if attribute = attributes.detect{|n,v| n == name}
        attribute[1] = value
      else
        attributes << [name, value]
      end
    end

    def reset_attributes
      self.attributes = []
    end

    def render_attributes
      attrs = attributes.select{|k,v| !k.nil? }
      attrs.empty? ? nil : attrs.map{|k,v| "#{k}=#{v}"}.join(" ")
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logjam_agent-0.37.1 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.37.0 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.36.0 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.35.1 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.35.0 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.34.3 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.34.2 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.34.1 lib/logjam_agent/logging_attributes.rb
logjam_agent-0.34.0 lib/logjam_agent/logging_attributes.rb