【问题标题】:'gunicorn --paster' log messages not shown未显示“gunicorn --paster”日志消息
【发布时间】:2014-02-21 07:18:00
【问题描述】:

我正在使用 --paster 选项启动 gunicorn 以运行 Pyramid。

gunicorn -w 1 --paster development.ini

gunicorn 自己的消息可以在控制台上正常显示,例如

2014-02-20 22:38:50 [44201] [INFO] Starting gunicorn 18.0
2014-02-20 22:38:50 [44201] [INFO] Listening at: http://0.0.0.0:6543 (44201)
2014-02-20 22:38:50 [44201] [INFO] Using worker: sync

但是我的 Pyramid 应用程序中的日志消息没有显示出来。

如果我使用pserve development.ini,它使用waitress 作为 WSGI 服务器,那么日志消息就会很好地显示在控制台上。

我的development.ini 包含一个非常普通的日志记录配置部分。

[loggers]
keys = root, apipython

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_apipython]
level = DEBUG
handlers =
qualname = apipython

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = DEBUG
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

我不知道为什么我使用 gunicorn 时没有显示日志。

【问题讨论】:

  • 我尝试了另一种方式,使用 pserve development.ini 并将 [server:main] 更改为 use = egg:gunicorn#main - 这有效。 pserve 使用 gunicorn,并且日志正确显示。

标签: pyramid pylons gunicorn paster


【解决方案1】:

不要将 pserve 与 gunicorn 一起使用,它已被弃用,很可能会在下一个版本中被删除。

Gunicorn 有 "logconfig" setting,只需通过命令行参数将其设置为您的配置:

gunicorn -w 1 --paster development.ini --log-config development.ini

或在相同的配置中:

[server:main]
use = egg:gunicorn#main
logconfig = %(here)s/development.ini

【讨论】:

  • 仍然对我不起作用。我什至尝试设置 pyramid_exclog 但这也不起作用...
  • @julkiewicz 你是如何启动它的?最新的 gunicorn 版本不再需要 --log-config 并使用与 --paster 提供的相同配置。要么你的 gunicorn 太老了,要么你的日志配置应该有一些错误
【解决方案2】:

这是因为“pserve”命令不仅会启动服务器并加载应用程序,还会设置日志记录。而“gunicorn --paster”只是加载应用程序。要修复它,您可以在您的应用程序上显式设置日志记录:

from pyramid.config import Configurator
from pyramid.paster import setup_logging

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application. """
    setup_logging(global_config['__file__'])
    config = Configurator(settings=settings)
    # Configure application 
    return config.make_wsgi_app()

或者正如您在评论中指出的那样,在配置文件中更改服务器并使用“pserve”命令:

[server:main]
use = egg:gunicorn#main 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 2022-01-16
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多