Skip to content

Commit

Permalink
fix(server): fix logging filter not working properly
Browse files Browse the repository at this point in the history
Special thanks to @offby1 on the official Django Discord for the
troubleshooting help and fix!
  • Loading branch information
ericswpark committed Apr 6, 2024
1 parent cd9865d commit b19f582
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/config/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class IgnoreMissingBuild503Errors(logging.Filter):
"""

def filter(self, record):
status_code = getattr(record, "status_code", None)
return status_code != 503
# Message is of the format `"GET /download_check/.../ HTTP/1.1" 503 125`
message = record.getMessage()
return "download_check" not in message and " 503 " not in message
40 changes: 38 additions & 2 deletions server/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from dotenv import load_dotenv

from .filters import IgnoreMissingBuild503Errors
from core.exceptions import UploadException, BuildMirrorException

load_dotenv()
Expand Down Expand Up @@ -161,16 +162,51 @@
"disable_existing_loggers": False,
"filters": {
"ignore_missing_build_503_errors": {
"()": "config.filters.IgnoreMissingBuild503Errors",
"()": IgnoreMissingBuild503Errors,
},
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
},
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue",
},
},
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "---- [{server_time}] {message}",
"style": "{",
}
},
"handlers": {
"console": {
"level": "INFO",
"filters": ["require_debug_true", "ignore_missing_build_503_errors"],
"class": "logging.StreamHandler",
},
"django.server": {
"level": "INFO",
"filters": ["ignore_missing_build_503_errors"],
"class": "logging.StreamHandler",
"formatter": "django.server",
},
"mail_admins": {
"level": "ERROR",
"filters": ["ignore_missing_build_503_errors"],
"filters": ["require_debug_false", "ignore_missing_build_503_errors"],
"class": "django.utils.log.AdminEmailHandler",
},
},
"loggers": {
"django": {
"handlers": ["console", "mail_admins"],
"level": "INFO",
},
"django.server": {
"handlers": ["django.server"],
"level": "INFO",
"propagate": False,
},
},
}


Expand Down

0 comments on commit b19f582

Please sign in to comment.