module Kafka::TaggedFormatter

Public Instance Methods

call(severity, timestamp, progname, msg) click to toggle source
Calls superclass method
# File lib/kafka/tagged_logger.rb, line 9
def call(severity, timestamp, progname, msg)
  super(severity, timestamp, progname, "#{tags_text}#{msg}")
end
clear_tags!() click to toggle source
# File lib/kafka/tagged_logger.rb, line 30
def clear_tags!
  current_tags.clear
end
current_tags() click to toggle source
# File lib/kafka/tagged_logger.rb, line 34
def current_tags
  # We use our object ID here to avoid conflicting with other instances
  thread_key = @thread_key ||= "kafka_tagged_logging_tags:#{object_id}".freeze
  Thread.current[thread_key] ||= []
end
pop_tags(size = 1) click to toggle source
# File lib/kafka/tagged_logger.rb, line 26
def pop_tags(size = 1)
  current_tags.pop size
end
push_tags(*tags) click to toggle source
# File lib/kafka/tagged_logger.rb, line 20
def push_tags(*tags)
  tags.flatten.reject { |t| t.nil? || t.empty? }.tap do |new_tags|
    current_tags.concat new_tags
  end
end
tagged(*tags) { |self| ... } click to toggle source
# File lib/kafka/tagged_logger.rb, line 13
def tagged(*tags)
  new_tags = push_tags(*tags)
  yield self
ensure
  pop_tags(new_tags.size)
end
tags_text() click to toggle source
# File lib/kafka/tagged_logger.rb, line 40
def tags_text
  tags = current_tags
  if tags.any?
    tags.collect { |tag| "[#{tag}] " }.join
  end
end