Module: ActiveSupport::TaggedLogging::Formatter

Defined in:
activesupport/lib/active_support/tagged_logging.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

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

This method is invoked when a log event occurs.


32
33
34
# File 'activesupport/lib/active_support/tagged_logging.rb', line 32

def call(severity, timestamp, progname, msg)
  super(severity, timestamp, progname, "#{tags_text}#{msg}")
end

#clear_tags!Object


54
55
56
# File 'activesupport/lib/active_support/tagged_logging.rb', line 54

def clear_tags!
  current_tags.clear
end

#current_tagsObject


58
59
60
61
62
# File 'activesupport/lib/active_support/tagged_logging.rb', line 58

def current_tags
  # We use our object ID here to avoid conflicting with other instances
  thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}"
  IsolatedExecutionState[thread_key] ||= []
end

#pop_tags(size = 1) ⇒ Object


50
51
52
# File 'activesupport/lib/active_support/tagged_logging.rb', line 50

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

#push_tags(*tags) ⇒ Object


43
44
45
46
47
48
# File 'activesupport/lib/active_support/tagged_logging.rb', line 43

def push_tags(*tags)
  tags.flatten!
  tags.reject!(&:blank?)
  current_tags.concat tags
  tags
end

#tagged(*tags) ⇒ Object


36
37
38
39
40
41
# File 'activesupport/lib/active_support/tagged_logging.rb', line 36

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

#tags_textObject


64
65
66
67
68
69
70
71
# File 'activesupport/lib/active_support/tagged_logging.rb', line 64

def tags_text
  tags = current_tags
  if tags.one?
    "[#{tags[0]}] "
  elsif tags.any?
    tags.collect { |tag| "[#{tag}] " }.join
  end
end