From 24fba3c2b1e8f632474c8388fb089e91a4317287 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sat, 10 May 2025 09:58:57 -0500 Subject: [PATCH] Change some celery tasks from info to debug. --- dispatcharr/celery.py | 33 ++++++++++++++++++++++++--------- docker/uwsgi.debug.ini | 4 ++-- docker/uwsgi.dev.ini | 4 ++-- docker/uwsgi.ini | 4 ++-- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/dispatcharr/celery.py b/dispatcharr/celery.py index f9e2525d..28b94263 100644 --- a/dispatcharr/celery.py +++ b/dispatcharr/celery.py @@ -2,6 +2,7 @@ import os from celery import Celery import logging +from django.conf import settings # Import Django settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dispatcharr.settings') app = Celery("dispatcharr") @@ -10,19 +11,33 @@ app.autodiscover_tasks() # Configure Celery logging app.conf.update( - worker_log_level='DEBUG', + worker_log_level=settings.LOG_LEVEL_NAME, # Use same log level from environment worker_log_format='%(asctime)s %(levelname)s %(name)s: %(message)s', - beat_log_level='DEBUG', + beat_log_level=settings.LOG_LEVEL_NAME, # Use same log level from environment worker_hijack_root_logger=False, worker_task_log_format='%(asctime)s %(levelname)s %(task_name)s: %(message)s', ) -# Set only specific log messages to DEBUG level -# This maintains user configurability for all other loggers @app.on_after_configure.connect def setup_celery_logging(**kwargs): - # Only set specific loggers to DEBUG that handle the routine messages - # we want to suppress from INFO level - logging.getLogger('celery.beat').getChild('Scheduler').setLevel(logging.DEBUG) - logging.getLogger('celery.worker.strategy').setLevel(logging.DEBUG) - logging.getLogger('celery.app.trace').setLevel(logging.DEBUG) + # Check if user has set logging to INFO level + if settings.LOG_LEVEL_NAME.upper() == 'INFO': + # Get the specific loggers that output the noisy INFO messages + for logger_name in ['celery.app.trace', 'celery.beat', 'celery.worker.strategy', 'celery.beat.Scheduler']: + # Create a custom filter to suppress specific messages + logger = logging.getLogger(logger_name) + + # Add a custom filter to completely filter out the repetitive messages + class SuppressFilter(logging.Filter): + def filter(self, record): + # Return False to completely suppress these specific patterns when at INFO level + if ( + "succeeded in" in getattr(record, 'msg', '') or + "Scheduler: Sending due task" in getattr(record, 'msg', '') or + "received" in getattr(record, 'msg', '') + ): + return False # Don't log these messages at all + return True # Log all other messages + + # Add the filter to each logger + logger.addFilter(SuppressFilter()) diff --git a/docker/uwsgi.debug.ini b/docker/uwsgi.debug.ini index 6acbdac3..9cd4ccdf 100644 --- a/docker/uwsgi.debug.ini +++ b/docker/uwsgi.debug.ini @@ -8,8 +8,8 @@ exec-before = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server ; Then start other services -attach-daemon = celery -A dispatcharr worker -l debug -attach-daemon = celery -A dispatcharr beat -l debug +attach-daemon = celery -A dispatcharr worker +attach-daemon = celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application attach-daemon = cd /app/frontend && npm run dev diff --git a/docker/uwsgi.dev.ini b/docker/uwsgi.dev.ini index 0aae9516..455111d3 100644 --- a/docker/uwsgi.dev.ini +++ b/docker/uwsgi.dev.ini @@ -8,8 +8,8 @@ exec-pre = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server ; Then start other services -attach-daemon = celery -A dispatcharr worker -l debug --concurrency=4 -attach-daemon = celery -A dispatcharr beat -l debug +attach-daemon = celery -A dispatcharr worker --concurrency=4 +attach-daemon = celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application attach-daemon = cd /app/frontend && npm run dev diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index 89d6e8a1..75d4de3f 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -8,8 +8,8 @@ exec-pre = python /app/scripts/wait_for_redis.py ; Start Redis first attach-daemon = redis-server ; Then start other services -attach-daemon = celery -A dispatcharr worker -l info --concurrency=4 -attach-daemon = celery -A dispatcharr beat -l error +attach-daemon = celery -A dispatcharr worker --concurrency=4 +attach-daemon = celery -A dispatcharr beat attach-daemon = daphne -b 0.0.0.0 -p 8001 dispatcharr.asgi:application # Core settings