From 82fa52c801d220a653d401ec9a5a97c09da1b1a4 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 21 Aug 2024 13:31:36 -0700 Subject: [PATCH] fix log formatting --- notifications_utils/logging.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index 9f5a98c2e..3ec092b8c 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -160,6 +160,12 @@ class JSONFormatter(BaseJSONFormatter): log_record["logType"] = "application" try: log_record["message"] = log_record["message"].format(**log_record) - except (KeyError, IndexError) as e: - logger.exception("failed to format log message: {} not found".format(e)) + except KeyError as e: + # We get occasional log messages that are nested dictionaries, + # for example, delivery receipts, where the formatting fails + # This is not a huge problem, don't dump stack traces into the logs + # for it. + logger.warning(f"failed to format log message: {e}") + except IndexError as e: + logger.exception(f"failed to format log message: {e}") return log_record