generated from bomzheg/aiogram_template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ychebyshev
committed
Jan 11, 2024
1 parent
9562633
commit 2858be6
Showing
4 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import FastAPI | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
|
||
from shvatka.api.middlewares.log import LoggingMiddleware | ||
|
||
|
||
def setup(app: FastAPI) -> None: | ||
app.add_middleware(BaseHTTPMiddleware, dispatch=LoggingMiddleware()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import logging | ||
|
||
from fastapi import Request, Response | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LoggingMiddleware: | ||
async def __call__(self, request: Request, call_next) -> Response: | ||
logger.debug("got request. url: %s, headers: %s", request.url, request.headers) | ||
response = await call_next(request) | ||
logger.debug("response will be: status: %s, headers: %s", response.status_code, response.headers) | ||
return response |