[Python-checkins] bpo-46557: Log captured warnings without format string (GH-30975)
vsajip
webhook-mailer at python.org
Tue Mar 15 05:01:07 EDT 2022
https://github.com/python/cpython/commit/d8066b420b888591f485d132e62979d07abfc3f4
commit: d8066b420b888591f485d132e62979d07abfc3f4
branch: main
author: Michael P. Nitowski <mpnitowski at gmail.com>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-03-15T09:01:03Z
summary:
bpo-46557: Log captured warnings without format string (GH-30975)
files:
A Misc/NEWS.d/next/Library/2022-01-28-01-23-25.bpo-46557.XSbhyQ.rst
M Lib/logging/__init__.py
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index e49e0d02a80cf..160b1afcee0f9 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -2246,7 +2246,9 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
logger = getLogger("py.warnings")
if not logger.handlers:
logger.addHandler(NullHandler())
- logger.warning("%s", s)
+ # bpo-46557: Log str(s) as msg instead of logger.warning("%s", s)
+ # since some log aggregation tools group logs by the msg arg
+ logger.warning(str(s))
def captureWarnings(capture):
"""
diff --git a/Misc/NEWS.d/next/Library/2022-01-28-01-23-25.bpo-46557.XSbhyQ.rst b/Misc/NEWS.d/next/Library/2022-01-28-01-23-25.bpo-46557.XSbhyQ.rst
new file mode 100644
index 0000000000000..dd7d3f3d6c51f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-01-28-01-23-25.bpo-46557.XSbhyQ.rst
@@ -0,0 +1 @@
+Warnings captured by the logging module are now logged without a format string to prevent systems that group logs by the msg argument from grouping captured warnings together.
More information about the Python-checkins
mailing list