# Help pattern for multiline logs

**URL:** <https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134>\
**Category:** Logstash\
**Created:** [April 17, 2023, 1:03pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134 "2023-04-17T13:03:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackieLaFrite](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JackieLaFrite](https://discuss.elastic.co/u/JackieLaFrite)\
**Post date:** [April 17, 2023, 1:03pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/1 "2023-04-17T13:03:10Z")

</div>

What pattern should I use to retrieve correctly multi-lines logs ?

Normally I use :

```auto
  file {
    path => "/var/log/appslogs/**/*.log"
    start_position => "beginning"
    sincedb_path => "/dev/null"
	codec => multiline {
	  pattern => "^\s"
	  what => "previous"
    }
    type => "app"
  }

```

Here is an exemple of logs (with and without error) :

```auto
2023-02-09 00:00:03 [DEBUG] org.apache.activemq.util.ThreadPoolUtils:54 -> Forcing shutdown of ExecutorService: java.util.concurrent.ThreadPoolExecutor@646bc5f[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 1] 2
2023-02-09 00:00:03 [ERROR] org.apache.camel.component.jms.DefaultJmsMessageListenerContainer:934 -> Could not refresh JMS Connection for destination 'EVENT-BUS-GET-ECHO-V1-eures-jv-batch-01' - retrying using FixedBackOff{interval=5000, currentAttempts=9124, maxAttempts=unlimited}. Cause: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://eures-jms:31314. Reason: java.net.UnknownHostException: eures-jms
javax.jms.JMSException: Error while attempting to add new Connection to the pool
	at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:279)
	at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:230)
	at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:209)
	at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
	at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:413)
	at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:398)
	at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:915)
	at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:890)
	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1061)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750) 3

```

But it's not working for this type of error.

Here is my grok pattern if you need it :

```auto
%{TIMESTAMP_ISO8601:time} \[%{LOGLEVEL:log_level}\] %{GREEDYDATA:message_of_log}

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 17, 2023, 1:19pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/2 "2023-04-17T13:19:53Z")

</div>

You should use the date as the multiline pattern, something like this:

`pattern => "^\d{4}-\d{2}-\d{2}"`

Every line that starts with a date will start the multiline, if a line does not start with a date it will e added to the previous multiline log.

---

<div class="post-metadata">

**Author:** ![JackieLaFrite](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JackieLaFrite](https://discuss.elastic.co/u/JackieLaFrite)\
**Post date:** [April 17, 2023, 2:22pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/3 "2023-04-17T14:22:32Z")

</div>

It's not working :  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/1/b1f8b4518916601ab01484847a57f7eeddf9c4d6.png)

You can see that multiple logs are retrieved as one 😕

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 17, 2023, 2:33pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/4 "2023-04-17T14:33:27Z")

</div>

Yeah, I thought you have the `negate` already in your multiline configuration.

You need to have `negate => true`.

Try this:

```auto
        codec => multiline {
            pattern => "^\d{4}-\d{2}-\d{2}"
            negate => true
            what => "previous"
        }

```

---

<div class="post-metadata">

**Author:** ![JackieLaFrite](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JackieLaFrite](https://discuss.elastic.co/u/JackieLaFrite)\
**Post date:** [April 17, 2023, 2:41pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/5 "2023-04-17T14:41:54Z")

</div>

Thanks, it work perfectly 😊

---

<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:** [May 15, 2023, 2:42pm UTC](https://discuss.elastic.co/t/help-pattern-for-multiline-logs/330134/6 "2023-05-15T14:42:35Z")

</div>

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