Is there a way to log python print statements in gunicorn?

kontur picture kontur · Dec 29, 2014 · Viewed 31.3k times · Source

With my Procfile like this:

web: gunicorn app:app \
    --bind "$HOST:$PORT" \
    --debug --error-logfile "-" \
    --enable-stdio-inheritance \
    --reload \
    --log-level "debug" 

is it in any way possible to get python print statements to be logged to stdout / bash? I am using the bottle framework here as well, if that affects anything.

Answer

suvtfopw picture suvtfopw · Nov 23, 2018

In python 3, adding flush=True in each print statement works for my flask/gunicorn app.

E.g.

gunicorn --bind 0.0.0.0:8080 server --log-level debug

No particular flags are required.

See if this helps.