Module: Logged::TaggedLogging

Included in:
Logger
Defined in:
lib/logged/tagged_logging.rb

Overview

Tagged logging support

Instance Method Summary collapse

Instance Method Details

#current_tagsObject



26
27
28
# File 'lib/logged/tagged_logging.rb', line 26

def current_tags
  Thread.current["logged_logger_tags_#{component}"] ||= []
end

#flushObject



12
13
14
# File 'lib/logged/tagged_logging.rb', line 12

def flush
  current_tags.clear
end

#pop_tags(size = 1) ⇒ Object



22
23
24
# File 'lib/logged/tagged_logging.rb', line 22

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

#push_tags(*tags) ⇒ Object



16
17
18
19
20
# File 'lib/logged/tagged_logging.rb', line 16

def push_tags(*tags)
  tags.flatten.reject(&:blank?).tap do |new_tags|
    current_tags.concat(new_tags)
  end
end

#tagged(*tags) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/logged/tagged_logging.rb', line 4

def tagged(*tags)
  new_tags = push_tags(*tags)

  yield self
ensure
  pop_tags(new_tags.size)
end