diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 549a6b3c457b2c6..2924ecdfbe204fd 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1680,6 +1680,8 @@ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, exc_info = (type(exc_info), exc_info, exc_info.__traceback__) elif not isinstance(exc_info, tuple): exc_info = sys.exc_info() + else: + exc_info = None record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo) self.handle(record) diff --git a/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst new file mode 100644 index 000000000000000..9bdf648f42783f2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst @@ -0,0 +1,5 @@ +The log functions in the :mod:`logging` module and the +:class:`logging.Logger` class now normalize falsy ``exc_info`` arguments to +``None`` before passing them to :meth:`logging.Logger.makeRecord` and +subsequently to :class:`logging.LogRecord`. This aligns +``logging.LogRecord.exc_info`` with the documentation.