1010
1111from src import api
1212from starlette_prometheus import metrics , PrometheusMiddleware
13-
13+ from src . core . fastapi . middleware import LoggingMiddleware
1414logger = logging .getLogger (__name__ )
1515
1616
@@ -32,6 +32,7 @@ def make_middleware() -> list[Middleware]:
3232 allow_methods = ["*" ],
3333 allow_headers = ["*" ],
3434 ),
35+ Middleware (LoggingMiddleware )
3536 ]
3637 return middleware
3738
@@ -60,29 +61,6 @@ async def root():
6061async def favicon ():
6162 return {}
6263
63-
64- @app .middleware ("http" )
65- async def add_process_time_header (request : Request , call_next ):
66- start_time = time .time ()
67- response = await call_next (request )
68- process_time = time .time () - start_time
69-
70- query_params_list = [
71- (key , value if key != "token" else "***" )
72- for key , value in request .query_params .items ()
73- ]
74-
75- url_path = request .url .path
76- logger .debug (
77- {
78- "url" : url_path ,
79- "params" : query_params_list ,
80- "process_time" : f"{ process_time :.4f} " ,
81- }
82- )
83- return response
84-
85-
8664@app .exception_handler (RequestValidationError )
8765async def validation_exception_handler (request : Request , exc : RequestValidationError ):
8866 error = json .loads (exc .json ())
@@ -95,12 +73,4 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
9573 "error" : error ,
9674 }
9775 )
98- return JSONResponse (content = {"detail" : error }, status_code = 422 )
99-
100-
101- # @app.on_event("startup")
102- # async def startup_event():
103- # if config.env != "DEV":
104- # logger.info("startup initiated")
105- # highscore_processor = HighscoreProcessor(batch_size=100)
106- # asyncio.ensure_future(highscore_processor.start())
76+ return JSONResponse (content = {"detail" : error }, status_code = 422 )
0 commit comments