将Flask Stadout重定向到Guinicorn日志文件

时间:2018-12-03 16:33:42

标签: python python-2.7 flask gunicorn

请让我知道如何将烧瓶中的佼佼者发送到guinicorn原木。

以下是我的代码

@app.route("/")
def home():
    print "print statement"
    return "<h1>hello World</h1>"

独角兽命令

gunicorn test:app -b 0.0.0.0:5005 --access-logfile ./access.log --error-logfile error.log --log-file gunicorn.log --capture-output -R --reload

但是,只有在关闭应用程序后,我才能在 gunicorn.log stdout

[2018-12-03 11:27:39 -0500] [68235] [INFO] Starting gunicorn 19.9.0
[2018-12-03 11:27:39 -0500] [68235] [INFO] Listening at: http://0.0.0.0:5005 (68235)
[2018-12-03 11:27:39 -0500] [68235] [INFO] Using worker: sync
[2018-12-03 11:27:39 -0500] [68238] [INFO] Booting worker with pid: 68238
[2018-12-03 11:29:13 -0500] [68235] [INFO] Handling signal: int
[2018-12-03 11:29:14 -0500] [68238] [INFO] Worker exiting (pid: 68238)
print statement
print statement
print statement
[2018-12-03 11:29:14 -0500] [68235] [INFO] Shutting down: Master

1 个答案:

答案 0 :(得分:-1)

使用print代替app.logger.info(<expr>)