summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2017-10-19 17:24:55 (GMT)
committerGitHub <noreply@github.com>2017-10-19 17:24:55 (GMT)
commitce9e62544571e7ade7186697d5dd065fb4c5243f (patch)
tree1ba66445412bb1b0fcbbb46d7a19cd5fa2b3de8d /Lib/test
parent05a634b12a8207611ae8e9d051427d615fcacb69 (diff)
downloadcpython-ce9e62544571e7ade7186697d5dd065fb4c5243f.zip
cpython-ce9e62544571e7ade7186697d5dd065fb4c5243f.tar.gz
cpython-ce9e62544571e7ade7186697d5dd065fb4c5243f.tar.bz2
bpo-31457: Don't omit inner ``process()`` calls with nested LogAdapters (#4044)
This used to be the case on Python 2. Commit 212b590e118e3650b596917021ed9612a918180b changed the implementation for Python 3, making the `log()` method of LogAdapter call `logger._log()` directly. This makes nested log adapters not execute their ``process()`` method. This patch fixes the issue. Also, now proxying `name`, too, to make `repr()` work with nested log adapters. New tests added.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_logging.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 583394c..1968b42 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3904,7 +3904,6 @@ class BasicConfigTest(unittest.TestCase):
class LoggerAdapterTest(unittest.TestCase):
-
def setUp(self):
super(LoggerAdapterTest, self).setUp()
old_handler_list = logging._handlerList[:]
@@ -3979,27 +3978,36 @@ class LoggerAdapterTest(unittest.TestCase):
self.assertFalse(self.adapter.hasHandlers())
def test_nested(self):
+ class Adapter(logging.LoggerAdapter):
+ prefix = 'Adapter'
+
+ def process(self, msg, kwargs):
+ return f"{self.prefix} {msg}", kwargs
+
msg = 'Adapters can be nested, yo.'
- adapter_adapter = logging.LoggerAdapter(logger=self.adapter, extra=None)
+ adapter = Adapter(logger=self.logger, extra=None)
+ adapter_adapter = Adapter(logger=adapter, extra=None)
+ adapter_adapter.prefix = 'AdapterAdapter'
+ self.assertEqual(repr(adapter), repr(adapter_adapter))
adapter_adapter.log(logging.CRITICAL, msg, self.recording)
self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertEqual(record.levelno, logging.CRITICAL)
- self.assertEqual(record.msg, msg)
+ self.assertEqual(record.msg, f"Adapter AdapterAdapter {msg}")
self.assertEqual(record.args, (self.recording,))
orig_manager = adapter_adapter.manager
- self.assertIs(self.adapter.manager, orig_manager)
+ self.assertIs(adapter.manager, orig_manager)
self.assertIs(self.logger.manager, orig_manager)
temp_manager = object()
try:
adapter_adapter.manager = temp_manager
self.assertIs(adapter_adapter.manager, temp_manager)
- self.assertIs(self.adapter.manager, temp_manager)
+ self.assertIs(adapter.manager, temp_manager)
self.assertIs(self.logger.manager, temp_manager)
finally:
adapter_adapter.manager = orig_manager
self.assertIs(adapter_adapter.manager, orig_manager)
- self.assertIs(self.adapter.manager, orig_manager)
+ self.assertIs(adapter.manager, orig_manager)
self.assertIs(self.logger.manager, orig_manager)