schon/evibes/settings/logconfig.py
Egor fureunoir Gorbunov 1024760c15 Features: 1) Add autocomplete_list_filter support in Admin classes; 2) Introduce SkipVariableDoesNotExistFilter to suppress specific log warnings.
Fixes: 1) Clean up unused imports in `filters.py`.

Extra: 1) Apply consistent string quoting across `admin.py` for formatting standardization; 2) Update logging configuration for `django.template` with new filter.
2025-07-01 16:41:20 +03:00

112 lines
3.9 KiB
Python

from evibes.settings.base import * # noqa: F403
class SkipVariableDoesNotExistFilter(logging.Filter): # noqa: F405
def filter(self, record: logging.LogRecord) -> bool: # noqa: F405
if record.exc_info:
exc_type, exc_instance, _ = record.exc_info
try:
if exc_type.__name__ == "VariableDoesNotExist": # type: ignore
return False
except AttributeError:
return True
return "VariableDoesNotExist" not in record.getMessage()
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"color": {
"()": "colorlog.ColoredFormatter",
"format": "%(asctime)s %(log_color)s[%(levelname)s]%(reset)s %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
"log_colors": {
"DEBUG": "cyan",
"INFO": "bold_green",
"WARNING": "bold_yellow",
"ERROR": "bold_red",
"CRITICAL": "bold_red,bg_white",
},
},
"plain": {
"format": "[%(asctime)s] [%(levelname)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
"filters": {
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue",
},
"skip_variable_doesnotexist": {
"()": "evibes.settings.logconfig.SkipVariableDoesNotExistFilter",
},
},
"handlers": {
"console_debug": {
"level": "DEBUG",
"filters": ["require_debug_true"],
"class": "logging.StreamHandler",
"formatter": "color",
},
"console_production": {
"level": "WARNING",
"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"],
"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
"propagate": False,
},
"django.db.backends": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "WARNING",
"propagate": False,
},
"django.template": {
"handlers": ["console_debug", "console_production"],
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"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
"propagate": True,
},
"django_elasticsearch_dsl": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"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
"propagate": False,
},
"celery.worker.strategy": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "DEBUG" if DEBUG else "INFO", # noqa: F405
"propagate": False,
},
"elastic_transport.transport": {
"handlers": ["console_debug" if DEBUG else "console_production"], # noqa: F405
"level": "ERROR",
"propagate": False,
},
},
}