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

前端 未结 4 1225
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 18:58

With my Procfile like this:

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


        
4条回答
  •  一向
    一向 (楼主)
    2021-02-03 19:45

    I use Python3 along with Flask.

    I use print('log info') directly instead of print('log info', flush=True).

    I only set capture_output to True and set a errorlog file and it works.

    Note that:

    capture_output

    --capture-output
    False
    Redirect stdout/stderr to specified file in errorlog

    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 setting

    accesslog = 'gunicorn.log'
    errorlog = 'gunicorn.error.log'
    capture_output = True
    

    Then 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

提交回复
热议问题