Logging Exception In Python With Stack Trace

January 16, 2018
logging.exception

Use logging.exception

import logging

try:
    1/0
except Exception:
    logging.exception("Test Exception Logging")

If you don’t want to log a message.

try:
    1/0
except Exception as e:
    logging.exception(e)

If you want to log at other level besides ERROR.

try:
    1/0
except Exception as e:
    logging.info(e, exec_info=True)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.