Module: Lumberjack::TaggedLoggerSupport

Defined in:
lib/lumberjack/tagged_logger_support.rb

Overview

Methods to make Lumberjack::Logger API compatible with ActiveSupport::TaggedLogger.

Defined Under Namespace

Classes: Formatter

Instance Method Summary collapse

Instance Method Details

#clear_tags!Object



63
64
65
# File 'lib/lumberjack/tagged_logger_support.rb', line 63

def clear_tags!
  tag("tagged" => nil)
end

#pop_tags(size = 1) ⇒ Object



57
58
59
60
61
# File 'lib/lumberjack/tagged_logger_support.rb', line 57

def pop_tags(size = 1)
  tagged_values = Array(@tags["tagged"])
  tagged_values = (tagged_values.size > size ? tagged_values[0, tagged_values.size - size] : nil)
  tag("tagged" => tagged_values)
end

#push_tags(*tags) ⇒ Object



53
54
55
# File 'lib/lumberjack/tagged_logger_support.rb', line 53

def push_tags(*tags)
  tagged(*tags)
end

#tagged(*tags, &block) ⇒ Object

Compatibility with ActiveSupport::TaggedLogging which only supports adding tags as strings. If a tag looks like “key:value” or “key=value”, it will be added as a key value pair. Otherwise it will be appended to a list named “tagged”.



44
45
46
47
48
49
50
51
# File 'lib/lumberjack/tagged_logger_support.rb', line 44

def tagged(*tags, &block)
  tag_hash = {}
  tags.flatten.each do |tag|
    tagged_values = Array(tag_hash["tagged"] || self.tags["tagged"])
    tag_hash["tagged"] = tagged_values + [tag]
  end
  tag(tag_hash, &block)
end