如何定义settings.LOGGING以便gunicorn能够找到它想要的版本值?

时间:2013-04-14 22:44:17

标签: python django gunicorn

我正在尝试运行Gunicorn,我遇到了一个错误(粘贴在下面)。目前看起来像Gunicorn或其中一个依赖项试图读取settings.LOGGING,而settings.py文件似乎没有定义settings.LOGGING。

所以我想知道我可以添加什么样的文字或其他代码,以便Gunicorn +依赖项具有他们认为需要的内容。

代码粘贴:

(socialenv)jonathan@li393-189:~/directory$ python manage.py run_gunicorn 0.0.0.
0:8000
2013-04-14 17:40:13 [26464] [INFO] Starting gunicorn 0.17.2
2013-04-14 17:40:13 [26464] [INFO] Listening at: http://0.0.0.0:8000 (26464)
2013-04-14 17:40:13 [26464] [INFO] Using worker: sync
2013-04-14 17:40:13 [26469] [INFO] Booting worker with pid: 26469
2013-04-14 17:40:13 [26469] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
    reload_django_settings()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
    logging_config_func(settings.LOGGING)
  File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 503, in configure
    raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
Traceback (most recent call last):
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
    reload_django_settings()
  File "/home/jonathan/socialenv/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
    logging_config_func(settings.LOGGING)
  File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 503, in configure
    raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
2013-04-14 17:40:13 [26469] [INFO] Worker exiting (pid: 26469)
2013-04-14 17:40:13 [26464] [INFO] Shutting down: Master
2013-04-14 17:40:13 [26464] [INFO] Reason: Worker failed to boot.
(socialenv)jonathan@li393-189:~/directory$ 

3 个答案:

答案 0 :(得分:15)

我遇到了同样的错误,我通过将日志配置添加到项目的设置文件来修复它,我使用了此页面中的示例

https://docs.djangoproject.com/en/dev/topics/logging/

这是我的设置文件中的代码

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console':{
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'filters': [],
        }
    },
    'loggers': {
        'django': {
            'handlers': ['null'],
            'propagate': True,
            'level': 'INFO',
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    }
}

答案 1 :(得分:11)

最简单的方法是在settings.py中添加:

LOGGING = {
    'version': 1,
}

答案 2 :(得分:1)

错误消息表示为日志记录配置传递的配置字典缺少架构版本。你需要显示你的字典才能确定,但​​这肯定是你所得到的错误所指的。有关详细信息,请参阅the docs