Skip to content

Commit

Permalink
Merge pull request #923 from benmalef/assert_messages_flush_to_log_file
Browse files Browse the repository at this point in the history
Assert messages to flush to the log file
  • Loading branch information
sarthakpati authored Sep 12, 2024
2 parents 5944c6a + d6d04c4 commit f26dbab
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions GANDLF/utils/gandlf_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from importlib import resources
import tempfile
from GANDLF.utils import get_unique_timestamp
import sys


def _create_tmp_log_file():
Expand All @@ -26,6 +27,13 @@ def _configure_logging_with_logfile(log_file, config_path):
logging.config.dictConfig(config_dict)


def gandlf_excepthook(exctype, value, tb):
if issubclass(exctype, Exception):
logging.exception("Uncaught exception", exc_info=(exctype, value, tb))
else:
sys.__excepthook__(exctype, value, tb)


def logger_setup(log_file=None, config_path="logging_config.yaml") -> None:
"""
It sets up the logger. Reads from logging_config.
Expand All @@ -42,6 +50,7 @@ def logger_setup(log_file=None, config_path="logging_config.yaml") -> None:
log_tmp_file = _create_tmp_log_file()
_create_log_file(log_tmp_file)
_configure_logging_with_logfile(log_tmp_file, config_path)
sys.excepthook = gandlf_excepthook
logging.info(f"The logs are saved in {log_tmp_file}")


Expand Down

0 comments on commit f26dbab

Please sign in to comment.