# Multiline parser

**URL:** <https://discuss.elastic.co/t/multiline-parser/277124>\
**Category:** Logstash\
**Created:** [June 26, 2021, 3:18pm UTC](https://discuss.elastic.co/t/multiline-parser/277124 "2021-06-26T15:18:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bz\_Os](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bz_os/32/90863_2.png) [@bz\_Os](https://discuss.elastic.co/u/bz_Os)\
**Post date:** [June 26, 2021, 3:18pm UTC](https://discuss.elastic.co/t/multiline-parser/277124/1 "2021-06-26T15:18:21Z")

</div>

Hello,

I am glad to joint the elastic stack community, to pars SQL logs I need to put together rows into one:

> juin 26 13:30:05 sqlpc mysql-slow: SELECT fk.pib, fk.id, fk.idAccount, fk.idVad, fk.somevalue, fk.somevalue, fk.somevalue AS date, fk.somevalue, "no" AS somevalue  
> juin 26 13:30:05 sqlpc mysql-slow: FROM fk
> 
> juin 26 13:30:05 sqlpc mysql-slow: LEFT JOIN fkifhkj AS tfcd ON tfcd.lf = fk.id
> 
> juin 26 13:30:05 sqlpc mysql-slow: INNER JOIN somevalue ON somevalue = fk.id
> 
> juin 26 13:30:05 sqlpc mysql-slow: LEFT JOIN somevalue ON fk.id = somevalue
> 
> juin 26 13:30:05 sqlpc mysql-slow: LEFT JOIN somevalue on fk.id = somevalue
> 
> juin 26 13:30:05 sqlpc mysql-slow: WHERE (somevalue IS NULL) AND (somevalue = 'somevalue') AND (somevalue BETWEEN 'somevalue' AND 'somevalue') AND ((somevalue = 'somevalue'))

And also :

> juin 26 01:06:35 pc-str END {  
> juin 26 01:06:35 pc-str print "processes.value " 0+processes;  
> juin 26 01:06:35 pc-str print "uninterruptible.value " 0+stat["D"];  
> juin 26 01:06:35 pc-str print "runnable.value " 0+stat["R"];  
> juin 26 01:06:35 pc-str print "sleeping.value " 0+stat["S"];  
> juin 26 01:06:35 pc-str print "idle.value " 0+stat["I"];  
> juin 26 01:06:35 pc-str print "stopped.value " 0+stat["T"];  
> juin 26 01:06:35 pc-str print "paging.value " 0+stat["W"];  
> juin 26 01:06:35 pc-str print "dead.value " 0+stat["X"];  
> juin 26 01:06:35 pc-str print "zombie.value " 0+stat["Z"];  
> juin 26 01:06:35 pc-str }  
> Can you help me to do this.

Best regards,

---

<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:** [June 26, 2021, 6:31pm UTC](https://discuss.elastic.co/t/multiline-parser/277124/2 "2021-06-26T18:31:20Z")

</div>

You can combine lines using a multiline codec, but that requires a regular expression that the codec can use to know when a multiline group starts or ends.

You can combine lines with an aggregate filter, but that requires a field (a task\_id) that indicates which lines should be grouped together.

You can combine lines with a ruby filter. You can write arbitrarily complex code in a ruby filter that maintains state across lines. The second example would not be very hard -- if you see `END {` then collect lines together until you see `}`. The first example is going to be much harder. Your code will need to know a lot about SQL syntax, and what can and cannot be part of a statement.

---

<div class="post-metadata">

**Author:** ![bz\_Os](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bz_os/32/90863_2.png) [@bz\_Os](https://discuss.elastic.co/u/bz_Os)\
**Post date:** [June 27, 2021, 12:29pm UTC](https://discuss.elastic.co/t/multiline-parser/277124/3 "2021-06-27T12:29:46Z")

</div>

Hello badger, thanks for the replay, I have another question, I am usoing a single syslog input for all source logs which directs the logs to the pipline concerned based on the IP address of the host. do you have any idea how i can apply multiline only for mysql-slow logs

---

<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:** [July 25, 2021, 12:29pm UTC](https://discuss.elastic.co/t/multiline-parser/277124/4 "2021-07-25T12:29:54Z")

</div>

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