Features: 1) Update all log handlers to dynamically switch based on DEBUG setting; 2) Introduce improved middleware logging configuration.

Fixes: 1) Remove unnecessary wildcard imports in settings files; 2) Add missing imports for `getenv`, `DEBUG`, and other constants; 3) Fix logger usage in middleware to align with `django.request`.

Extra: 1) Refactor settings files for readability and consistency; 2) Remove outdated `noqa` comments; 3) Minor formatting adjustments.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-07-06 16:58:43 +03:00
parent 41dd02147c
commit adfffee0a3
8 changed files with 51 additions and 33 deletions

View file

@ -16,7 +16,7 @@ from sentry_sdk import capture_exception
from evibes.settings import DEBUG
logger = logging.getLogger("evibes")
logger = logging.getLogger("django.request")
class CustomCommonMiddleware(CommonMiddleware):

View file

@ -1,4 +1,4 @@
from evibes.settings.base import getenv
from os import getenv
DATABASES = {
"default": {

View file

@ -1,4 +1,4 @@
from evibes.settings.base import getenv
from os import getenv
DBBACKUP_CONNECTORS = {
"default": {

View file

@ -1,9 +1,9 @@
# mypy: ignore-errors
from datetime import timedelta
from os import getenv
from django.utils.translation import gettext_lazy as _
from evibes.settings.base import * # noqa: F403
from evibes.settings import DEBUG, EVIBES_VERSION, SECRET_KEY
from evibes.settings.constance import CONSTANCE_CONFIG
REST_FRAMEWORK: dict = {

View file

@ -1,9 +1,11 @@
from evibes.settings.base import * # noqa: F403
from os import getenv
from evibes.settings import DEBUG
ELASTICSEARCH_DSL = {
"default": {
"hosts": ["http://elasticsearch:9200"],
"http_auth": ("elastic", getenv("ELASTIC_PASSWORD")), # noqa: F405
"http_auth": ("elastic", getenv("ELASTIC_PASSWORD")),
"verify_certs": False,
"timeout": 30,
"ssl_show_warn": False,
@ -12,6 +14,6 @@ ELASTICSEARCH_DSL = {
},
}
ELASTICSEARCH_DSL_AUTOSYNC = DEBUG # noqa: F405
ELASTICSEARCH_DSL_AUTOSYNC = DEBUG
ELASTICSEARCH_DSL_PARALLEL = True
ELASTICSEARCH_DSL_SIGNAL_PROCESSOR = "django_elasticsearch_dsl.signals.CelerySignalProcessor"

View file

@ -1,3 +1,5 @@
from evibes.settings.base import * # noqa: F403
GRAPH_MODELS = {
"all_applications": True,
"group_models": True,

View file

@ -1,11 +1,11 @@
from evibes.settings.base import * # noqa: F403
from evibes.settings.base import DEBUG
GRAPHENE = {
"MIDDLEWARE": [
"evibes.middleware.GrapheneLoggingErrorsDebugMiddleware",
"evibes.middleware.GrapheneJWTAuthorizationMiddleware",
]
if DEBUG # noqa: F405
if DEBUG
else [
"evibes.middleware.GrapheneJWTAuthorizationMiddleware",
],

View file

@ -1,8 +1,10 @@
from evibes.settings.base import * # noqa: F403
import logging
from evibes.settings.base import DEBUG
class SkipVariableDoesNotExistFilter(logging.Filter): # noqa: F405
def filter(self, record: logging.LogRecord) -> bool: # noqa: F405
class SkipVariableDoesNotExistFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
if record.exc_info:
exc_type, exc_instance, _ = record.exc_info
try:
@ -57,57 +59,69 @@ LOGGING = {
"class": "logging.StreamHandler",
"formatter": "color",
},
"mail_admins": {
"level": "ERROR",
"class": "django.utils.log.AdminEmailHandler",
"include_html": True,
"formatter": "plain",
},
},
"loggers": {
"django": {
"handlers": ["console_debug", "console_production"],
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"propagate": True,
},
"django.request": {
"handlers": ["console_debug", "mail_admins"],
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "INFO",
"propagate": False,
},
"django.db.backends": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "WARNING",
"propagate": False,
},
"django.template": {
"handlers": ["console_debug", "console_production"],
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "INFO",
"propagate": True,
"filters": ["skip_variable_doesnotexist"],
},
"evibes": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "DEBUG" if DEBUG else "WARNING", # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "WARNING",
"propagate": True,
},
"django_elasticsearch_dsl": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "WARNING",
"propagate": False,
},
"celery.app.trace": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "INFO",
"propagate": False,
},
"celery.worker.strategy": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "DEBUG" if DEBUG else "INFO",
"propagate": False,
},
"elastic_transport.transport": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"handlers": [
"console_debug" if DEBUG else "console_production",
],
"level": "ERROR",
"propagate": False,
},