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.
# File lib/active_support/tagged_logging.rb, line 35 def add(severity, message = nil, progname = nil, &block) message = (block_given? ? block.call : progname) if message.nil? @logger.add(severity, "#{tags_text}#{message}", progname) end
# File lib/active_support/tagged_logging.rb, line 48 def flush @tags.delete(Thread.current) @logger.flush if @logger.respond_to?(:flush) end
# File lib/active_support/tagged_logging.rb, line 53 def method_missing(method, *args) @logger.send(method, *args) end
Generated with the Darkfish Rdoc Generator 2.