Gunicorn没有采摘stderr

时间:2014-06-26 00:37:58

标签: python flask gunicorn

我有一个带有以下路线的Flask应用程序:

@app.route('/')
def index():
    console = logging.StreamHandler()
    log = logging.getLogger("asdasd")
    log.addHandler(console)
    log.setLevel(logging.DEBUG)

    log.error("Something")
    print >> sys.stderr, "Another thing"
    return 'ok'

我使用

运行
python gunicorn --access-logfile /mnt/log/test.log --error-logfile /mnt/log/test.log --bind 0.0.0.0:8080 --workers 2 --worker-class gevent --log-level debug server:app

日志如下:

2014-06-26 00:13:55 [21621] [INFO] Using worker: gevent
2014-06-26 00:13:55 [21626] [INFO] Booting worker with pid: 21626
2014-06-26 00:13:55 [21627] [INFO] Booting worker with pid: 21627
2014-06-26 00:14:05 [21626] [DEBUG] GET /
10.224.67.41 - - [26/Jun/2014:00:14:14 +0000] "GET / HTTP/1.1" 200 525 "-" "python-requests/2.2.1 CPython/2.7.5 Darwin/13.2.0"
2014-06-26 00:14:14 [21626] [DEBUG] Closing connection. 

我的日志索引方法发生了什么?

1 个答案:

答案 0 :(得分:5)

截至Gunicorn 19.0,gunicorn已停止将stderr重定向到其原木。

请参阅https://github.com/benoitc/gunicorn/commit/41523188bc05fcbba840ba2e18ff67cd9df638e9