Is there a way not to log body if it's binary data? #2968
Unanswered
vkuznetsovgn
asked this question in
Q&A
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone.
I am using a simple
LoggingMiddlewareConfig
to log requests and responses. Sometimes I have files in requests or responses and I don't want to log the body that consists of binary array. Can I maybe say somehow not to log files or maybe at least set up a size limit for the body to log?Beta Was this translation helpful? Give feedback.
All reactions