]> granicus.if.org Git - python/commitdiff
Closes #17508: Merged fix from 3.3.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 22 Mar 2013 15:27:52 +0000 (15:27 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 22 Mar 2013 15:27:52 +0000 (15:27 +0000)
1  2 
Lib/logging/config.py
Lib/test/test_logging.py

Simple merge
index 0981704b0a37bf31c0661244357c2fb56b32a880,69da27a94585ab2cffb7610ba340c0b63eb47759..f2ae09568bbd5bdff17f31ecc2e061c0681143e7
@@@ -2389,32 -2364,36 +2389,62 @@@ class ConfigDictTest(BaseTest)
          },
      }
  
 +    # As config0, but with properties
 +    config14 = {
 +        'version': 1,
 +        'formatters': {
 +            'form1' : {
 +                'format' : '%(levelname)s ++ %(message)s',
 +            },
 +        },
 +        'handlers' : {
 +            'hand1' : {
 +                'class' : 'logging.StreamHandler',
 +                'formatter' : 'form1',
 +                'level' : 'NOTSET',
 +                'stream'  : 'ext://sys.stdout',
 +                '.': {
 +                    'foo': 'bar',
 +                    'terminator': '!\n',
 +                }
 +            },
 +        },
 +        'root' : {
 +            'level' : 'WARNING',
 +            'handlers' : ['hand1'],
 +        },
 +    }
 +
+     out_of_order = {
+         "version": 1,
+         "formatters": {
+             "mySimpleFormatter": {
+                 "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s"
+             }
+         },
+         "handlers": {
+             "fileGlobal": {
+                 "class": "logging.StreamHandler",
+                 "level": "DEBUG",
+                 "formatter": "mySimpleFormatter"
+             },
+             "bufferGlobal": {
+                 "class": "logging.handlers.MemoryHandler",
+                 "capacity": 5,
+                 "formatter": "mySimpleFormatter",
+                 "target": "fileGlobal",
+                 "level": "DEBUG"
+                 }
+         },
+         "loggers": {
+             "mymodule": {
+                 "level": "DEBUG",
+                 "handlers": ["bufferGlobal"],
+                 "propagate": "true"
+             }
+         }
+     }
      def apply_config(self, conf):
          logging.config.dictConfig(conf)
  
              # Original logger output is empty.
              self.assert_log_lines([])
  
 +    @unittest.skipUnless(threading, 'Threading required for this test.')
 +    def test_listen_verify(self):
 +
 +        def verify_fail(stuff):
 +            return None
 +
 +        def verify_reverse(stuff):
 +            return stuff[::-1]
 +
 +        logger = logging.getLogger("compiler.parser")
 +        to_send = textwrap.dedent(ConfigFileTest.config1)
 +        # First, specify a verification function that will fail.
 +        # We expect to see no output, since our configuration
 +        # never took effect.
 +        with captured_stdout() as output:
 +            self.setup_via_listener(to_send, verify_fail)
 +            # Both will output a message
 +            logger.info(self.next_message())
 +            logger.error(self.next_message())
 +        self.assert_log_lines([], stream=output)
 +        # Original logger output has the stuff we logged.
 +        self.assert_log_lines([
 +            ('INFO', '1'),
 +            ('ERROR', '2'),
 +        ], pat=r"^[\w.]+ -> (\w+): (\d+)$")
 +
 +        # Now, perform no verification. Our configuration
 +        # should take effect.
 +
 +        with captured_stdout() as output:
 +            self.setup_via_listener(to_send)    # no verify callable specified
 +            logger = logging.getLogger("compiler.parser")
 +            # Both will output a message
 +            logger.info(self.next_message())
 +            logger.error(self.next_message())
 +        self.assert_log_lines([
 +            ('INFO', '3'),
 +            ('ERROR', '4'),
 +        ], stream=output)
 +        # Original logger output still has the stuff we logged before.
 +        self.assert_log_lines([
 +            ('INFO', '1'),
 +            ('ERROR', '2'),
 +        ], pat=r"^[\w.]+ -> (\w+): (\d+)$")
 +
 +        # Now, perform verification which transforms the bytes.
 +
 +        with captured_stdout() as output:
 +            self.setup_via_listener(to_send[::-1], verify_reverse)
 +            logger = logging.getLogger("compiler.parser")
 +            # Both will output a message
 +            logger.info(self.next_message())
 +            logger.error(self.next_message())
 +        self.assert_log_lines([
 +            ('INFO', '5'),
 +            ('ERROR', '6'),
 +        ], stream=output)
 +        # Original logger output still has the stuff we logged before.
 +        self.assert_log_lines([
 +            ('INFO', '1'),
 +            ('ERROR', '2'),
 +        ], pat=r"^[\w.]+ -> (\w+): (\d+)$")
 +
+     def test_out_of_order(self):
+         self.apply_config(self.out_of_order)
+         handler = logging.getLogger('mymodule').handlers[0]
+         self.assertIsInstance(handler.target, logging.Handler)
      def test_baseconfig(self):
          d = {
              'atuple': (1, 2, 3),