Permalink
Browse files

made the broadcast logger quack more like a logger

  • Loading branch information...
1 parent 04241f3 commit e7e1890c49ce645986959aac5ab39607bb22fd53 @tenderlove tenderlove committed Jan 20, 2012
Showing with 59 additions and 15 deletions.
  1. +24 −0 activesupport/lib/active_support/logger.rb
  2. +35 −15 activesupport/test/broadcast_logger_test.rb
View
24 activesupport/lib/active_support/logger.rb
@@ -10,6 +10,30 @@ def initialize(logs)
@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) }
View
50 activesupport/test/broadcast_logger_test.rb
@@ -2,43 +2,63 @@
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

0 comments on commit e7e1890

Please sign in to comment.