From 69e96f697dd6a6bf85db17a522dc617e372d63b0 Mon Sep 17 00:00:00 2001 From: Zoran Jankovic Date: Sun, 19 May 2024 21:31:38 +0200 Subject: [PATCH] logging fix --- .../adapters/ga_logging/logging_settings.py | 20 ++++++++++++------- setup.py | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gadapt/adapters/ga_logging/logging_settings.py b/gadapt/adapters/ga_logging/logging_settings.py index 853b9bd..3961241 100644 --- a/gadapt/adapters/ga_logging/logging_settings.py +++ b/gadapt/adapters/ga_logging/logging_settings.py @@ -23,6 +23,12 @@ def get_last_num(s: str) -> int: except Exception: return -1 + logger = logging.getLogger("gadapt_logger") + if not is_logging: + logger.disabled = True + else: + logger.disabled = False + return path = os.path.join(os.getcwd(), "log") if not os.path.exists(path): os.mkdir(path) @@ -36,7 +42,6 @@ def get_last_num(s: str) -> int: os.path.join(path, f), os.path.join(path, "gadapt_log.log.1") ) except Exception: - print("Unable to rename log file: " + os.path.join(path, f)) break elif f.startswith("gadapt_log.log."): n_last_number = get_last_num(f) @@ -51,7 +56,7 @@ def get_last_num(s: str) -> int: except Exception: break logpath = os.path.join(path, "gadapt_log.log") - logger = logging.getLogger("gadapt_logger") + handler = logging.FileHandler(logpath) handler.setFormatter( TimestampFormatter("%(asctime)s - %(levelname)s - %(message)s") @@ -60,12 +65,13 @@ def get_last_num(s: str) -> int: logger.removeHandler(h) logger.addHandler(handler) logger.setLevel(logging.INFO) - if not is_logging: - logger.disabled = True - else: - logger.disabled = False def gadapt_log_info(msg: str): logger = logging.getLogger("gadapt_logger") - logger.info(msg) + if logger.disabled: + return + try: + logger.info(msg) + except Exception: + pass diff --git a/setup.py b/setup.py index 98cac3f..27059ac 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="gadapt", - version="0.4.6", + version="0.4.7", author="Zoran Jankovic", author_email="bpzoran@yahoo.com", url="https://github.com/bpzoran/gadapt",