我的配置文件
[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链接中按照他们的示例进行了跟踪
Gunicorn配置文件如下所示:https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py
您的文件是记录器配置文件。
记录器配置由--log config参数传递。
[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:55959 下运行的logstash