From 18135c6e6c8e89176a594e456b1abb7df61a06e0 Mon Sep 17 00:00:00 2001 From: Veniamin Malefioudakis Date: Mon, 19 Aug 2024 12:26:40 +0300 Subject: [PATCH 1/5] update gandlf_logging with excepthook function --- GANDLF/utils/gandlf_logging.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/GANDLF/utils/gandlf_logging.py b/GANDLF/utils/gandlf_logging.py index 9c376aaf0..f2d431f38 100644 --- a/GANDLF/utils/gandlf_logging.py +++ b/GANDLF/utils/gandlf_logging.py @@ -4,7 +4,8 @@ from importlib import resources import tempfile from GANDLF.utils import get_unique_timestamp - +import sys +import traceback def _create_tmp_log_file(): tmp_dir = Path(tempfile.gettempdir()) @@ -25,6 +26,14 @@ def _configure_logging_with_logfile(log_file, config_path): config_dict["handlers"]["rotatingFileHandler"]["filename"] = str(log_file) logging.config.dictConfig(config_dict) +def gandlf_excepthook(exctype, value, tb): + if issubclass(exctype, AssertionError): + logging.exception( + f"{exctype.__name__}: {value}\n{''.join(traceback.format_exception(exctype, value, tb))}", + exc_info=False, + ) + else: + sys.__excepthook__(exctype, value, tb) def logger_setup(log_file=None, config_path="logging_config.yaml") -> None: """ @@ -43,7 +52,7 @@ def logger_setup(log_file=None, config_path="logging_config.yaml") -> None: logging.info(f"The logs are saved in {log_tmp_file}") _create_log_file(log_tmp_file) _configure_logging_with_logfile(log_tmp_file, config_path) - + sys.excepthook = gandlf_excepthook class InfoOnlyFilter(logging.Filter): """ From 421a9441cd5f1bd38a26e963d3db469263fd7169 Mon Sep 17 00:00:00 2001 From: Veniamin Malefioudakis Date: Mon, 19 Aug 2024 12:36:18 +0300 Subject: [PATCH 2/5] blacked --- GANDLF/utils/gandlf_logging.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GANDLF/utils/gandlf_logging.py b/GANDLF/utils/gandlf_logging.py index f2d431f38..fee523475 100644 --- a/GANDLF/utils/gandlf_logging.py +++ b/GANDLF/utils/gandlf_logging.py @@ -7,6 +7,7 @@ import sys import traceback + def _create_tmp_log_file(): tmp_dir = Path(tempfile.gettempdir()) log_dir = Path.joinpath(tmp_dir, ".gandlf") @@ -26,6 +27,7 @@ def _configure_logging_with_logfile(log_file, config_path): config_dict["handlers"]["rotatingFileHandler"]["filename"] = str(log_file) logging.config.dictConfig(config_dict) + def gandlf_excepthook(exctype, value, tb): if issubclass(exctype, AssertionError): logging.exception( @@ -35,6 +37,7 @@ def gandlf_excepthook(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. @@ -54,6 +57,7 @@ def logger_setup(log_file=None, config_path="logging_config.yaml") -> None: _configure_logging_with_logfile(log_tmp_file, config_path) sys.excepthook = gandlf_excepthook + class InfoOnlyFilter(logging.Filter): """ Display only INFO messages. From a92ff5aa9f72cfc6ab0805351fce6d1a630b2116 Mon Sep 17 00:00:00 2001 From: Sarthak Pati Date: Thu, 12 Sep 2024 12:22:47 -0400 Subject: [PATCH 3/5] Update GANDLF/utils/gandlf_logging.py Co-authored-by: Viacheslav Kukushkin --- GANDLF/utils/gandlf_logging.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/GANDLF/utils/gandlf_logging.py b/GANDLF/utils/gandlf_logging.py index 144091c31..0d88593e6 100644 --- a/GANDLF/utils/gandlf_logging.py +++ b/GANDLF/utils/gandlf_logging.py @@ -30,10 +30,7 @@ def _configure_logging_with_logfile(log_file, config_path): def gandlf_excepthook(exctype, value, tb): if issubclass(exctype, AssertionError): - logging.exception( - f"{exctype.__name__}: {value}\n{''.join(traceback.format_exception(exctype, value, tb))}", - exc_info=False, - ) + logging.exception("Uncaught exception", exc_info=(exctype, value, tb)) else: sys.__excepthook__(exctype, value, tb) From 662ce8dd8597eb9a163a604a8873d2cf20d56990 Mon Sep 17 00:00:00 2001 From: Sarthak Pati Date: Thu, 12 Sep 2024 12:43:40 -0400 Subject: [PATCH 4/5] Update GANDLF/utils/gandlf_logging.py --- GANDLF/utils/gandlf_logging.py | 1 - 1 file changed, 1 deletion(-) diff --git a/GANDLF/utils/gandlf_logging.py b/GANDLF/utils/gandlf_logging.py index 0d88593e6..a679b464d 100644 --- a/GANDLF/utils/gandlf_logging.py +++ b/GANDLF/utils/gandlf_logging.py @@ -5,7 +5,6 @@ import tempfile from GANDLF.utils import get_unique_timestamp import sys -import traceback def _create_tmp_log_file(): From d6d04c429234842fceda90e89fa7115f15f0dc35 Mon Sep 17 00:00:00 2001 From: benmalef Date: Thu, 12 Sep 2024 19:56:08 +0300 Subject: [PATCH 5/5] change the AssertionError -> Exception --- GANDLF/utils/gandlf_logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GANDLF/utils/gandlf_logging.py b/GANDLF/utils/gandlf_logging.py index a679b464d..576df868e 100644 --- a/GANDLF/utils/gandlf_logging.py +++ b/GANDLF/utils/gandlf_logging.py @@ -28,7 +28,7 @@ def _configure_logging_with_logfile(log_file, config_path): def gandlf_excepthook(exctype, value, tb): - if issubclass(exctype, AssertionError): + if issubclass(exctype, Exception): logging.exception("Uncaught exception", exc_info=(exctype, value, tb)) else: sys.__excepthook__(exctype, value, tb)