# Grok pattern - sometimes nesting bracket

**URL:** https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797
**Category:** Logstash
**Created:** [September 6, 2022, 1:15pm UTC](https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797 "2022-09-06T13:15:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elkuser1234](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@elkuser1234](https://discuss.elastic.co/u/elkuser1234)
#### Post date: [September 6, 2022, 1:15pm UTC](https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797/1 "2022-09-06T13:15:03Z")

</div>

Hi

I have a difficult log for me.  
Because sometimes I have nested bracket and sometimes i don't

How to parse it in a grok.

```auto
[2022-09-05 17:27:24,537] [apps-thread | test-policy] WARN
[2022-09-06 14:19:25,708] [App (app-1) thread #1 - AppsConsumer[apps-notify]] INFO

```

```auto
        grok {

             match => ["message", "\[%{TIMESTAMP_ISO8601:timestamp}\] \[HOW TO HANDLE THIS:thread\] %{LOGLEVEL:log_level}" ]
             tag_on_failure => ["failed-to-parse"]

        }

```

Please help

---

<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: [September 6, 2022, 4:01pm UTC](https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797/2 "2022-09-06T16:01:33Z")

</div>

You could try

```
"^\[%{TIMESTAMP_ISO8601:timestamp}\] \[%{GREEDYDATA:someField}\] %{LOGLEVEL:log_level}$"

```

---

<div class="post-metadata">

### Author: ![elkuser1234](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@elkuser1234](https://discuss.elastic.co/u/elkuser1234)
#### Post date: [September 7, 2022, 6:34am UTC](https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797/3 "2022-09-07T06:34:08Z")

</div>

Thanks, I was convinced that the above proposal would give me:

```auto
{
   "log_level": "] INFO",
   "someField": "App (app-1) thread # 1 - AppsConsumer [apps-notify",
   "timestamp": "2022-09-06 14:19: 25,708"
}

```

because the grok will stop on the first squere bracket "]"

Today in the morning I understand that there is a squere bracket space log\_level, which is why it does not stop on the first bracket

---

<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: [October 5, 2022, 6:34am UTC](https://discuss.elastic.co/t/grok-pattern-sometimes-nesting-bracket/313797/4 "2022-10-05T06:34:45Z")

</div>

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