[Python-checkins] [3.11] bpo-46755: Don't log stack info twice in QueueHandler (GH-31355) (GH-94564)

vsajip webhook-mailer at python.org
Tue Jul 5 10:49:44 EDT 2022


https://github.com/python/cpython/commit/d49159bd9f1fd7596ca4d77e26c1c2564c624b36
commit: d49159bd9f1fd7596ca4d77e26c1c2564c624b36
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022年07月05日T15:49:05+01:00
summary:
[3.11] bpo-46755: Don't log stack info twice in QueueHandler (GH-31355) (GH-94564)
Co-authored-by: Erik Montnemery <erik at montnemery.com>
files:
A Misc/NEWS.d/next/Library/2022-02-15-12-40-48.bpo-46755.zePJfx.rst
M Doc/library/logging.handlers.rst
M Lib/logging/handlers.py
M Lib/test/test_logging.py
diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst
index f5ef80ea044c6..0cbe707339a7a 100644
--- a/Doc/library/logging.handlers.rst
+++ b/Doc/library/logging.handlers.rst
@@ -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
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 78e919d195d97..78b756019dc83 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1455,7 +1455,7 @@ def prepare(self, record):
 # (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.
@@ -1465,6 +1465,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):
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 9eda0706ac6fd..71926a5432e26 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3665,7 +3665,7 @@ def test_queue_listener(self):
 @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:
@@ -3673,8 +3673,10 @@ def test_queue_listener_with_StreamHandler(self):
 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
index 0000000000000..399caf7253593
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-15-12-40-48.bpo-46755.zePJfx.rst
@@ -0,0 +1,2 @@
+In :class:`QueueHandler`, clear ``stack_info`` from :class:`LogRecord` to
+prevent stack trace from being written twice.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /