mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 02:35:18 -05:00
refactor: Replace direct error logging with capture_and_log utility in performance and rate limiting middleware.
This commit is contained in:
@@ -9,6 +9,8 @@ from django.conf import settings
|
|||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.utils.deprecation import MiddlewareMixin
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
|
|
||||||
|
from apps.core.utils import capture_and_log
|
||||||
|
|
||||||
performance_logger = logging.getLogger("performance")
|
performance_logger = logging.getLogger("performance")
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -130,12 +132,11 @@ class PerformanceMiddleware(MiddlewareMixin):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
performance_logger.error(
|
capture_and_log(
|
||||||
f"Request exception: {request.method} {request.path} - "
|
exception,
|
||||||
f"{duration:.3f}s, {total_queries} queries, {type(exception).__name__}: {
|
f'Request exception: {request.method} {request.path} - {duration:.3f}s, {total_queries} queries',
|
||||||
exception
|
source='middleware',
|
||||||
}",
|
severity='high',
|
||||||
extra=performance_data,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Don't return anything - let the exception propagate normally
|
# Don't return anything - let the exception propagate normally
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ from collections.abc import Callable
|
|||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpRequest, HttpResponse, JsonResponse
|
from django.http import HttpRequest, HttpResponse, JsonResponse
|
||||||
|
|
||||||
|
from apps.core.utils import capture_and_log
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +217,9 @@ class SecurityEventLogger:
|
|||||||
user = getattr(request, "user", None)
|
user = getattr(request, "user", None)
|
||||||
username = user.username if user and user.is_authenticated else "anonymous"
|
username = user.username if user and user.is_authenticated else "anonymous"
|
||||||
|
|
||||||
logger.error(
|
capture_and_log(
|
||||||
f"Suspicious activity detected - Type: {activity_type}, "
|
RuntimeError(f'Suspicious activity detected - Type: {activity_type}'),
|
||||||
f"IP: {client_ip}, User: {username}, Details: {details}"
|
f'Suspicious activity - IP: {client_ip}, User: {username}, Details: {details}',
|
||||||
|
source='security',
|
||||||
|
severity='high',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from .signals import (
|
|||||||
pre_state_transition,
|
pre_state_transition,
|
||||||
state_transition_failed,
|
state_transition_failed,
|
||||||
)
|
)
|
||||||
|
from apps.core.utils import capture_and_log
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -84,7 +85,12 @@ def with_callbacks(
|
|||||||
if not pre_success and pre_failures:
|
if not pre_success and pre_failures:
|
||||||
for callback, exc in pre_failures:
|
for callback, exc in pre_failures:
|
||||||
if not callback.continue_on_error:
|
if not callback.continue_on_error:
|
||||||
logger.error(f"Pre-transition callback {callback.name} failed, " f"aborting transition")
|
capture_and_log(
|
||||||
|
exc or RuntimeError(f'Pre-transition callback {callback.name} failed'),
|
||||||
|
f'Aborting transition - pre-callback failed',
|
||||||
|
source='state_machine',
|
||||||
|
severity='high',
|
||||||
|
)
|
||||||
if exc:
|
if exc:
|
||||||
raise exc
|
raise exc
|
||||||
raise RuntimeError(f"Pre-transition callback {callback.name} failed")
|
raise RuntimeError(f"Pre-transition callback {callback.name} failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user