# Collect multiple line in stdin

**URL:** <https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647>\
**Category:** Logstash\
**Created:** [April 8, 2021, 10:25pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647 "2021-04-08T22:25:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elk\_newbie](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@elk\_newbie](https://discuss.elastic.co/u/elk_newbie)\
**Post date:** [April 8, 2021, 10:25pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/1 "2021-04-08T22:25:21Z")

</div>

Hi,

Is it possible to read multiple lines at once?  
The first line indicates the error. I would like to log the statement that causes the error.

```auto
    < 2021-04-07 10:19:18.883 CEST db dbuser App 37386 > ERROR: operator does not exist: date = character varying at character 340
    < 2021-04-07 10:19:18.883 CEST db dbuser App 37386 > HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
    < 2021-04-07 10:19:18.883 CEST db dbuser App 37386 > STATEMENT: select a.col1,a.col2 from TABLE a where ( col3= $1 AND col4= $2)

```

Thanks in advance for any 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:** [April 8, 2021, 10:39pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/2 "2021-04-08T22:39:04Z")

</div>

> [@elk\_newbie](#):
>
> Is it possible to read multiple lines at once?

Yes, you can do that using a [multiline codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html) if you can find an appropriate pattern.

---

<div class="post-metadata">

**Author:** ![elk\_newbie](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@elk\_newbie](https://discuss.elastic.co/u/elk_newbie)\
**Post date:** [April 8, 2021, 11:31pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/3 "2021-04-08T23:31:40Z")

</div>

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

---

<div class="post-metadata">

**Author:** ![elk\_newbie](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@elk\_newbie](https://discuss.elastic.co/u/elk_newbie)\
**Post date:** [April 8, 2021, 11:38pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/4 "2021-04-08T23:38:04Z")

</div>

The only way I see is to detect a line having a different PID.

Example;

```auto
< 2021-04-07 10:19:18.883 CEST db dbuser App 23676 > FATAL: ....

```

The timestamp isn't very reliable though, but the PID is. The first three lines have PID = 37386, it should stop as soon as it detects a different PID in the log line.

I have no idea how to build the pattern. I am not a regex fun. ☹

---

<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:** [April 8, 2021, 11:46pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/5 "2021-04-08T23:46:34Z")

</div>

In that case I would suggest using an aggregate filter with the PID as the task id. Look at example 3 in the documentation. In the code section you would do something like

```
code => '
    map["messages"] ||= []
    map["messages"] << event.get("message")
    # Plus whatever else you need
'
```

---

<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 6, 2021, 11:47pm UTC](https://discuss.elastic.co/t/collect-multiple-line-in-stdin/269647/6 "2021-05-06T23:47:26Z")

</div>

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