Module: LunaPark::Notifiers::TaggedLog::Formatter

Defined in:
lib/luna_park/notifiers/tagged_log.rb

Instance Method Summary collapse

Instance Method Details

#call(severity, timestamp, progname, msg) ⇒ Object



30
31
32
# File 'lib/luna_park/notifiers/tagged_log.rb', line 30

def call(severity, timestamp, progname, msg)
  super(severity, timestamp, progname, msg, tags_text)
end

#clear_tags!Object



52
53
54
# File 'lib/luna_park/notifiers/tagged_log.rb', line 52

def clear_tags!
  current_tags.clear
end

#current_tagsObject



56
57
58
59
# File 'lib/luna_park/notifiers/tagged_log.rb', line 56

def current_tags
  thread_key = @thread_key ||= "tagged_log_tag_store_tags:#{object_id}"
  Thread.current[thread_key] ||= []
end

#pop_tags(size = 1) ⇒ Object



48
49
50
# File 'lib/luna_park/notifiers/tagged_log.rb', line 48

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

#push_tags(*tags) ⇒ Object



41
42
43
44
45
46
# File 'lib/luna_park/notifiers/tagged_log.rb', line 41

def push_tags(*tags)
  tags.flatten!
  tags.reject! { |tag| tag.respond_to?(:empty?) ? tag.empty? : !tag }
  current_tags.concat tags
  tags
end

#tagged(*tags) ⇒ Object



34
35
36
37
38
39
# File 'lib/luna_park/notifiers/tagged_log.rb', line 34

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

#tags_textObject



61
62
63
# File 'lib/luna_park/notifiers/tagged_log.rb', line 61

def tags_text
  current_tags.join(' ').strip
end