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.
Please try below command:
It did work for me.
Please specify
log-level
todebug
(defaultinfo
)http://docs.gunicorn.org/en/stable/settings.html#loglevel,Also, specify
capture-output
flag (default false)http://docs.gunicorn.org/en/stable/settings.html#capture-output.You should be able to watch logs in error log file.
I use Python3 along with Flask.
I use
print('log info')
directly instead ofprint('log info', flush=True)
.I only set
capture_output
toTrue
and set aerrorlog
file and it works.Note that:
I think it's that you need to specifiy a errorlog file to get the standard output.
Here's my config file
gunicorn.config.py
settingThen run with
gunicorn app_py:myapp -c gunicorn.config.py
The equivaluent command line would be
gunicorn app_py:myapp --error-logfile gunicorn.error.log --access-logfile gunicorn.log --capture-output
It turns out the
print
statements were actually getting through, but with delay.The gunicorn docs for --enable-stdio-inheritance note to set the
PYTHONUNBUFFERED
, which I thought I had, but it seems with wrong syntax.I solved it using a
.env
file with myforeman
setup to set the variable like this:In python 3, adding
flush=True
in each print statement works for my flask/gunicorn app.E.g.
No particular flags are required.
See if this helps.