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:       @tags   = Hash.new { |h,k| h[k] = [] }
19:     end

Public Instance Methods

add(severity, message = nil, progname = nil, &block) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 35
35:     def add(severity, message = nil, progname = nil, &block)
36:       message = (block_given? ? block.call : progname) if message.nil?
37:       @logger.add(severity, "#{tags_text}#{message}", progname)
38:     end
flush() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 48
48:     def flush
49:       @tags.delete(Thread.current)
50:       @logger.flush if @logger.respond_to?(:flush)
51:     end
method_missing(method, *args) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 53
53:     def method_missing(method, *args)
54:       @logger.send(method, *args)
55:     end
silence(temporary_level = Logger::ERROR, &block) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 30
30:     def silence(temporary_level = Logger::ERROR, &block)
31:       @logger.silence(temporary_level, &block)
32:     end
tagged(*new_tags) click to toggle source
    # File lib/active_support/tagged_logging.rb, line 21
21:     def tagged(*new_tags)
22:       tags     = current_tags
23:       new_tags = Array.wrap(new_tags).flatten.reject(&:blank?)
24:       tags.concat new_tags
25:       yield
26:     ensure
27:       new_tags.size.times { tags.pop }
28:     end

Protected Instance Methods

current_tags() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 66
66:     def current_tags
67:       @tags[Thread.current]
68:     end
tags_text() click to toggle source
    # File lib/active_support/tagged_logging.rb, line 59
59:     def tags_text
60:       tags = current_tags
61:       if tags.any?
62:         tags.collect { |tag| "[#{tag}]" }.join(" ") + " "
63:       end
64:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.