Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
22 changes: 22 additions & 0 deletions backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def set_ciso_assistant_url(_, __, event_dict):
return event_dict


class IgnoreApiBuildFilter(logging.Filter):
"""Filter out request_finished logs for /api/build endpoint with 404 status."""

def filter(self, record):
request = getattr(record, "request", None)
code = getattr(record, "code", None)
if (
code == 404
and request
and (request.endswith("/api/build") or request.endswith("/api/build/"))
):
return False
return True


LOGGING = {
"version": 1,
"disable_existing_loggers": False,
Expand All @@ -54,10 +69,16 @@ def set_ciso_assistant_url(_, __, event_dict):
"processor": structlog.dev.ConsoleRenderer(),
},
},
"filters": {
"ignore_api_build": {
"()": IgnoreApiBuildFilter,
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": LOG_FORMAT,
"filters": ["ignore_api_build"],
},
},
"loggers": {
Expand All @@ -76,6 +97,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"class": "logging.handlers.WatchedFileHandler",
"filename": "ciso-assistant.log",
"formatter": "json",
"filters": ["ignore_api_build"],
}
LOGGING["loggers"][""]["handlers"].append("file")

Expand Down
18 changes: 18 additions & 0 deletions enterprise/backend/enterprise_core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def set_ciso_assistant_url(_, __, event_dict):
return event_dict


class IgnoreApiBuildFilter(logging.Filter):
"""Filter out request_finished logs for /api/build endpoint with 404 status."""

def filter(self, record):
request = getattr(record, "request", None)
code = getattr(record, "code", None)
if code == 404 and request and "/api/build" in request:
return False
return True


LOGGING = {
"version": 1,
"disable_existing_loggers": False,
Expand All @@ -51,10 +62,16 @@ def set_ciso_assistant_url(_, __, event_dict):
"processor": structlog.dev.ConsoleRenderer(),
},
},
"filters": {
"ignore_api_build": {
"()": IgnoreApiBuildFilter,
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": LOG_FORMAT,
"filters": ["ignore_api_build"],
},
},
"loggers": {
Expand All @@ -68,6 +85,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"class": "logging.handlers.WatchedFileHandler",
"filename": "ciso-assistant.log",
"formatter": "json",
"filters": ["ignore_api_build"],
}
LOGGING["loggers"][""]["handlers"].append("file")

Expand Down
Loading