有没有办法在gunicorn中记录python打印语句?
我的proc文件如下:有没有办法在gunicorn中记录python打印语句?,python,debugging,logging,bottle,gunicorn,Python,Debugging,Logging,Bottle,Gunicorn,我的proc文件如下: web: gunicorn app:app \ --bind "$HOST:$PORT" \ --debug --error-logfile "-" \ --enable-stdio-inheritance \ --reload \ --log-level "debug" PYTHONUNBUFFERED=TRUE 是否有可能将pythonprint语句记录到stdout/bash?我在这里也使用了瓶子框架,如果这有什么影响的
web: gunicorn app:app \
--bind "$HOST:$PORT" \
--debug --error-logfile "-" \
--enable-stdio-inheritance \
--reload \
--log-level "debug"
PYTHONUNBUFFERED=TRUE
是否有可能将python
print
语句记录到stdout/bash?我在这里也使用了瓶子
框架,如果这有什么影响的话。结果是打印
语句实际上已经通过了,但是延迟了
设置PYTHONUNBUFFERED
的注释,我以为我有,但似乎语法错误
我使用.env
文件和我的工头设置解决了这个问题,设置变量如下:
web: gunicorn app:app \
--bind "$HOST:$PORT" \
--debug --error-logfile "-" \
--enable-stdio-inheritance \
--reload \
--log-level "debug"
PYTHONUNBUFFERED=TRUE
请尝试以下命令:
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
它确实对我有用
请指定log level
到debug
(默认info
)
另外,指定capture output
标志(默认为false)
您应该能够查看错误日志文件中的日志。在Python3中,在每个打印语句中添加flush=True
适用于my flask/gunicorn应用程序
例如
不需要特定的标志
看看这是否有用。我把蟒蛇3和烧瓶一起使用
我直接使用print('log info')
,而不是print('log info',flush=True)
我只将capture\u output
设置为True
,并设置一个errorlog
文件,它就工作了
注:
捕获输出
--捕获输出
False
将stdout/stderr重定向到错误日志中的指定文件
我认为您需要指定一个errorlog文件来获得标准输出
这是我的配置文件gunicorn.config.py
设置
accesslog = 'gunicorn.log'
errorlog = 'gunicorn.error.log'
capture_output = True
然后使用gunicorn app\u py:myapp-c gunicorn.config.py运行
等价命令行是
gunicorn应用程序\u py:myapp——错误日志文件gunicorn.error.log——访问日志文件gunicorn.log——捕获输出
即使这是官方的方式——由于未知原因(python 2.7)它不工作调试标志不适用于gunicorn。如果您尝试运行它,它实际上会失败:gunicorn:error:无法识别的参数:--debug
似乎不方便更改应用程序代码来解决此问题。