# Grok a multi format log file - custom app

**URL:** <https://discuss.elastic.co/t/grok-a-multi-format-log-file-custom-app/171310>\
**Category:** Logstash\
**Created:** [March 7, 2019, 1:26pm UTC](https://discuss.elastic.co/t/grok-a-multi-format-log-file-custom-app/171310 "2019-03-07T13:26:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![octav\_a](https://avatars.discourse-cdn.com/v4/letter/o/bc8723/32.png) [@octav\_a](https://discuss.elastic.co/u/octav_a)\
**Post date:** [March 7, 2019, 1:26pm UTC](https://discuss.elastic.co/t/grok-a-multi-format-log-file-custom-app/171310/1 "2019-03-07T13:26:10Z")

</div>

Hi there,

So I have a custom application with a log file that have multiple type of lines, normal syslog and also json.

It looks like this:

```
 2019-03-07T11:29:52+0000 | 10.0.0.0 | [3rdParty] xxxxxxxxxxxx || INFO | REQUEST | PUT https://10.0.0.0/xxxx | HEADERS: Accept-Encoding: gzip, deflate
        M2M-Tracking-Token: xxxxxx
        Content-Length: 2
        Content-Type: application/json
        Host: 10.0.0.0
        User-Agent: Zend_Http_Client
        Connection: Keep-Alive
        M2M-Apikey: xxxxxxxx
        X-Forwarded-Server: 10.0.0.0
        X-Forwarded-Host: 10.0.0.0
        X-Forwarded-Proto: https
        X-Forwarded-For: 10.0.0.0

         BODY: []
2019-03-07T11:29:52+0000 | 10.0.0.0 | [3rdParty] xxxxxxxxxxxx | xxxxxxx | INFO | RESPONSE | 200 OK PUT https://10.0.0.0 | 32ms | HEADERS: Content-Type: application/json
        Content-Length: 473
        X-CSRF-Token: None
        X-Tracking-Token: xxxxxxx

         BODY: {
          "serviceSession": {
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "xxxxxx",
            "testID: xxxxxx",
          }
        }

```

So I configured filebeat to use multiline since I want to "merge" them by timestamp date, otherwise I will get a lot of lines inside message and it`s hard to grok when you have a log with hundred of lines.

```
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after 

```

Now I get in my full length under message so I can play with grok to extract some relevant data.

I have some questions:

1. Is there a way to mark that `BODY: {}` as json?
2. Is there a way to grok through this json part to extract `testID` field? a find function?
3. In the first part of the log I have a response time measured in milliseconds, can I extract that as a metric `%NUMBER` field?

Thanks for your time!

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 7, 2019, 4:02pm UTC](https://discuss.elastic.co/t/grok-a-multi-format-log-file-custom-app/171310/2 "2019-03-07T16:02:21Z")

</div>

Assuming it is valid JSON (which your example most certainly is not) then you could do that using

```
    grok { match => { "message" => " \| %{NUMBER:duration:int}ms \| %{DATA} BODY: %{GREEDYDATA:body}" } }
    json { source => "body" }
```

---

<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 4, 2019, 4:02pm UTC](https://discuss.elastic.co/t/grok-a-multi-format-log-file-custom-app/171310/3 "2019-04-04T16:02:22Z")

</div>

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