From 05c2f47de838f543683025354f01efad5486c4f1 Mon Sep 17 00:00:00 2001 From: Aart Stuurman Date: Mon, 11 Sep 2023 12:20:01 +0200 Subject: [PATCH] Cleanup standard logging and fix bug where level was not applied (#265) Co-authored-by: Aart Stuurman --- .../revolve2/standard_resources/logging.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/standard_resources/revolve2/standard_resources/logging.py b/standard_resources/revolve2/standard_resources/logging.py index ac2656a2b..bbeec77f9 100644 --- a/standard_resources/revolve2/standard_resources/logging.py +++ b/standard_resources/revolve2/standard_resources/logging.py @@ -15,17 +15,12 @@ def setup_logging(level: int = logging.INFO, file_name: str | None = None) -> No # By default, we are interested in messages of level 'info' and the more severe 'warning', 'error', and 'critical', # and we exclude the less severe 'debug'. # Furthermore, we specify the format in which we want the messages to be printed. - if file_name is None: - logging.basicConfig( - level=logging.INFO, - format="[%(asctime)s] [%(levelname)s] [%(module)s] %(message)s", - ) - else: - logging.basicConfig( - level=logging.INFO, - format="[%(asctime)s] [%(levelname)s] [%(module)s] %(message)s", - handlers=[logging.FileHandler(file_name), logging.StreamHandler()], - ) + logging.basicConfig( + level=level, + format="[%(asctime)s] [%(levelname)s] [%(module)s] %(message)s", + ) + if file_name is not None: + logging.root.handlers.append(logging.FileHandler(file_name)) logging.info("=======================================") logging.info("=======================================") logging.info("=======================================")