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