【问题标题】:How to flush Flask appication log output using Gunicorn on Python 2.7如何在 Python 2.7 上使用 Gunicorn 刷新 Flask 应用程序日志输出
【发布时间】:2026-01-15 01:10:02
【问题描述】:

我想刷新我的 Flask 应用程序的日志,因为它由 Gunicorn 和 Supervisord 运行。我找到了几个选项 here 用于 supervisord 和 there 专门用于 Gunicorn。

Gunicorn 的那些仅适用于 Python 3,是否有适用于 Python 2 的东西?特别是,当 Gunicorn 执行我的应用程序时,有没有办法将 -u 选项传递给 Python?

【问题讨论】:

  • 使用过python 2吗?
  • 好吧,如果没有人知道我将不得不使用 python 3... 但也许有一种简单的方法可以在执行 Gunicorn 时传递 -u 标志
  • 如果它是新开发的而不是现有的遗留代码库,那么确实没有充分的理由不使用 python3。 Python2 将于 2020 年 1 月 1 日正式结束生命周期且不受支持。
  • 至于你的问题,我认为还需要更多信息。您是否在 Flask 应用程序中使用 print() 语句,并且输出没有出现在您期望的位置?您是否在应用程序中配置任何日志处理程序?您将日志数据发送到哪里,您希望它出现在哪里?您是在独立系统上运行它,还是在 Docker 容器中运行它?
  • 好问题!

标签: python gunicorn supervisord


【解决方案1】:

我从 print() 切换到 app.logger.info() 并使用https://medium.com/@trstringer/logging-flask-and-gunicorn-the-manageable-way-2e6f0b8beb2f 中描述的方法来获取要由 supervisord 存储的日志。

【讨论】:

    最近更新 更多