# Fixing Multiline Logs in Filebeat

**URL:** <https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299>\
**Category:** Beats\
**Tags:** docker, filebeat\
**Created:** [March 19, 2020, 6:51pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299 "2020-03-19T18:51:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin5617](https://avatars.discourse-cdn.com/v4/letter/k/46a35a/32.png) [@kevin5617](https://discuss.elastic.co/u/kevin5617)\
**Post date:** [March 19, 2020, 6:51pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299/1 "2020-03-19T18:51:19Z")

</div>

I know that filebeat has a multiline tool to handle multiline logs. However, the way my log structure is setup I do not think those solutions work exactly the same way. I am using the ELK stack with docker, and for filebeat, I am using the "autodiscover" tool to read docker logs.

When directing my filebeat output to a file, the logs are in the form of

```
`{"@timestamp":"2020-03-19T18:42:33.589Z",........."message":"INFO: stuff here"....}`

```

So I think filebeat will look to match a pattern for that entire log, not just the message field. So if I were to try to use multiline, would I have to do something like

```auto
    multiline.pattern: '^.*\"message\":\"<some_pattern_here>'
    multiline.negate: true
    multiline.match: after

```

Also, where would I put this inside the filebeat config. Would I put it one level under the autodiscover, like

```auto
    filebeat.autodiscover:
        multiline.pattern: '^.*\"message\":\"<some_pattern_here>'
        multiline.negate: true
        multiline.match: after
        providers:
        ....

```

I also don't just want to move the whole log that doesn't match the matter, I want to move the message field of that log and move it to the end of the message field of the previous log.

---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [March 23, 2020, 6:45pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299/2 "2020-03-23T18:45:41Z")

</div>

Perhaps I'm misunderstanding but it sounds like the multiline messages are encoded within the `message` field, right? If so, wouldn't there be `\n` characters in there already? If so, do you even need the `multiline.*` settings?

It might be helpful if you could copy-paste a small chunk (few lines) from your Docker logs. If it doesn't fit in here, feel free to use [https://gist.github.com/](https://gist.github.com/) or [https://pastebin.com/](https://pastebin.com/) and post the link here.

Shaunak

---

<div class="post-metadata">

**Author:** ![kevin5617](https://avatars.discourse-cdn.com/v4/letter/k/46a35a/32.png) [@kevin5617](https://discuss.elastic.co/u/kevin5617)\
**Post date:** [March 23, 2020, 8:03pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299/3 "2020-03-23T20:03:18Z")

</div>

So i'm not totally sure what the multiline plugin is "looking at" to use the pattern. I'm using the autodiscover tool to get docker logs. so if I look at the locations where the docker logs are from, and `cat` the `<docker_id>-json.log` file, the lines are in the form

```
{"log":"INFO: message here\n","stream":"stderr","time":"<timestamp>"}

```

and then for the "indented" lines which I want to attach to the previous message, they look like

```
{"log":"\u0009this should be part of the previous log\n","stream":"stderr","time":"<timestamp>"}

```

let me know if this answers your question

---

<div class="post-metadata">

**Author:** ![kevin5617](https://avatars.discourse-cdn.com/v4/letter/k/46a35a/32.png) [@kevin5617](https://discuss.elastic.co/u/kevin5617)\
**Post date:** [March 31, 2020, 9:09pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299/4 "2020-03-31T21:09:45Z")

</div>

I found the solution for my case. This is now my filebeat.yml file

```auto
filebeat.autodiscover:
        providers:
            - type: docker
                templates:
                    - config:
                        - type: container
                            paths:
                                - "/var/lib/docker/containers/${data.docker.container.id}/*.log"
                        multiline.pattern: "^\t"
                        multiline.negate: false
                        multiline.match: after
    logging.metrics.enabled: false
    output.logstash:
        hosts:
            - logstash:5044

```

I had the three multiline lines at the wrong "level". Originally they were right between the `- type: docker` and `templates:` lines.

---

<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:** [April 28, 2020, 9:09pm UTC](https://discuss.elastic.co/t/fixing-multiline-logs-in-filebeat/224299/5 "2020-04-28T21:09:46Z")

</div>

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