Parent

Class Index [+]

Quicksearch

ActiveSupport::TaggedLogging

Wraps any standard Logger class to provide tagging capabilities. Examples:

  Logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
  Logger.tagged("BCX") { Logger.info "Stuff" }                            # Logs "[BCX] Stuff"
  Logger.tagged("BCX", "Jason") { Logger.info "Stuff" }                   # Logs "[BCX] [Jason] Stuff"
  Logger.tagged("BCX") { Logger.tagged("Jason") { Logger.info "Stuff" } } # Logs "[BCX] [Jason] Stuff"

This is used by the default Rails.logger as configured by Railties to make it easy to stamp log lines with subdomains, request ids, and anything else to aid debugging of multi-user production applications.

Public Class Methods

new(logger) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 16
16:     def initialize(logger)
17:       @logger = logger
18:     end

Public Instance Methods

add(severity, message = nil, progname = nil, &block) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 46
46:     def add(severity, message = nil, progname = nil, &block)
47:       message = (block_given? ? block.call : progname) if message.nil?
48:       @logger.add(severity, "#{tags_text}#{message}", progname)
49:     end
clear_tags!() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 37
37:     def clear_tags!
38:       current_tags.clear
39:     end
flush() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 59
59:     def flush
60:       clear_tags!
61:       @logger.flush if @logger.respond_to?(:flush)
62:     end
method_missing(method, *args) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 64
64:     def method_missing(method, *args)
65:       @logger.send(method, *args)
66:     end
pop_tags(size = 1) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 33
33:     def pop_tags(size = 1)
34:       current_tags.pop size
35:     end
push_tags(*tags) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 27
27:     def push_tags(*tags)
28:       tags.flatten.reject(&:blank?).tap do |new_tags|
29:         current_tags.concat new_tags
30:       end
31:     end
silence(temporary_level = Logger::ERROR, &block) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 41
41:     def silence(temporary_level = Logger::ERROR, &block)
42:       @logger.silence(temporary_level, &block)
43:     end
tagged(*tags) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 20
20:     def tagged(*tags)
21:       new_tags = push_tags(*tags)
22:       yield self
23:     ensure
24:       pop_tags(new_tags.size)
25:     end

Private Instance Methods

current_tags() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 76
76:       def current_tags
77:         Thread.current[:activesupport_tagged_logging_tags] ||= []
78:       end
tags_text() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 69
69:       def tags_text
70:         tags = current_tags
71:         if tags.any?
72:           tags.collect { |tag| "[#{tag}] " }.join
73:         end
74:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.