# How to send logs to filebeat with python logging

**URL:** <https://discuss.elastic.co/t/how-to-send-logs-to-filebeat-with-python-logging/85187>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [May 10, 2017, 4:29am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-filebeat-with-python-logging/85187 "2017-05-10T04:29:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wang](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@Tony\_Wang](https://discuss.elastic.co/u/Tony_Wang)\
**Post date:** [May 10, 2017, 4:29am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-filebeat-with-python-logging/85187/1 "2017-05-10T04:29:05Z")

</div>

The code I used shows below. I want to send logs with python. But What I got from Kibana is :

`elk_1 | {"type":"log","@timestamp":"2017-05-10T04:23:51Z","tags":["connection","client","error"],"pid":194,"level":"error","message":"Parse Error","error":{"message":"Parse Error","name":"Error","stack":"Error: Parse Error\n at Error (native)","code":"HPE_INVALID_METHOD"}}`

The images I used is here :[https://github.com/spujadas/elk-docker/tree/master/nginx-filebeat](https://github.com/spujadas/elk-docker/tree/master/nginx-filebeat)

Is there any better solution for python? Thanks!

[test.py](http://test.py)  
import logger

```
logger = logger.configure()

logger.info('hello world')

```

#[logger.py](http://logger.py)  
import logging  
import logstash  
import logging.handlers

```
def configure():
    host = '10.211.55.12'
    logging.basicConfig(level=logging.DEBUG,
                        format="%(asctime)s - %(module)s - line %(lineno)d - process-id %(process)d - (%(threadName)-5s)- %(levelname)s - %(message)s")
    # fileConfig(log_file_path)
    logger = logging.getLogger( __name__ )
    logger.addHandler(logstash.TCPLogstashHandler(host, 5601, version=1))
    return logger
```

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [May 10, 2017, 11:32am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-filebeat-with-python-logging/85187/2 "2017-05-10T11:32:00Z")

</div>

One doesn't send logs to Filebeat. Filebeat ships logs from files. One just logs to a file (don't forget about logrotation in logger or via logrotate) and filebeat picks it up. When logging e.g. python stack-traces, you might want to configure multiline in filebeat.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 7, 2017, 11:40am UTC](https://discuss.elastic.co/t/how-to-send-logs-to-filebeat-with-python-logging/85187/3 "2017-06-07T11:40:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
