From 29c871367ebf764e19c634422108821fe403a716 Mon Sep 17 00:00:00 2001 From: Lorenzo Volpi Date: Sun, 5 Nov 2023 20:19:22 +0100 Subject: [PATCH] logger updated --- quacc/logger.py | 17 +++++++++++++++++ quacc/main.py | 2 ++ 2 files changed, 19 insertions(+) diff --git a/quacc/logger.py b/quacc/logger.py index c3b72b1..794a73d 100644 --- a/quacc/logger.py +++ b/quacc/logger.py @@ -2,6 +2,7 @@ import logging import logging.handlers import multiprocessing import threading +from pathlib import Path class Logger: @@ -11,6 +12,7 @@ class Logger: __queue = None __thread = None __setup = False + __handlers = [] @classmethod def __logger_listener(cls, q): @@ -62,6 +64,21 @@ class Logger: cls.__setup = True + @classmethod + def add_handler(cls, path: Path): + root = logging.getLogger("listener") + rh = logging.FileHandler(path, mode="a") + rh.setLevel(logging.DEBUG) + cls.__handlers.append(rh) + root.addHandler(rh) + + @classmethod + def clear_handlers(cls): + root = logging.getLogger("listener") + for h in cls.__handlers: + root.removeHandler(h) + cls.__handlers.clear() + @classmethod def queue(cls): if not cls.__setup: diff --git a/quacc/main.py b/quacc/main.py index 1fe0279..eaf4067 100644 --- a/quacc/main.py +++ b/quacc/main.py @@ -27,6 +27,7 @@ def estimate_comparison(): prevs=env.DATASET_PREVS, ) create_dataser_dir(dataset.name, update=env.DATASET_DIR_UPDATE) + Logger.add_handler(env.OUT_DIR / f"{dataset.name}.log") try: dr = comp.evaluate_comparison( dataset, @@ -52,6 +53,7 @@ def estimate_comparison(): f"Failed while saving configuration {plot_conf} of {dataset.name}. Exception: {e}" ) traceback(e) + Logger.clear_handlers() # print(df.to_latex(float_format="{:.4f}".format)) # print(utils.avg_group_report(df).to_latex(float_format="{:.4f}".format))