kon*_*tur 22 python debugging logging bottle gunicorn
使用我的Procfile如下:
web: gunicorn app:app \
--bind "$HOST:$PORT" \
--debug --error-logfile "-" \
--enable-stdio-inheritance \
--reload \
--log-level "debug"
Run Code Online (Sandbox Code Playgroud)
是否有可能将python print语句记录到stdout/bash?我bottle也在这里使用框架,如果这会影响任何东西.
kon*_*tur 20
事实证明,这些print陈述实际上是通过,但有延迟.
在为--enable-标准输入输出继承gunicorn文档音符设置PYTHONUNBUFFERED,我认为我有,但它有错误的语法似乎.
我使用.env我的foreman设置文件解决了它,设置变量如下:
PYTHONUNBUFFERED=TRUE
Run Code Online (Sandbox Code Playgroud)
jsn*_*ceo 14
在python 3中,添加flush=True每个打印语句对我的flask / gunicorn应用程序有效。
例如
gunicorn --bind 0.0.0.0:8080 server --log-level debug
Run Code Online (Sandbox Code Playgroud)
不需要特定的标志。
看看是否有帮助。
我将 Python3 与 Flask 一起使用。
我print('log info')直接使用而不是print('log info', flush=True).
我只设置capture_output到True并设置errorlog文件和它的作品。
需要注意的是:
捕获输出
--capture-output
False
将 stdout/stderr 重定向到错误日志中的指定文件
我认为您需要指定一个错误日志文件来获取标准输出。
这是我的配置文件gunicorn.config.py设置
accesslog = 'gunicorn.log'
errorlog = 'gunicorn.error.log'
capture_output = True
Run Code Online (Sandbox Code Playgroud)
然后运行 gunicorn app_py:myapp -c gunicorn.config.py
等效的命令行是
gunicorn app_py:myapp --error-logfile gunicorn.error.log --access-logfile gunicorn.log --capture-output
请尝试以下命令:
gunicorn --workers 3 --bind 127.0.0.1:5000 --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --capture-output --log-level debug
Run Code Online (Sandbox Code Playgroud)
它确实为我工作。
请指定log-level为debug(默认info)http://docs.gunicorn.org/en/stable/settings.html#loglevel,
另外,请指定capture-output标志(默认为false)http://docs.gunicorn.org/en/stable/settings.html#capture-output。
您应该能够查看错误日志文件中的日志。
| 归档时间: |
|
| 查看次数: |
15871 次 |
| 最近记录: |