Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update logging middleware with more request details #1107

Open
hrodmn opened this issue Mar 24, 2025 · 0 comments
Open

update logging middleware with more request details #1107

hrodmn opened this issue Mar 24, 2025 · 0 comments

Comments

@hrodmn
Copy link
Contributor

hrodmn commented Mar 24, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant