This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author erik.montnemery
Recipients erik.montnemery
Date 2022-02-15.08:36:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644914215.76.0.40425567068.issue46755@roundup.psfhosted.org>
In-reply-to
Content
logging.handlers.QueueHandler logs stack twice when stack_info=True:

>>> import logging
>>> from logging.handlers import QueueHandler, QueueListener
>>> from queue import Queue
>>> q = Queue()
>>> logging.getLogger().addHandler(QueueHandler(q))
>>> listener = QueueListener(q, logging.StreamHandler())
>>> listener.start()
>>> _LOGGER.error("Hello", stack_info=True)
Hello
Stack (most recent call last):
  File "<stdin>", line 1, in <module>
Stack (most recent call last):
  File "<stdin>", line 1, in <module>


Reproduced on CPython 3.9.9, but the code is unchanged in 3.10 and 3.11, so the issue should exist there too.

Patching QueueHandler.prepare() to set stack_info to None seems to fix this:

diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index d42c48de5f..7cd5646d85 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1452,6 +1452,7 @@ def prepare(self, record):
         record.args = None
         record.exc_info = None
         record.exc_text = None
+        record.stack_info = None
         return record

     def emit(self, record):

Related issue: Issue34334, with patch https://github.com/python/cpython/pull/9537
History
Date User Action Args
2022-02-15 08:36:55erik.montnemerysetrecipients: + erik.montnemery
2022-02-15 08:36:55erik.montnemerysetmessageid: <1644914215.76.0.40425567068.issue46755@roundup.psfhosted.org>
2022-02-15 08:36:55erik.montnemerylinkissue46755 messages
2022-02-15 08:36:55erik.montnemerycreate