Logging stdout to gunicorn access log?

后端 未结 4 1065
萌比男神i
萌比男神i 2021-02-06 06:38

When I wrap my Flask application in gunicorn writing to stdout no longer seems to go anywhere (simple print statements don\'t appear). Is there someway to either ca

4条回答
  •  情书的邮戳
    2021-02-06 07:06

    The solution from John mee works, but it duplicates log entries in the stdout from gunicorn.

    I used this:

    import logging
    from flask import Flask
    
    app = Flask(__name__)
    
    if __name__ != '__main__':
        gunicorn_logger = logging.getLogger('gunicorn.error')
        app.logger.handlers = gunicorn_logger.handlers
        app.logger.setLevel(gunicorn_logger.level)
    

    and got I this from: https://medium.com/@trstringer/logging-flask-and-gunicorn-the-manageable-way-2e6f0b8beb2f

提交回复
热议问题