I've been noticing that there are times when my log statements or print statements are not visible in a python-based docker compose service's output until I close/restart the service. This is because Python buffers its stdout by default.
How I did it
Run services with PYTHONBUFFERED=1 env var, which is akin to python -u .... As described in the docs:
Force the stdout and stderr streams to be unbuffered. This option has no effect on the stdin stream.
With this enabled, logs and print statements are made immediately available in the docker compose output.
What I'm changing
I've been noticing that there are times when my log statements or print statements are not visible in a python-based docker compose service's output until I close/restart the service. This is because Python buffers its stdout by default.
How I did it
Run services with
PYTHONBUFFERED=1
env var, which is akin topython -u ...
. As described in the docs:With this enabled, logs and print statements are made immediately available in the docker compose output.