mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-02-10 22:20:24 +00:00
- Add pyproject.toml with uv and ruff configuration - Pin Python version to 3.13 via .python-version - Add Makefile commands: lint, format, fix - Apply ruff formatting to entire codebase - Remove unused imports (base64 in yookassa/simple_subscription) - Update .gitignore for new config files
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from time import monotonic
|
|
|
|
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
|
from starlette.requests import Request
|
|
from starlette.responses import Response
|
|
|
|
|
|
logger = logging.getLogger('web_api')
|
|
|
|
|
|
class RequestLoggingMiddleware(BaseHTTPMiddleware):
|
|
"""Логирование входящих запросов в административный API."""
|
|
|
|
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
|
|
start = monotonic()
|
|
response: Response | None = None
|
|
try:
|
|
response = await call_next(request)
|
|
return response
|
|
finally:
|
|
duration_ms = (monotonic() - start) * 1000
|
|
status = response.status_code if response else 'error'
|
|
logger.debug(
|
|
'%s %s -> %s (%.2f ms)',
|
|
request.method,
|
|
request.url.path,
|
|
status,
|
|
duration_ms,
|
|
)
|