diff options
-rw-r--r-- | activesupport/lib/active_support/logger.rb | 24 | ||||
-rw-r--r-- | activesupport/test/broadcast_logger_test.rb | 50 |
2 files changed, 59 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index 8288368d8d..3a2646d55f 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -10,6 +10,30 @@ module ActiveSupport @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) } diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb index af34221cfe..aa792eb0c8 100644 --- a/activesupport/test/broadcast_logger_test.rb +++ b/activesupport/test/broadcast_logger_test.rb @@ -2,43 +2,63 @@ require 'abstract_unit' module ActiveSupport class BroadcastLoggerTest < TestCase - def test_debug - log1 = FakeLogger.new - log2 = FakeLogger.new + attr_reader :logger, :log1, :log2 + def setup + @log1 = FakeLogger.new + @log2 = FakeLogger.new + @logger = BroadcastLogger.new [log1, log2] + end - logger = BroadcastLogger.new [log1, log2] + def test_debug logger.debug "foo" assert_equal 'foo', log1.adds.first[2] assert_equal 'foo', log2.adds.first[2] end def test_close - log1 = FakeLogger.new - log2 = FakeLogger.new - - logger = BroadcastLogger.new [log1, log2] logger.close assert log1.closed, 'should be closed' assert log2.closed, 'should be closed' end def test_chevrons - log1 = FakeLogger.new - log2 = FakeLogger.new - - logger = BroadcastLogger.new [log1, log2] logger << "foo" assert_equal %w{ foo }, log1.chevrons assert_equal %w{ foo }, log2.chevrons end + def test_level + assert_nil logger.level + logger.level = 10 + assert_equal 10, log1.level + assert_equal 10, log2.level + end + + def test_progname + assert_nil logger.progname + logger.progname = 10 + assert_equal 10, log1.progname + assert_equal 10, log2.progname + end + + def test_formatter + assert_nil logger.formatter + logger.formatter = 10 + assert_equal 10, log1.formatter + assert_equal 10, log2.formatter + end + class FakeLogger attr_reader :adds, :closed, :chevrons + attr_accessor :level, :progname, :formatter def initialize - @adds = [] - @closed = false - @chevrons = [] + @adds = [] + @closed = false + @chevrons = [] + @level = nil + @progname = nil + @formatter = nil end def << x |