# Grok pattern issue

**URL:** <https://discuss.elastic.co/t/grok-pattern-issue/284247>\
**Category:** Logs\
**Created:** [September 15, 2021, 5:57am UTC](https://discuss.elastic.co/t/grok-pattern-issue/284247 "2021-09-15T05:57:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya\_Bansal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bansal/32/81564_2.png) [@Divya\_Bansal](https://discuss.elastic.co/u/Divya_Bansal)\
**Post date:** [September 15, 2021, 5:57am UTC](https://discuss.elastic.co/t/grok-pattern-issue/284247/1 "2021-09-15T05:57:34Z")

</div>

I have two logs: one with loglevel field and one without it as mentioned below. can anyone help me with thescript processing both type of logs from single pattern.  
the sample logs are:-  
2021-09-13T23:58:22.676 [_**] localhost - [**_] :: getFormName:: Formname received is _ **-** _  
[DEBUG] 2021-09-13T23:58:22.676 [_**] localhost - [**_] :: getFormName:: Formname received is _ **-** _

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [October 4, 2021, 3:24pm UTC](https://discuss.elastic.co/t/grok-pattern-issue/284247/2 "2021-10-04T15:24:51Z")

</div>

Hi @Divya_Bansal,

since grok is just syntactic sugar on top of regular expressions, a normal non-capturing group with a `?` quantifier should work, as in

```auto
(?:\[%{LOGLEVEL:loglevel}\] )?%{TIMESTAMP_ISO8601:@timestamp} ...

```

---

<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:** [November 1, 2021, 3:25pm UTC](https://discuss.elastic.co/t/grok-pattern-issue/284247/3 "2021-11-01T15:25:25Z")

</div>

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