【问题标题】:Gunicorn giving syntax error for my configuration fileGunicorn 为我的配置文件提供语法错误
【发布时间】:2017-01-05 01:27:45
【问题描述】:

我的配置文件

[loggers]
keys=root, gunicorn.error, gunicorn.access

[handlers]
keys=console, error_file, access_file

[formatters]
keys=generic, access

[logger_root]
level=INFO
handlers=console

[logger_gunicorn.error]
level=INFO
handlers=error_file
propagate=1
qualname=gunicorn.error

[logger_gunicorn.access]
level=INFO
handlers=access_file
propagate=0
qualname=gunicorn.access

[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )

[handler_error_file]
class=logging.FileHandler
formatter=generic
args=('/tmp/gunicorn.error.log',)

[handler_access_file]
class=logging.FileHandler
formatter=access
args=('/tmp/gunicorn.access.log',)

[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter

[formatter_access]
format=%(message)s
class=logging.Formatter

我要执行的命令

gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi --log-level debug --log-file=- -c file:gunicorn_log.conf

收到此错误

Failed to read config file: gunicorn_log.conf
Traceback (most recent call last):
  File "/home/jameel/django-env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 93, in get_config_from_filename
    execfile_(filename, cfg, cfg)
  File "/home/jameel/django-env/local/lib/python2.7/site-packages/gunicorn/_compat.py", line 91, in execfile_
    return execfile(fname, *args)
  File "gunicorn_log.conf", line 27
    class=StreamHandler
         ^
SyntaxError: invalid syntax

按照他们在 github link 中的示例跟踪我

【问题讨论】:

  • 这是记录器配置文件,不是 gunicorn

标签: python django logging celery gunicorn


【解决方案1】:

Gunicorn 配置文件如下所示:https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py

您的文件是一个记录器配置文件。

Logger 配置通过--log-config 参数传递。

【讨论】:

  • 感谢您的回复。但那是python配置文件。我需要如上所述的普通配置文件来定义额外的处理程序
  • 是否有任何其他语法可以在命令行中提供日志配置文件
  • 是的,明白了。我需要给出“--log-config”而不是“-c”谢谢你告诉我,因为有 2 种不同类型的配置文件
【解决方案2】:
[loggers]
keys=root, logstash.error, logstash.access

[handlers]
keys=console , logstash

[formatters]
keys=generic, access, json

[logger_root]
level=INFO
handlers=console

[logger_logstash.error]
level=DEBUG
handlers=logstash
propagate=1
qualname=gunicorn.error

[logger_logstash.access]
level=DEBUG
handlers=logstash
propagate=0
qualname=gunicorn.access


[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )

[handler_logstash]
class=logstash.TCPLogstashHandler
formatter=json
args=('localhost',5959)


[formatter_generic]
format=%(asctime)s [%(process)d] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter

[formatter_access]
format=%(message)s
class=logging.Formatter

[formatter_json]
class=jsonlogging.JSONFormatter

上面的配置文件对我有用 将日志发送到在 localhost:5959 下运行的 logstash

【讨论】:

    猜你喜欢
    • 2011-12-16
    • 2021-01-31
    • 2013-11-24
    • 1970-01-01
    • 2012-12-06
    • 2014-10-25
    • 2013-02-06
    • 2019-08-27
    • 2022-01-12
    相关资源
    最近更新 更多