Module: LogStashLogger::TaggedLogging::Formatter

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

Instance Method Summary collapse

Instance Method Details

#clear_tags!Object



31
32
33
# File 'lib/logstash-logger/tagged_logging.rb', line 31

def clear_tags!
  current_tags.clear
end

#current_tagsObject



35
36
37
# File 'lib/logstash-logger/tagged_logging.rb', line 35

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

#pop_tags(size = 1) ⇒ Object



27
28
29
# File 'lib/logstash-logger/tagged_logging.rb', line 27

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

#push_tags(*tags) ⇒ Object



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

def push_tags(*tags)
  tags.flatten.reject(&:empty?).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