Module: Kafka::TaggedFormatter
- Defined in:
- lib/kafka/tagged_logger.rb
Instance Method Summary collapse
- #call(severity, timestamp, progname, msg) ⇒ Object
- #clear_tags! ⇒ Object
- #current_tags ⇒ Object
- #pop_tags(size = 1) ⇒ Object
- #push_tags(*tags) ⇒ Object
- #tagged(*tags) ⇒ Object
- #tags_text ⇒ Object
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
9 10 11 |
# File 'lib/kafka/tagged_logger.rb', line 9 def call(severity, , progname, msg) super(severity, , progname, "#{}#{msg}") end |
#clear_tags! ⇒ Object
30 31 32 |
# File 'lib/kafka/tagged_logger.rb', line 30 def .clear end |
#current_tags ⇒ Object
34 35 36 37 38 |
# File 'lib/kafka/tagged_logger.rb', line 34 def # 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) ⇒ Object
26 27 28 |
# File 'lib/kafka/tagged_logger.rb', line 26 def (size = 1) .pop size end |
#push_tags(*tags) ⇒ Object
20 21 22 23 24 |
# File 'lib/kafka/tagged_logger.rb', line 20 def (*) .flatten.reject { |t| t.nil? || t.empty? }.tap do || .concat end end |
#tagged(*tags) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/kafka/tagged_logger.rb', line 13 def tagged(*) = (*) yield self ensure (.size) end |
#tags_text ⇒ Object
40 41 42 43 44 45 |
# File 'lib/kafka/tagged_logger.rb', line 40 def = if .any? .collect { |tag| "[#{tag}] " }.join end end |