avoid double logging of celery

This commit is contained in:
Phlogi
2025-08-26 16:59:14 +02:00
parent a6bdf966a4
commit 9f834a67bc
2 changed files with 17 additions and 2 deletions

View File

@@ -285,9 +285,16 @@ def setup_celery_logging(**kwargs):
"""
This handler ensures Celery uses our application logging settings
instead of its own. Prevents duplicate log configurations.
Also disables console logging if NO_CONSOLE_LOG=1 is set in the environment.
"""
# Using the root logger's handlers and level preserves our config
return logging.getLogger()
root_logger = logging.getLogger()
import os
if os.environ.get("NO_CONSOLE_LOG") == "1":
# Remove all StreamHandlers (console handlers) from the root logger
handlers_to_remove = [h for h in root_logger.handlers if isinstance(h, logging.StreamHandler)]
for h in handlers_to_remove:
root_logger.removeHandler(h)
return root_logger
# The initialization of a worker will log the worker configuration