mirror of
https://github.com/Viren070/MediaFusion.git
synced 2025-12-01 23:21:11 +01:00
23 lines
716 B
Python
23 lines
716 B
Python
import logging
|
|
|
|
from fastapi.requests import Request
|
|
from fastapi.responses import Response
|
|
|
|
|
|
class SecureLoggingMiddleware:
|
|
async def __call__(self, request: Request, call_next):
|
|
response = await call_next(request)
|
|
self.custom_log(request, response)
|
|
return response
|
|
|
|
@staticmethod
|
|
def custom_log(request: Request, response: Response):
|
|
url_path = request.url.path
|
|
if request.path_params.get("secret_str"):
|
|
url_path = url_path.replace(
|
|
request.path_params.get("secret_str"), "***MASKED***"
|
|
)
|
|
logging.info(
|
|
f'{request.client.host} - "{request.method} {url_path} HTTP/1.1" {response.status_code}'
|
|
)
|