Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass custom logger to iotaa #411

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading