From b83661c8991e4cd5ebe3c248992a9cb40451eaae Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:29:31 +0200 Subject: [PATCH] Change log level for "/health" endpoint to debug (#352) --- changelog.d/352.feature | 1 + sygnal/http.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelog.d/352.feature diff --git a/changelog.d/352.feature b/changelog.d/352.feature new file mode 100644 index 00000000..90537fba --- /dev/null +++ b/changelog.d/352.feature @@ -0,0 +1 @@ +Set log level for `/health` endpoint to `DEBUG`. \ No newline at end of file diff --git a/sygnal/http.py b/sygnal/http.py index 86c69043..9669b71d 100644 --- a/sygnal/http.py +++ b/sygnal/http.py @@ -352,9 +352,18 @@ def log(self, request: server.Request) -> None: """Log this request. Called by request.finish.""" # this also works around a bug in twisted.web.http.HTTPFactory which uses a # monotonic time as an epoch time. + + def _should_log_request() -> bool: + """Whether we should log at INFO that we processed the request.""" + if request.path == b"/health": + return False + + return True + + log_level = logging.INFO if _should_log_request() else logging.DEBUG log_date_time = datetimeToLogString() line = self.log_formatter(log_date_time, request) - self.logger.info("Handled request: %s", line) + self.logger.log(log_level, "Handled request: %s", line) class PushGatewayApiServer(object):