From: Scott Gasch Date: Fri, 8 Apr 2022 13:54:04 +0000 (-0700) Subject: Cause the custom exception handler to also log unhandled exceptions' X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=b69d402dc503a0d38381bfa0fcd6dd5829e92775;p=python_utils.git Cause the custom exception handler to also log unhandled exceptions' tracebacks. --- diff --git a/bootstrap.py b/bootstrap.py index 1174686..a4923b4 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -98,9 +98,15 @@ def handle_uncaught_exception(exc_type, exc_value, exc_tb): ORIGINAL_EXCEPTION_HOOK(exc_type, exc_value, exc_tb) else: # a terminal is attached and stderr is not redirected, maybe debug. + import io import traceback - traceback.print_exception(exc_type, exc_value, exc_tb) + tb_output = io.StringIO() + traceback.print_tb(exc_tb, None, tb_output) + print(tb_output.getvalue(), file=sys.stderr) + logger.error(tb_output.getvalue()) + tb_output.close() + if config.config['debug_unhandled_exceptions']: import pdb