Get count of lines in a multiline message field

Hi Team,

I have a message field with multiline i.e
Exception in thread "main" java.lang.IllegalStateException: A book has a null property\n\tat com.example.myproject.Author.getBookIds(Author.java:38)
\n\tat com.example.myproject.Bootstrap.main(Bootstrap.java:14)\nCaused by: java.lang.NullPointerException\n\tat com.example.myproject.Book.getId(Book.java:22)\n\tat com.example.myproject.Author.getBookIds(Author.java:35)

In this message there are 6 lines

I used following ruby code in logstash filter

ruby {
code => 'event.set("numLines", 1 + event.get("message").count("\n"))'
}

This giving count as '1' not the actual number of lines.

Please, Can anyone help me!

See here. You want to count the number of newlines, not the number of occurences of the string backslash-n.

Hi @Badger ,

How can get count of number of newlines, Please give some input .

ruby {
code => 'event.set("numLines", 1 +event.get("message").count(" "))'
}

I tried the above code, with this code I am getting count spaces in a message , not lines.

ruby {
code => 'event.set("numLines", 1 +event.get("message").count("
"))'
}

Tried this one, it gives 1 as output value.

Thanks in advance.

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