diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-20 14:18:29 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-20 14:18:29 -0800 |
commit | a0da46ecaf354a5b95210e11a4b7aba90a1d7383 (patch) | |
tree | b558eb5c65cb48b82d240d18e3580be5d1faed7d /activesupport/lib/active_support | |
parent | f02cec3c49bd08c0b3f8733ae7356b124f0622a4 (diff) | |
download | rails-a0da46ecaf354a5b95210e11a4b7aba90a1d7383.tar.gz rails-a0da46ecaf354a5b95210e11a4b7aba90a1d7383.tar.bz2 rails-a0da46ecaf354a5b95210e11a4b7aba90a1d7383.zip |
pushed broadcasting down to a module
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/logger.rb | 80 |
1 files changed, 34 insertions, 46 deletions
diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index 3a2646d55f..d055767eab 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -1,54 +1,42 @@ require 'logger' module ActiveSupport - # Broadcasts logs to multiple loggers - class BroadcastLogger < ::Logger # :nodoc: - attr_reader :logs - - def initialize(logs) - super(nil) - @logs = logs - end - - def progname - logs.first.progname - end - - def progname=(name) - logs.each { |x| x.progname = name } - end - - def formatter - logs.first.formatter - end - - def formatter=(formatter) - logs.each { |x| x.formatter = formatter } - end - - def level - logs.first.level - end - - def level=(level) - logs.each { |x| x.level = level } - end - - def add(severity, message = nil, progname = nil, &block) - super - logs.each { |l| l.add(severity, message, progname, &block) } - end - - def <<(x) - logs.each { |l| l << x } - end - - def close - logs.each(&:close) + class Logger < ::Logger + # Broadcasts logs to multiple loggers + def self.broadcast(logger) # :nodoc: + Module.new do + define_method(:add) do |*args, &block| + logger.add(*args, &block) + super(*args, &block) + end + + define_method(:<<) do |x| + logger << x + super(x) + end + + define_method(:close) do + logger.close + super() + end + + define_method(:progname=) do |name| + logger.progname = name + super(name) + end + + define_method(:formatter=) do |formatter| + logger.formatter = formatter + super(formatter) + end + + define_method(:level=) do |level| + logger.level = level + super(level) + end + end end - end - class Logger < ::Logger def initialize(*args) super @formatter = SimpleFormatter.new |