We could include more info about the route, path parameters, query parameters, etc like we recently added to the maap-eoapi deployment in MAAP-Project/maap-eoapi#49
|
class LoggerMiddleware: |
|
"""MiddleWare to add logging.""" |
|
|
|
def __init__( |
|
self, |
|
app: ASGIApp, |
|
querystrings: bool = False, |
|
headers: bool = False, |
|
) -> None: |
|
"""Init Middleware. |
|
|
|
Args: |
|
app (ASGIApp): starlette/FastAPI application. |
|
|
|
""" |
|
self.app = app |
|
self.querystrings = querystrings |
|
self.headers = headers |
|
self.logger = logger |
|
logger.setLevel(logging.DEBUG) |
|
|
|
async def __call__(self, scope: Scope, receive: Receive, send: Send): |
|
"""Handle call.""" |
|
if scope["type"] == "http": |
|
request = Request(scope) |
|
|
|
self.logger.debug(str(request.url)) |
|
|
|
qs = dict(request.query_params) |
|
if qs and self.querystrings: |
|
self.logger.debug(qs) |
|
|
|
if self.headers: |
|
self.logger.debug(dict(request.headers)) |
|
|
|
await self.app(scope, receive, send) |
We could include more info about the route, path parameters, query parameters, etc like we recently added to the maap-eoapi deployment in MAAP-Project/maap-eoapi#49
titiler/src/titiler/core/titiler/core/middleware.py
Lines 100 to 135 in 6d1519e