From a22588c93f76746a2e7a973c6ade30349170353f Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Fri, 30 Aug 2013 14:04:41 +0200 Subject: Fixed issue with builtin filtering. The superclass (which ultimately inherits from 'Handler') checks against any registered filters, before allowing a logging record. Nose's logging capture plugin should do the same, because these filters are allowed to modify the record. And it can easily happen that the logging format requires this modification (e.g. add an attribute). --- unit_tests/test_logcapture_plugin.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'unit_tests') diff --git a/unit_tests/test_logcapture_plugin.py b/unit_tests/test_logcapture_plugin.py index 63d1f8b..63aa651 100644 --- a/unit_tests/test_logcapture_plugin.py +++ b/unit_tests/test_logcapture_plugin.py @@ -155,6 +155,26 @@ class TestLogCapturePlugin(object): eq_(1, len(records)) eq_("++Hello++", records[0]) + def test_builtin_logging_filtering(self): + c = LogCapture() + c.logformat = '++%(message)s++' + c.start() + log = logging.getLogger("foobar.something") + filtered = [] + class filter(object): + def filter(record): + filtered.append(record) + return len(filtered) == 1 + filter = staticmethod(filter) + c.handler.addFilter(filter) + log.debug("Hello") + log.debug("World") + c.end() + eq_(2, len(filtered)) + records = c.formatLogRecords() + eq_(1, len(records)) + eq_("++Hello++", records[0]) + def test_logging_filter(self): env = {'NOSE_LOGFILTER': 'foo,bar'} c = LogCapture() -- cgit v1.2.1