From a2af75b0be8ad7a66517ea7fee09a952b7ec15b1 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Tue, 20 Feb 2024 16:43:41 +0000 Subject: [PATCH] Instruct iotaa to use custom logger, too --- src/uwtools/logging.py | 3 +++ src/uwtools/tests/test_logging.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/uwtools/logging.py b/src/uwtools/logging.py index 788bfdf21..cba2d8cc7 100644 --- a/src/uwtools/logging.py +++ b/src/uwtools/logging.py @@ -7,6 +7,8 @@ import sys from typing import Any +import iotaa + # The logging prefix # # [YYYY-MM-DDTHH:MM:HH]_CRITICAL_ @@ -67,3 +69,4 @@ def use_logger(logger: logging.Logger) -> None: :param logger: The logger to log to. """ log.logger = logger + iotaa.logset(logger) diff --git a/src/uwtools/tests/test_logging.py b/src/uwtools/tests/test_logging.py index 6cba77952..8c6b20526 100644 --- a/src/uwtools/tests/test_logging.py +++ b/src/uwtools/tests/test_logging.py @@ -54,9 +54,11 @@ def test_setup_logging_verbose(): def test_use_logger(): with patch.object(uwtools.logging, "log", uwtools.logging._Logger()): - # Initially, uwtools logging uses the Python root logger: - assert uwtools.logging.log.logger == logging.getLogger() - # But the logger can be swapped to use a logger of choice: - test_logger = logging.getLogger("test-logger") - uwtools.logging.use_logger(test_logger) - assert uwtools.logging.log.logger == test_logger + with patch.object(uwtools.logging.iotaa, "logset") as logset: + # Initially, uwtools logging uses the Python root logger: + assert uwtools.logging.log.logger == logging.getLogger() + # But the logger can be swapped to use a logger of choice: + test_logger = logging.getLogger("test-logger") + uwtools.logging.use_logger(test_logger) + assert uwtools.logging.log.logger == test_logger + logset.assert_called_once_with(test_logger)