Vinay Sajip avatar Vinay Sajip committed 3f2bd19

Fixed bug in Filter handling and added unit test.

Comments (0)

Files changed (2)

src/dictconfig.py

         if formatter:
             formatter = self.config['formatters'][formatter]
         level = config.pop('level', None)
+        filters = config.pop('filters', None)
         klass = self.resolve(config.pop('class'))
         #Special case for handler which refers to another handler
         if issubclass(klass, logging.handlers.MemoryHandler) and\
             result.setFormatter(formatter)
         if level is not None:
             result.setLevel(_checkLevel(level))
-        filters = config.get('filters', None)
         if filters:
             self.add_filters(result, filters)
         return result

src/test_dictconfig.py

         },
     } 
 
+    #As config1 but with a filter added
+    config10 = {
+        'formatters': {
+            'form1' : {
+                'format' : '%(levelname)s ++ %(message)s',
+            },
+        },
+        'filters' : {
+            'filt1' : {
+                'name' : 'compiler.parser',
+            },
+        },
+        'handlers' : {
+            'hand1' : {
+                'class' : 'logging.StreamHandler',
+                'formatter' : 'form1',
+                'level' : 'NOTSET',
+                'stream'  : 'ext://sys.stdout',
+                'filters' : ['filt1'],
+            },
+        },
+        'loggers' : {
+            'compiler.parser' : {
+                'level' : 'DEBUG',
+                'filters' : ['filt1'],
+            },
+        },
+        'root' : {
+            'level' : 'WARNING',
+            'handlers' : ['hand1'],
+        },
+    } 
+
     def apply_config(self, conf):
         dictConfig(conf)
 
                 ('INFO', '3'),
             ], stream=output)
 
+    def test_config_10_ok(self):
+        with captured_stdout() as output:
+            self.apply_config(self.config10)
+            logger = logging.getLogger("compiler.parser")
+            logger.warning(self.next_message())
+            logger = logging.getLogger('compiler')
+            #Not output, because filtered
+            logger.warning(self.next_message())
+            logger = logging.getLogger('compiler.lexer')
+            #Not output, because filtered
+            logger.warning(self.next_message())
+            logger = logging.getLogger("compiler.parser.codegen")
+            #Output, as not filtered
+            logger.error(self.next_message())
+            self.assert_log_lines([
+                ('WARNING', '1'),
+                ('ERROR', '4'),
+            ], stream=output)
+        
 def test_main():
     run_unittest(ConfigDictTest)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.