Is there a way not to log body if it's binary data? #2968
Answered
by
peterschutt
vkuznetsovgn
asked this question in
Q&A
-
Hi everyone. I am using a simple |
Beta Was this translation helpful? Give feedback.
Answered by
peterschutt
Apr 30, 2024
Replies: 1 comment
-
This is not tested, but should work - subclass from typing import Any
from litestar.middleware import LoggingMiddleware, LoggingMiddlewareConfig
from litestar.types import Scope
class MyLoggingMiddleware(LoggingMiddleware):
def should_remove_body(body: Any) -> bool:
# custom logic here
def extract_response_data(scope: Scope) -> dict[str, Any]:
data = super().response_data(scope)
if not self.should_remove_body(data.get("body", None)):
del data["body"]
return data
config = LoggingMiddlewareConfig(..., middleware_class=MyLoggingMiddleware) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vkuznetsovgn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not tested, but should work - subclass
LoggingMiddleware
and inspect/manipulate the data to be logged from there, e.g.: