Skip to content

Instantly share code, notes, and snippets.

@isaac-ped
Last active August 19, 2021 19:16
Show Gist options
  • Save isaac-ped/d2399f62c2c2da757891469d693c344b to your computer and use it in GitHub Desktop.
Save isaac-ped/d2399f62c2c2da757891469d693c344b to your computer and use it in GitHub Desktop.
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