Skip to content

Commit ddb5dc3

Browse files
committed
feat: use celery structlog logging
1 parent b6d8f03 commit ddb5dc3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

config/celery_app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
2+
from logging.config import dictConfig
23
from pathlib import Path
34

45
from celery import Celery, bootsteps
56
from celery.schedules import crontab
6-
from celery.signals import worker_ready, worker_shutdown
7+
from celery.signals import setup_logging, worker_ready, worker_shutdown
8+
from django.conf import settings
79

810
# set the default Django settings module for the 'celery' program.
911
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
@@ -17,6 +19,11 @@
1719
app.config_from_object("django.conf:settings", namespace="CELERY")
1820

1921

22+
@setup_logging.connect
23+
def config_loggers(*args, **kwargs):
24+
dictConfig(settings.LOGGING)
25+
26+
2027
HEARTBEAT_FILE = Path("/tmp/worker_heartbeat")
2128
READINESS_FILE = Path("/tmp/worker_ready")
2229

config/settings/local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
DEV_FILTERED_EVENTS = ["request_started"]
7878

7979

80-
class DevelopmentFilter(logging.Filter):
80+
class DevelopmentFilter(logging.Filter): # pylint: disable=too-few-public-methods
8181
"""Filter out events in development so they don't clutter the console"""
8282

8383
def filter(self, record):
@@ -88,7 +88,7 @@ def filter(self, record):
8888
return True
8989

9090

91-
LOGGING["handlers"]["console"]["filters"] = [DevelopmentFilter()]
91+
LOGGING["handlers"]["console"]["filters"] = [DevelopmentFilter()] # type: ignore
9292

9393
# Celery
9494
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)