Skip to content

Configuration and making it work in Python

Sandino edited this page Sep 2, 2014 · 2 revisions

The purpose of this page is to share how to make it work in python and posterior analysis in kibana. I wanted to share what worked for me, I made it work with dict config, this way I got every formatter in only one config file and so I can change it behaviour easily.

In your config file (say logging.cfg) add the logstash formatter like this:

"formatters": { "logstash":{ "()": "logstash_formatter.LogstashFormatter" } }

Then in python (for example in an init method of your logManager):

import json, logging from dictconfig import dictConfig from logstash_formatter import LogstashFormatter

config = json.load(open('path_to_your_config/logging.cfg', 'r')) dictConfig(config)

That's all you need to formatt output in json format, but if you want every field to be load and indexed into elasticsearch for better quering you must add a logstash filter in your logstash config file:

filter { json { source => "message" } }

Hope this help someone else when configuring things.

Clone this wiki locally