From ae5c89b49c9ebe6d6e2a98c2a756612c1df73e1b Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Wed, 15 Jan 2025 14:51:06 +0000 Subject: [PATCH 1/2] flask logging: add NOTIFY_LOG_LEVEL_HANDLERS config variable this allows the handler's log level to be set differently from NOTIFY_LOG_LEVEL, but it should continue to fall back to NOTIFY_LOG_LEVEL's value if not set explicitly this is a stopgap workaround to introduce a little bit of flexibility into our weirdly inflexible log setup (i.e. to make it possible to get some use out of NOTIFY_REQUEST_LOG_LEVEL without having to raise the global log level --- notifications_utils/logging/flask.py | 3 ++- tests/test_logging.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/notifications_utils/logging/flask.py b/notifications_utils/logging/flask.py index 95aa20a2..aa2da7cf 100644 --- a/notifications_utils/logging/flask.py +++ b/notifications_utils/logging/flask.py @@ -104,6 +104,7 @@ def _log_response_closed( def init_app(app, statsd_client=None, extra_filters: Sequence[logging.Filter] = ()): app.config.setdefault("NOTIFY_LOG_LEVEL", "INFO") + app.config.setdefault("NOTIFY_LOG_LEVEL_HANDLERS", app.config["NOTIFY_LOG_LEVEL"]) app.config.setdefault("NOTIFY_APP_NAME", "none") app.config.setdefault("NOTIFY_LOG_DEBUG_PATH_LIST", {"/_status", "/metrics"}) app.config.setdefault("NOTIFY_REQUEST_LOG_LEVEL", "CRITICAL") @@ -252,7 +253,7 @@ def is_200_static_log(log): def configure_handler(handler, app, formatter, *, extra_filters: Sequence[logging.Filter]): - handler.setLevel(logging.getLevelName(app.config["NOTIFY_LOG_LEVEL"])) + handler.setLevel(logging.getLevelName(app.config["NOTIFY_LOG_LEVEL_HANDLERS"])) handler.setFormatter(formatter) handler.addFilter(AppNameFilter(app.config["NOTIFY_APP_NAME"])) handler.addFilter(RequestIdFilter()) diff --git a/tests/test_logging.py b/tests/test_logging.py index 7b8a981f..cb7b358a 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -14,7 +14,7 @@ def test_get_handlers_sets_up_logging_appropriately_with_debug(): class App: - config = {"NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "ERROR"} + config = {"NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "ERROR", "NOTIFY_LOG_LEVEL_HANDLERS": "ERROR"} debug = True app = App() @@ -31,6 +31,7 @@ class App: config = { "NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "ERROR", + "NOTIFY_LOG_LEVEL_HANDLERS": "ERROR", } debug = False @@ -58,6 +59,7 @@ class App: config = { "NOTIFY_APP_NAME": "bar", "NOTIFY_LOG_LEVEL": "INFO", + "NOTIFY_LOG_LEVEL_HANDLERS": "INFO", } debug = False From e0689c806f5760b3591e2c7c96d12a6023ed589a Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Wed, 15 Jan 2025 14:56:03 +0000 Subject: [PATCH 2/2] Bump version to 93.1.0 --- CHANGELOG.md | 4 ++++ notifications_utils/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d36622..8018f081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 93.1.0 + +* Introduce `NOTIFY_LOG_LEVEL_HANDLERS` config variable for separate control of handler log level + ## 93.0.0 * BREAKING CHANGE: logging: all contents of `logging/__init__.py` have been moved to `logging/flask.py` because they all assume a flask(-like) environment and this way we don't implicitly import all of flask etc. every time anything under `logging` is imported. diff --git a/notifications_utils/version.py b/notifications_utils/version.py index 58904e7b..4b48c0e0 100644 --- a/notifications_utils/version.py +++ b/notifications_utils/version.py @@ -5,4 +5,4 @@ # - `make version-minor` for new features # - `make version-patch` for bug fixes -__version__ = "93.0.0" # be07bef3f012f0ac2c700237176bb412 +__version__ = "93.1.0" # 9cc2b70dbe2edeadbeef