Skip to content

Instantly share code, notes, and snippets.

@Menziess
Created June 15, 2024 15:20
Show Gist options
  • Save Menziess/4636b3ea00dceb1c25717366f5bf5e8c to your computer and use it in GitHub Desktop.
Save Menziess/4636b3ea00dceb1c25717366f5bf5e8c to your computer and use it in GitHub Desktop.
import sys
import logging
logger = logging.getLogger(__file__)
def handle_exception(exc_type, exc_value, exc_traceback):
"""Can be assigned to sys.excepthook to log uncaught exceptions."""
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.critical('Uncaught exception', exc_info=(
exc_type,
exc_value,
exc_traceback
))
sys.excepthook = handle_exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment