From fc2a01cd52cf7f96f1d085d3eeb3cb7840d22ad2 Mon Sep 17 00:00:00 2001 From: gmuloc Date: Tue, 24 Dec 2024 16:53:40 +0100 Subject: [PATCH 1/3] WIP: idempotency of setup logger --- anta/logger.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/anta/logger.py b/anta/logger.py index 54733fb73..2fcd619e3 100644 --- a/anta/logger.py +++ b/anta/logger.py @@ -69,7 +69,12 @@ def setup_logging(level: LogLevel = Log.INFO, file: Path | None = None) -> None: # httpx as well logging.getLogger("httpx").setLevel(logging.WARNING) - # Add RichHandler for stdout + # Add RichHandler for stdout if not already present + if root.hasHandlers(): + logger.handlers = [] + + root. + rich_handler = RichHandler(markup=True, rich_tracebacks=True, tracebacks_show_locals=False) # Show Python module in stdout at DEBUG level fmt_string = "[grey58]\\[%(name)s][/grey58] %(message)s" if loglevel == logging.DEBUG else "%(message)s" From 197187055520d1b4b95ff249fe6748a0cbcd7877 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:57:40 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- anta/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anta/logger.py b/anta/logger.py index 2fcd619e3..1bb245038 100644 --- a/anta/logger.py +++ b/anta/logger.py @@ -70,7 +70,7 @@ def setup_logging(level: LogLevel = Log.INFO, file: Path | None = None) -> None: logging.getLogger("httpx").setLevel(logging.WARNING) # Add RichHandler for stdout if not already present - if root.hasHandlers(): + if root.hasHandlers(): logger.handlers = [] root. From b17dde6b41479c22d65ade92bdc6c4f8c7400d6a Mon Sep 17 00:00:00 2001 From: gmuloc Date: Tue, 24 Dec 2024 17:43:33 +0100 Subject: [PATCH 3/3] Fix: With the correct logic #yolo --- anta/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anta/logger.py b/anta/logger.py index 6bdf4bc15..9f193c91b 100644 --- a/anta/logger.py +++ b/anta/logger.py @@ -72,7 +72,7 @@ def setup_logging(level: LogLevel = Log.INFO, file: Path | None = None) -> None: # Add RichHandler for stdout if not already present maybe_add_rich_handler = True if root.hasHandlers(): - maybe_add_rich_handler = any(handler.get_name() == "ANTA_RICH_HANDLER" for handler in root.handlers) + maybe_add_rich_handler = all(handler.get_name() != "ANTA_RICH_HANDLER" for handler in root.handlers) if maybe_add_rich_handler: rich_handler = RichHandler(markup=True, rich_tracebacks=True, tracebacks_show_locals=False)