Module: LogStashLogger::TaggedLogging::Formatter

Included in:
Formatter::Base
Defined in:
lib/logstash-logger/tagged_logging.rb

Instance Method Summary collapse

Instance Method Details

#clear_tags!Object



33
34
35
# File 'lib/logstash-logger/tagged_logging.rb', line 33

def clear_tags!
  current_tags.clear
end

#current_tagsObject



37
38
39
# File 'lib/logstash-logger/tagged_logging.rb', line 37

def current_tags
  Thread.current[:logstash_logger_tags] ||= []
end

#pop_tags(size = 1) ⇒ Object



29
30
31
# File 'lib/logstash-logger/tagged_logging.rb', line 29

def pop_tags(size = 1)
  current_tags.pop size
end

#push_tags(*tags) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/logstash-logger/tagged_logging.rb', line 21

def push_tags(*tags)
  non_empty_tags = tags.flatten.compact.reject { |t| t.respond_to?(:empty?) && t.empty? }

  non_empty_tags.tap do |new_tags|
    current_tags.concat new_tags
  end
end

#tagged(*tags) ⇒ Object



14
15
16
17
18
19
# File 'lib/logstash-logger/tagged_logging.rb', line 14

def tagged(*tags)
  new_tags = push_tags(*tags)
  yield self
ensure
  pop_tags(new_tags.size)
end