Module: LogjamAgent::LoggingAttributes

Extended by:
LoggingAttributes
Included in:
LoggingAttributes
Defined in:
lib/logjam_agent/logging_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



10
11
12
13
# File 'lib/logjam_agent/logging_attributes.rb', line 10

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

#attributes=(attributes) ⇒ Object



6
7
8
# File 'lib/logjam_agent/logging_attributes.rb', line 6

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

#non_nil_attributesObject



32
33
34
# File 'lib/logjam_agent/logging_attributes.rb', line 32

def non_nil_attributes
  attributes.select{|k,v| !k.nil? }
end

#render_attributesObject



27
28
29
30
# File 'lib/logjam_agent/logging_attributes.rb', line 27

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

#reset_attributesObject



23
24
25
# File 'lib/logjam_agent/logging_attributes.rb', line 23

def reset_attributes
  self.attributes = []
end

#set_attribute(name, value) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/logjam_agent/logging_attributes.rb', line 15

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