Last active
August 19, 2021 19:16
-
-
Save isaac-ped/d2399f62c2c2da757891469d693c344b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log_exception(msg: str, e: Exception) -> None: | |
"""Log detailed exception info. | |
Only the exception stack logs to logging.critical | |
Local variales are also appended to logging.debug | |
:param msg: A message to prefix the exception output | |
:param e: An exception object to inspect for local variables | |
""" | |
logging.critical(msg, exc_info=sys.exc_info()) | |
detailed_info = traceback.TracebackException.from_exception( | |
e, capture_locals=True | |
) | |
detailed_msg = list(detailed_info.format()) | |
logging.debug("\n".join(detailed_msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment