module Lumberjack::TaggedLoggerSupport

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

Public Instance Methods

clear_tags!() click to toggle source
# File lib/lumberjack/tagged_logger_support.rb, line 62
def clear_tags!
  tag("tagged" => nil)
end
pop_tags(size = 1) click to toggle source
# File lib/lumberjack/tagged_logger_support.rb, line 56
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) click to toggle source
# File lib/lumberjack/tagged_logger_support.rb, line 52
def push_tags(*tags)
  tagged(*tags)
end
tagged(*tags, &block) click to toggle source

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”.

# File lib/lumberjack/tagged_logger_support.rb, line 43
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