Skip to content

Commit 0024b8f

Browse files
committed
Verbose mode targets desired logging familes
Why these changes are being introduced: Previously, when --verbose was set for the CLI all loggers inherited this. In other applications, we have used a 'WARNING_ONLY_LOGGERS' env var that would limit them to WARNING level. This worked, but was perhaps not ideal. Without that env var, it's a bit of whack-a-mole to figure out which loggers to quiet. How this addresses that need: Instead of defaulting all loggers to DEBUG in verbose mode, we target only libraries we expect this application to log in DEBUG. By default, all other logger families will still have WARNING. This may be a pattern we want to explore in other repositories. Potentially even further inverting the pattern and supporting a 'DEBUG_LOGGERS' env var list that would explicitly toggle on DEBUG logging for those libraries. That would allow troubleshooting in deployed environments just by setting an env var. This is NOT applied in this commit, but noting for future consideration. Side effects of this change: * Both 'embeddings' and 'timdex_dataset_api' are logged as DEBUG in verbose mode, but only those libraries. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/USE-112
1 parent ce181df commit 0024b8f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

embeddings/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def configure_logger(logger: logging.Logger, *, verbose: bool) -> str:
1010
format="%(asctime)s %(levelname)s %(name)s.%(funcName)s() line %(lineno)d: "
1111
"%(message)s"
1212
)
13-
logger.setLevel(logging.DEBUG)
13+
logging.getLogger("embeddings").setLevel(logging.DEBUG)
14+
logging.getLogger("timdex_dataset_api").setLevel(logging.DEBUG)
1415
else:
1516
logging.basicConfig(
1617
format="%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s"

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def test_configure_logger_not_verbose():
1212

1313

1414
def test_configure_logger_verbose():
15-
logger = logging.getLogger(__name__)
15+
logger = logging.getLogger("embeddings.cli")
1616
result = configure_logger(logger, verbose=True)
1717
debug_log_level = 10
1818
assert logger.getEffectiveLevel() == debug_log_level
19-
assert result == "Logger 'tests.test_config' configured with level=DEBUG"
19+
assert result == "Logger 'embeddings.cli' configured with level=DEBUG"
2020

2121

2222
def test_configure_sentry_no_env_variable(monkeypatch):

0 commit comments

Comments
 (0)