Skip to content

Commit

Permalink
Pass custom logger to iotaa (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Feb 22, 2024
1 parent b89a788 commit 4fa8106
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/uwtools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
from typing import Any

import iotaa

# The logging prefix
#
# [YYYY-MM-DDTHH:MM:HH]_CRITICAL_
Expand Down Expand Up @@ -67,3 +69,4 @@ def use_logger(logger: logging.Logger) -> None:
:param logger: The logger to log to.
"""
log.logger = logger
iotaa.logset(logger)
14 changes: 8 additions & 6 deletions src/uwtools/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 4fa8106

Please sign in to comment.