Skip to content

Commit

Permalink
log Exception information
Browse files Browse the repository at this point in the history
  • Loading branch information
xiuqhou committed Aug 1, 2024
1 parent d24ab49 commit 608f210
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions util/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def filter(self, record):
return True


def handle_exception(exc_type, exc_value, exc_traceback):
# Catch exception in logger
logger = logging.getLogger(os.path.basename(os.getcwd()) + "." + __name__)
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))


sys.excepthook = handle_exception


@functools.lru_cache() # so that calling setup_logger multiple times won't add many handlers
def setup_logger(
output=None,
Expand Down

0 comments on commit 608f210

Please sign in to comment.