2 ms·
> Use the almost undocumented `exc_info=True` Why not simply use logger.exception()? try: do_thing() except Exception: logger.exception("It br
by teddyh 7y ago
> Use the almost undocumented `exc_info=True`
Why not simply use logger.exception()?
try:
do_thing()
except Exception:
logger.exception("It broke.")
Called from within an exception handler, logger.exception() automatically includes exception information.
- olsgaarddk 7y agoMostly because I didn't know of it. But also if you want to log caught exceptions as debug, because you were expecting the exception. E.g., a StopIteration exception you for some reason might want information about, or you have an object you need to check if it has a certain key, but for some reason doesn't have a get-method. I'm sure there are also good reasons :)