Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,30 @@
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
"filters": {
"below_error": {
"()": "django.utils.log.CallbackFilter",
"callback": lambda record: record.levelno < logging.ERROR,
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "verbose",
"filters": ["below_error"],
},
"console_error": {
"level": "ERROR",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
"formatter": "verbose",
},
"time_logging": {
"level": "INFO",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "request_time",
},
},
Expand All @@ -357,7 +372,7 @@
"propagate": False,
},
},
"root": {"level": "INFO", "handlers": ["console"]},
"root": {"level": "INFO", "handlers": ["console", "console_error"]},
}

# Django Rest Framework
Expand Down
26 changes: 22 additions & 4 deletions config/settings/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,40 @@
"%(process)d %(thread)d %(message)s"
}
},
"filters": {
"below_error": {
"()": "django.utils.log.CallbackFilter",
"callback": lambda record: record.levelno < logging.ERROR,
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "verbose",
}
"filters": ["below_error"],
},
"console_error": {
"level": "ERROR",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
"formatter": "verbose",
},
},
"root": {"level": "INFO", "handlers": ["console"]},
"root": {"level": "INFO", "handlers": ["console", "console_error"]},
"loggers": {
"django.db.backends": {
"level": "ERROR",
"handlers": ["console"],
"handlers": ["console_error"],
"propagate": False,
},
# Errors logged by the SDK itself
"sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
"sentry_sdk": {
"level": "ERROR",
"handlers": ["console_error"],
"propagate": False,
},
},
}

Expand Down
25 changes: 20 additions & 5 deletions config/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
import logging

from authlib.jose import JsonWebKey

Expand Down Expand Up @@ -66,28 +67,42 @@
"formatters": {
"verbose": {"format": "%(levelname)s %(asctime)s %(module)s %(message)s"}
},
"filters": {
"below_error": {
"()": "django.utils.log.CallbackFilter",
"callback": lambda record: record.levelno < logging.ERROR,
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"formatter": "verbose",
}
"filters": ["below_error"],
},
"console_error": {
"level": "ERROR",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
"formatter": "verbose",
},
},
"loggers": {
"django.request": {
"handlers": ["console"],
"handlers": ["console_error"],
"level": "ERROR",
},
"audit_log": {
"handlers": ["console"],
"handlers": ["console_error"],
"level": "ERROR",
},
"celery": {
"handlers": ["console"],
"handlers": ["console_error"],
"level": "ERROR",
},
Comment on lines 92 to 103

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Double-emission of ERROR logs in test settings

The django.request, audit_log, and celery loggers all send records directly to console_error, but none have "propagate": False. Because the root logger also includes console_error, every ERROR record from these loggers will be written to stderr twice — once by the logger's own handler and once by the root logger's handler. The deployment.py loggers (django.db.backends, sentry_sdk) correctly use "propagate": False to prevent exactly this. Adding the same key to the three loggers in test.py would fix the duplicate output.

},
"root": {"level": "INFO", "handlers": ["console"]},
"root": {"level": "INFO", "handlers": ["console", "console_error"]},
Comment on lines 91 to +105

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

git ls-files config/settings && printf '\n--- test.py ---\n' && sed -n '1,220p' config/settings/test.py && printf '\n--- deployment.py ---\n' && sed -n '1,260p' config/settings/deployment.py

Repository: ohcnetwork/care

Length of output: 9939


Add propagate: False to these loggers. django.request, audit_log, and celery already write to console_error; letting them bubble to root just emits the same ERROR twice on stderr. config/settings/test.py:91-105

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config/settings/test.py` around lines 91 - 105, Add propagate: False to the
django.request, audit_log, and celery logger entries in the logging config so
their ERROR messages do not bubble up to the root logger and get duplicated on
stderr. Update the loggers block in config/settings/test.py by setting propagate
to False for each of these named loggers while keeping their existing
console_error handler and ERROR level.

}

CELERY_TASK_ALWAYS_EAGER = True
Expand Down
Loading