Skip to content
This repository
Browse code

made the broadcast logger quack more like a logger

  • Loading branch information...
commit e7e1890c49ce645986959aac5ab39607bb22fd53 1 parent 04241f3
Aaron Patterson authored January 20, 2012
24  activesupport/lib/active_support/logger.rb
@@ -10,6 +10,30 @@ def initialize(logs)
10 10
       @logs = logs
11 11
     end
12 12
 
  13
+    def progname
  14
+      logs.first.progname
  15
+    end
  16
+
  17
+    def progname=(name)
  18
+      logs.each { |x| x.progname = name }
  19
+    end
  20
+
  21
+    def formatter
  22
+      logs.first.formatter
  23
+    end
  24
+
  25
+    def formatter=(formatter)
  26
+      logs.each { |x| x.formatter = formatter }
  27
+    end
  28
+
  29
+    def level
  30
+      logs.first.level
  31
+    end
  32
+
  33
+    def level=(level)
  34
+      logs.each { |x| x.level = level }
  35
+    end
  36
+
13 37
     def add(severity, message = nil, progname = nil, &block)
14 38
       super
15 39
       logs.each { |l| l.add(severity, message, progname, &block) }
50  activesupport/test/broadcast_logger_test.rb
@@ -2,43 +2,63 @@
2 2
 
3 3
 module ActiveSupport
4 4
   class BroadcastLoggerTest < TestCase
5  
-    def test_debug
6  
-      log1 = FakeLogger.new
7  
-      log2 = FakeLogger.new
  5
+    attr_reader :logger, :log1, :log2
  6
+    def setup
  7
+      @log1 = FakeLogger.new
  8
+      @log2 = FakeLogger.new
  9
+      @logger = BroadcastLogger.new [log1, log2]
  10
+    end
8 11
 
9  
-      logger = BroadcastLogger.new [log1, log2]
  12
+    def test_debug
10 13
       logger.debug "foo"
11 14
       assert_equal 'foo', log1.adds.first[2]
12 15
       assert_equal 'foo', log2.adds.first[2]
13 16
     end
14 17
 
15 18
     def test_close
16  
-      log1 = FakeLogger.new
17  
-      log2 = FakeLogger.new
18  
-
19  
-      logger = BroadcastLogger.new [log1, log2]
20 19
       logger.close
21 20
       assert log1.closed, 'should be closed'
22 21
       assert log2.closed, 'should be closed'
23 22
     end
24 23
 
25 24
     def test_chevrons
26  
-      log1 = FakeLogger.new
27  
-      log2 = FakeLogger.new
28  
-
29  
-      logger = BroadcastLogger.new [log1, log2]
30 25
       logger << "foo"
31 26
       assert_equal %w{ foo }, log1.chevrons
32 27
       assert_equal %w{ foo }, log2.chevrons
33 28
     end
34 29
 
  30
+    def test_level
  31
+      assert_nil logger.level
  32
+      logger.level = 10
  33
+      assert_equal 10, log1.level
  34
+      assert_equal 10, log2.level
  35
+    end
  36
+
  37
+    def test_progname
  38
+      assert_nil logger.progname
  39
+      logger.progname = 10
  40
+      assert_equal 10, log1.progname
  41
+      assert_equal 10, log2.progname
  42
+    end
  43
+
  44
+    def test_formatter
  45
+      assert_nil logger.formatter
  46
+      logger.formatter = 10
  47
+      assert_equal 10, log1.formatter
  48
+      assert_equal 10, log2.formatter
  49
+    end
  50
+
35 51
     class FakeLogger
36 52
       attr_reader :adds, :closed, :chevrons
  53
+      attr_accessor :level, :progname, :formatter
37 54
 
38 55
       def initialize
39  
-        @adds     = []
40  
-        @closed   = false
41  
-        @chevrons = []
  56
+        @adds      = []
  57
+        @closed    = false
  58
+        @chevrons  = []
  59
+        @level     = nil
  60
+        @progname  = nil
  61
+        @formatter = nil
42 62
       end
43 63
 
44 64
       def << x

0 notes on commit e7e1890

Please sign in to comment.
Something went wrong with that request. Please try again.