]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46755: Don't log stack info twice in QueueHandler (GH-31355)
authorErik Montnemery <erik@montnemery.com>
Tue, 5 Jul 2022 14:23:12 +0000 (16:23 +0200)
committerGitHub <noreply@github.com>
Tue, 5 Jul 2022 14:23:12 +0000 (15:23 +0100)
Doc/library/logging.handlers.rst
Lib/logging/handlers.py
Lib/test/test_logging.py
Misc/NEWS.d/next/Library/2022-02-15-12-40-48.bpo-46755.zePJfx.rst [new file with mode: 0644]

index 4bdd5508c67c4ee10c7c00a36afffd71ea3a4d88..1447cabb9a1df00f0672adede3d37fd970e223e1 100644 (file)
@@ -1034,7 +1034,7 @@ possible, while any potentially slow operations (such as sending an email via
       method is enqueued.
 
       The base implementation formats the record to merge the message,
-      arguments, and exception information, if present.  It also removes
+      arguments, exception and stack information, if present.  It also removes
       unpickleable items from the record in-place. Specifically, it overwrites
       the record's :attr:`msg` and :attr:`message` attributes with the merged
       message (obtained by calling the handler's :meth:`format` method), and
index b4c8a3ba9a18964e08c2934686a4c3a2e871029a..1c8226c181632228926ffd75cdb39f4475cc7212 100644 (file)
@@ -1456,7 +1456,7 @@ class QueueHandler(logging.Handler):
         # (if there's exception data), and also returns the formatted
         # message. We can then use this to replace the original
         # msg + args, as these might be unpickleable. We also zap the
-        # exc_info and exc_text attributes, as they are no longer
+        # exc_info, exc_text and stack_info attributes, as they are no longer
         # needed and, if not None, will typically not be pickleable.
         msg = self.format(record)
         # bpo-35726: make copy of record to avoid affecting other handlers in the chain.
@@ -1466,6 +1466,7 @@ class QueueHandler(logging.Handler):
         record.args = None
         record.exc_info = None
         record.exc_text = None
+        record.stack_info = None
         return record
 
     def emit(self, record):
index 0aec0728c0a8a0604301824ae1a02638b615d5fb..a900dabec6774b4ca2ed7f033cb4bf136e9eb387 100644 (file)
@@ -3808,7 +3808,7 @@ class QueueHandlerTest(BaseTest):
     @unittest.skipUnless(hasattr(logging.handlers, 'QueueListener'),
                          'logging.handlers.QueueListener required for this test')
     def test_queue_listener_with_StreamHandler(self):
-        # Test that traceback only appends once (bpo-34334).
+        # Test that traceback and stack-info only appends once (bpo-34334, bpo-46755).
         listener = logging.handlers.QueueListener(self.queue, self.root_hdlr)
         listener.start()
         try:
@@ -3816,8 +3816,10 @@ class QueueHandlerTest(BaseTest):
         except ZeroDivisionError as e:
             exc = e
             self.que_logger.exception(self.next_message(), exc_info=exc)
+        self.que_logger.error(self.next_message(), stack_info=True)
         listener.stop()
         self.assertEqual(self.stream.getvalue().strip().count('Traceback'), 1)
+        self.assertEqual(self.stream.getvalue().strip().count('Stack'), 1)
 
     @unittest.skipUnless(hasattr(logging.handlers, 'QueueListener'),
                          'logging.handlers.QueueListener required for this test')
diff --git a/Misc/NEWS.d/next/Library/2022-02-15-12-40-48.bpo-46755.zePJfx.rst b/Misc/NEWS.d/next/Library/2022-02-15-12-40-48.bpo-46755.zePJfx.rst
new file mode 100644 (file)
index 0000000..399caf7
--- /dev/null
@@ -0,0 +1,2 @@
+In :class:`QueueHandler`, clear ``stack_info`` from :class:`LogRecord` to
+prevent stack trace from being written twice.