Skip to content

Commit

Permalink
Merge pull request #1185 from alphagov/ris-notify-log-level-handlers
Browse files Browse the repository at this point in the history
flask logging: add `NOTIFY_LOG_LEVEL_HANDLERS` config variable
  • Loading branch information
risicle authored Jan 16, 2025
2 parents 7322d35 + e0689c8 commit b593583
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion notifications_utils/logging/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion notifications_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -31,6 +31,7 @@ class App:
config = {
"NOTIFY_APP_NAME": "bar",
"NOTIFY_LOG_LEVEL": "ERROR",
"NOTIFY_LOG_LEVEL_HANDLERS": "ERROR",
}
debug = False

Expand Down Expand Up @@ -58,6 +59,7 @@ class App:
config = {
"NOTIFY_APP_NAME": "bar",
"NOTIFY_LOG_LEVEL": "INFO",
"NOTIFY_LOG_LEVEL_HANDLERS": "INFO",
}
debug = False

Expand Down

0 comments on commit b593583

Please sign in to comment.