Skip to content

Commit

Permalink
logging fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoran Jankovic committed May 19, 2024
1 parent 99c4765 commit 69e96f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions gadapt/adapters/ga_logging/logging_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="gadapt",
version="0.4.6",
version="0.4.7",
author="Zoran Jankovic",
author_email="[email protected]",
url="https://github.com/bpzoran/gadapt",
Expand Down

0 comments on commit 69e96f6

Please sign in to comment.