#How to reduce logging of Stream responses when using the logging middleware?

1 messages · Page 1 of 1 (latest)

runic flare
#

My route handler returns a litestar.response.Stream and I'm using the structlog plugin. I'm getting a lot of log messages, presumably due to send being called in a loop here: https://github.com/litestar-org/litestar/blob/8bcf051ab9f8ee65ff893e39417f370da007db11/litestar/response/streaming.py#L122-L128

{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930036Z"}
{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930118Z"}
{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930190Z"}
{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930271Z"}
{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930349Z"}
{"status_code":201,"event":"HTTP Response","level":"info","timestamp":"2025-03-29T00:09:20.930464Z"}

Is there a straightforward way to log only once, similar to the behavior of File respones?

GitHub

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs - litestar-org/litestar

normal rootBOT
#
Notes for Hot to reduce logging of Stream responses when using the logging middleware?
At your assistance

@runic flare

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.