Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/logging.handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Lib/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3665,16 +3665,18 @@ 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:
1 / 0
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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :class:`QueueHandler`, clear ``stack_info`` from :class:`LogRecord` to
prevent stack trace from being written twice.