From a45e411094c8c88787093def93cedf308b748815 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 18 Dec 2024 11:59:30 -0800 Subject: [PATCH] stop workers from propagating logs --- app/__init__.py | 4 ++++ notifications_utils/logging.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 16ffbd5a9..23c2399e1 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,3 +1,4 @@ +import logging as real_logging import os import secrets import string @@ -36,6 +37,9 @@ def init_app(self, app): # Configure Celery app with options from the main app config. self.config_from_object(app.config["CELERY"]) + self.conf.worker_hijack_root_logger = False + logger = real_logging.getLogger("celery") + logger.propagate = False def send_task(self, name, args=None, kwargs=None, **other_kwargs): other_kwargs["headers"] = other_kwargs.get("headers") or {} diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index 0a13555d4..a15d00169 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -70,10 +70,12 @@ def init_app(app): for logger_instance, handler in product(loggers, handlers): logger_instance.addHandler(handler) logger_instance.setLevel(loglevel) + logger_instance.propagate = False warning_loggers = [logging.getLogger("boto3"), logging.getLogger("s3transfer")] for logger_instance, handler in product(warning_loggers, handlers): logger_instance.addHandler(handler) logger_instance.setLevel(logging.WARNING) + logger_instance.propagate = False # Suppress specific loggers to prevent leaking sensitive info logging.getLogger("boto3").setLevel(logging.ERROR)