Skip to content

Commit

Permalink
Log uncaught exceptions into debug.log
Browse files Browse the repository at this point in the history
  • Loading branch information
Y0ndaime committed Apr 12, 2022
1 parent c78d027 commit c2ad114
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,21 @@ def process_files_aimlab():
update_aimlab(config, scenarios, cs_level_ids, blacklist)


def handle_exception(exc_type, exc_value, exc_traceback):
"""
Function that replaces sys.excepthook to also log uncaught exceptions, see:
https://stackoverflow.com/questions/6234405/logging-uncaught-exceptions-in-python/16993115#16993115
"""
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return

logging.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))


if __name__ == "__main__":
logging.config.fileConfig('logging.conf')
sys.excepthook = handle_exception

config_file = 'config.json'
if not os.path.isfile(config_file):
Expand Down

0 comments on commit c2ad114

Please sign in to comment.