Module: KeyValueLogging::TaggedLogging::Formatter

Defined in:
lib/key_value_logging/tagged_logging.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#key_value_formatObject

Returns the value of attribute key_value_format.



11
12
13
# File 'lib/key_value_logging/tagged_logging.rb', line 11

def key_value_format
  @key_value_format
end

Instance Method Details

#call(severity, timestamp, progname, msg) ⇒ Object

This method is invoked when a log event occurs.



14
15
16
17
# File 'lib/key_value_logging/tagged_logging.rb', line 14

def call(severity, timestamp, progname, msg)
  formatted_msg = self.send("process_#{key_value_format}", msg)
  super(severity, timestamp, progname, formatted_msg)
end

#clear_tags!Object



38
39
40
# File 'lib/key_value_logging/tagged_logging.rb', line 38

def clear_tags!
  current_tags.clear
end

#current_tagsObject



42
43
44
# File 'lib/key_value_logging/tagged_logging.rb', line 42

def current_tags
  Thread.current[:key_value_tagged_logging_tags] ||= {}
end

#pop_tags(keys) ⇒ Object



34
35
36
# File 'lib/key_value_logging/tagged_logging.rb', line 34

def pop_tags(keys)
  keys.each { |key| current_tags.delete(key) }
end

#push_tags(tags) ⇒ Object



28
29
30
31
32
# File 'lib/key_value_logging/tagged_logging.rb', line 28

def push_tags(tags)
  tags.tap do |new_tags|
    current_tags.merge! new_tags
  end
end

#tagged(tags) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/key_value_logging/tagged_logging.rb', line 19

def tagged(tags)
  # Add temporary tags to current tags
  new_tags = push_tags(tags)
  yield self
ensure
  # Remove the temporary tags from current tags
  pop_tags(tags.keys)
end