summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/logging/__init__.py6
-rw-r--r--Lib/test/test_logging.py20
-rw-r--r--Misc/NEWS.d/next/Library/2017-10-18-19-05-17.bpo-31457.KlE6r8.rst2
3 files changed, 21 insertions, 7 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 7544190..9f2c0f0 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1713,7 +1713,7 @@ class LoggerAdapter(object):
"""
if self.isEnabledFor(level):
msg, kwargs = self.process(msg, kwargs)
- self.logger._log(level, msg, args, **kwargs)
+ self.logger.log(level, msg, *args, **kwargs)
def isEnabledFor(self, level):
"""
@@ -1760,6 +1760,10 @@ class LoggerAdapter(object):
def manager(self, value):
self.logger.manager = value
+ @property
+ def name(self):
+ return self.logger.name
+
def __repr__(self):
logger = self.logger
level = getLevelName(logger.getEffectiveLevel())
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)
diff --git a/Misc/NEWS.d/next/Library/2017-10-18-19-05-17.bpo-31457.KlE6r8.rst b/Misc/NEWS.d/next/Library/2017-10-18-19-05-17.bpo-31457.KlE6r8.rst
new file mode 100644
index 0000000..49463c4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-18-19-05-17.bpo-31457.KlE6r8.rst
@@ -0,0 +1,2 @@
+If nested log adapters are used, the inner ``process()`` methods are no
+longer omitted.