Gunicorn logstash log handler
<p>my log config file</p>

<pre><code>[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
</code></pre>

<p>my command to execute</p>

<pre><code>gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi --log-level debug --log-file=- --log-config gunicorn_log.conf
</code></pre>

<p>I am not getting any error but logstash is not receiving access logs.
This handler worked with DJango and celery but I am helpless with gunicorn</p>

<pre><code>[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
</code></pre>

<p>The above config file worked for me 
to send logs to logstash which is running under localhost:5959</p>

python django logging logstash gunicorn