我的日志配置文件
[loggers]
keys=root, logstash
[handlers]
keys=console , logstash
[formatters]
keys=generic, access
[logger_root]
level=INFO
handlers=console
[logger_logstash]
level=DEBUG
handlers=logstash
propagate=1
qualname=logstash
[handler_console]
class=StreamHandler
formatter=generic
args=(sys.stdout, )
[handler_logstash]
class=logstash.TCPLogstashHandler
formatter=generic
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
我的执行命令
gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi --log-level debug --log-file=- --log-config gunicorn_log.conf
我没有收到任何错误,但logstash没有收到访问日志。 这个处理程序与DJango和芹菜合作,但我对gunicorn无能为力
答案 0 :(得分:0)
基于python-logstash documentation:
[handler_logstash]
class=logstash.TCPLogstashHandler
formatter=generic
host=localhost
port=5959
version=1
答案 1 :(得分:0)
[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