mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 00:55:19 -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.utils.deprecation import MiddlewareMixin
|
||||
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
performance_logger = logging.getLogger("performance")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -130,12 +132,11 @@ class PerformanceMiddleware(MiddlewareMixin):
|
||||
),
|
||||
}
|
||||
|
||||
performance_logger.error(
|
||||
f"Request exception: {request.method} {request.path} - "
|
||||
f"{duration:.3f}s, {total_queries} queries, {type(exception).__name__}: {
|
||||
exception
|
||||
}",
|
||||
extra=performance_data,
|
||||
capture_and_log(
|
||||
exception,
|
||||
f'Request exception: {request.method} {request.path} - {duration:.3f}s, {total_queries} queries',
|
||||
source='middleware',
|
||||
severity='high',
|
||||
)
|
||||
|
||||
# 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.http import HttpRequest, HttpResponse, JsonResponse
|
||||
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -215,7 +217,9 @@ class SecurityEventLogger:
|
||||
user = getattr(request, "user", None)
|
||||
username = user.username if user and user.is_authenticated else "anonymous"
|
||||
|
||||
logger.error(
|
||||
f"Suspicious activity detected - Type: {activity_type}, "
|
||||
f"IP: {client_ip}, User: {username}, Details: {details}"
|
||||
capture_and_log(
|
||||
RuntimeError(f'Suspicious activity detected - Type: {activity_type}'),
|
||||
f'Suspicious activity - IP: {client_ip}, User: {username}, Details: {details}',
|
||||
source='security',
|
||||
severity='high',
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ from .signals import (
|
||||
pre_state_transition,
|
||||
state_transition_failed,
|
||||
)
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -84,7 +85,12 @@ def with_callbacks(
|
||||
if not pre_success and pre_failures:
|
||||
for callback, exc in pre_failures:
|
||||
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:
|
||||
raise exc
|
||||
raise RuntimeError(f"Pre-transition callback {callback.name} failed")
|
||||
|
||||
Reference in New Issue
Block a user