Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing python log files to logstash

I am currently using the ELK stack as provided by Docker here:

https://github.com/deviantony/docker-elk

To log in my python program, I am utilising the python-logstash library:

https://github.com/vklochan/python-logstash

I am trying to write log to logstash (and view the subsequent data in Kibana) using the example at the python-logstash github page:

LOGGER = logging.getLogger('python-logstash-logger')
LOGGER.setLevel(logging.INFO)
LOGGER.addHandler(logstash.LogstashHandler(127.0.0.1, 5000, version=1))
LOGGER.error('python-logstash: test logstash error message.')

However, this is not writing any data to ElasticSearch, as verified via:

http://127.0.0.1:9200/_search?pretty=true

There are also no error or debug messages returned by the python-logstash library.

Can anybody point out what I am doing incorrectly?

My logstash.conf contains the following:

input {
tcp {
        port => 5000
        codec => json
    }
}

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        codec => rubydebug
    }
}
like image 812
fjir01d Avatar asked Aug 09 '16 18:08

fjir01d


1 Answers

Use

LOGGER.addHandler(logstash.TCPLogstashHandler(127.0.0.1, 5000, version=1))
like image 90
ippogrifo Avatar answered Oct 02 '22 10:10

ippogrifo