Created
June 15, 2024 15:20
-
-
Save Menziess/4636b3ea00dceb1c25717366f5bf5e8c to your computer and use it in GitHub Desktop.
This file contains 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
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