Skip to content

Commit 8e3ad2e

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Align logging.exception signature with that or Python's builtin by adding exc_info.
PiperOrigin-RevId: 559680080
1 parent 9764133 commit 8e3ad2e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com).
2626
`enum_values` is provided as a single string value. Additionally,
2727
`EnumParser.enum_values` is now stored as a list copy of the provided
2828
`enum_values` parameter.
29-
* (tesing) Updated `paramaterized.CoopTestCase()` to use Python 3 metaclass
29+
* (testing) Updated `paramaterized.CoopTestCase()` to use Python 3 metaclass
3030
idioms. Most uses of this function continued working during the Python 3
3131
migration still worked because a Python 2 compatibility `__metaclass__`
3232
variables also existed. Now pure Python 3 base classes without backwards
3333
compatibility will work as intended.
34+
* `logging.exception` can now take `exc_info` as argument, with default value
35+
`True`. Prior to this change setting `exc_info` would raise `KeyError`, this
36+
change fixes this behaviour.
3437

3538
## 1.4.0 (2023-01-11)
3639

absl/logging/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ def debug(msg, *args, **kwargs):
447447
log(DEBUG, msg, *args, **kwargs)
448448

449449

450-
def exception(msg, *args, **kwargs):
450+
def exception(msg, *args, exc_info=True, **kwargs):
451451
"""Logs an exception, with traceback and message."""
452-
error(msg, *args, **kwargs, exc_info=True)
452+
error(msg, *args, exc_info=exc_info, **kwargs)
453453

454454

455455
# Counter to keep track of number of log entries per token.

absl/logging/tests/logging_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,11 @@ def test_exception_dict_format(self):
819819
# Just verify that this doesn't raise a TypeError.
820820
logging.exception('%(test)s', {'test': 'Hello world!'})
821821

822+
def test_exception_with_exc_info(self):
823+
# Just verify that this doesn't raise a KeyeError.
824+
logging.exception('exc_info=True', exc_info=True)
825+
logging.exception('exc_info=False', exc_info=False)
826+
822827
def test_logging_levels(self):
823828
old_level = logging.get_verbosity()
824829

0 commit comments

Comments
 (0)