Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在gunicorn中记录python打印语句?_Python_Debugging_Logging_Bottle_Gunicorn - Fatal编程技术网

有没有办法在gunicorn中记录python打印语句?

有没有办法在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?我在这里也使用了瓶子框架,如果这有什么影响的

我的proc文件如下:

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
似乎不方便更改应用程序代码来解决此问题。