Исправлен формат представления лога

This commit is contained in:
2026-07-19 20:10:44 +03:00
parent a6c9db1a71
commit e40d5a4159
4 changed files with 17 additions and 10 deletions

View File

@@ -30,7 +30,7 @@ class CoreResponse(Response):
result: dict[str, list | dict | str | float | int | bool] = { result: dict[str, list | dict | str | float | int | bool] = {
"status": internal_status, "status": internal_status,
"timestamp": timezone.now().timestamp() "timestamp": int(timezone.now().timestamp())
} }
# Формируем данные ответа # Формируем данные ответа

View File

@@ -10,6 +10,7 @@
import json import json
import logging import logging
import traceback
from logging import Logger from logging import Logger
from typing import Any from typing import Any
@@ -155,7 +156,7 @@ class CustomLoggingMiddleware:
try: try:
data_json = json.loads(raw_response) data_json = json.loads(raw_response)
masked_response = self._mask_sensitive_data(data_json) masked_response = self._mask_sensitive_data(data_json)
result = json.dumps(masked_response, ensure_ascii=False, indent=2) result = json.dumps(masked_response, ensure_ascii=False, indent=4)
except json.JSONDecodeError: except json.JSONDecodeError:
result = raw_response result = raw_response
except UnicodeDecodeError: except UnicodeDecodeError:
@@ -174,16 +175,24 @@ class CustomLoggingMiddleware:
if exc or status_code >= status.HTTP_400_BAD_REQUEST: if exc or status_code >= status.HTTP_400_BAD_REQUEST:
if exc:
tb_string = ''.join(traceback.format_exception(
type(exc), # тип исключения
exc, # сам объект исключения
exc.__traceback__ # объект traceback
))
log_message += f"\n{tb_string}\n"
if status_code == status.HTTP_400_BAD_REQUEST: if status_code == status.HTTP_400_BAD_REQUEST:
self.logger.debug(log_message, exc_info=exc) self.logger.debug(log_message)
elif status_code == status.HTTP_401_UNAUTHORIZED: elif status_code == status.HTTP_401_UNAUTHORIZED:
self.logger.warning(log_message, exc_info=exc) self.logger.warning(log_message)
elif status_code == status.HTTP_403_FORBIDDEN: elif status_code == status.HTTP_403_FORBIDDEN:
self.logger.warning(log_message, exc_info=exc) self.logger.warning(log_message)
elif status_code == status.HTTP_404_NOT_FOUND: elif status_code == status.HTTP_404_NOT_FOUND:
self.logger.error(log_message, exc_info=exc) self.logger.error(log_message)
else: else:
self.logger.critical(log_message, exc_info=exc) self.logger.critical(log_message)
else: else:
self.logger.debug(log_message) self.logger.debug(log_message)

View File

@@ -53,7 +53,7 @@ LOGGING = {
"formatters": { "formatters": {
"custom_format": { "custom_format": {
"format": "\n{asctime} [{levelname}] {message}", "format": "{asctime} [{levelname}] {message}",
"datefmt": "%Y-%m-%d %H:%M:%S", "datefmt": "%Y-%m-%d %H:%M:%S",
"style": "{", "style": "{",
}, },

View File

@@ -45,8 +45,6 @@ class VersionViewSet(ViewSetRetrieveMixin, CoreViewSet):
"version": SettingUtils.get_app_version() "version": SettingUtils.get_app_version()
} }
z = 1 / 0
return version_info return version_info
@classmethod @classmethod