【问题标题】:Redirect Flask Stadout to Guinicorn log file将 Flask 标准输出重定向到 Gunicorn 日志文件
【发布时间】:2018-12-03 16:33:41
【问题描述】:

有人可以告诉我如何将flask standout 发送到guinicorn 原木。

以下是我的代码

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

Gunicorn 命令

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.logstdout

[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

【问题讨论】:

    标签: python python-2.7 flask gunicorn


    【解决方案1】:

    app.logger.info(&lt;expr&gt;)代替print

    【讨论】:

    • 我知道如何重定向日志。我也可以重定向stdout。唯一的问题是,它只有在我关闭应用程序后才会被附加。
    猜你喜欢
    • 2018-01-09
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 2016-10-07
    相关资源
    最近更新 更多