{"id":85,"date":"2015-03-30T04:01:35","date_gmt":"2015-03-30T04:01:35","guid":{"rendered":"http:\/\/svops.com\/blog\/?p=85"},"modified":"2015-03-30T04:02:16","modified_gmt":"2015-03-30T04:02:16","slug":"using-the-multiline-filter","status":"publish","type":"post","link":"http:\/\/svops.com\/blog\/using-the-multiline-filter\/","title":{"rendered":"Combining lines with the multiline{} filter"},"content":{"rendered":"<p>The multiline filter is designed to combine messages that span lines into a single event that can be easily processed with other logstash filters. \u00a0Systems that throw large exceptions (e.g. Java) are the standard use-case for this filter.<\/p>\n<p>At the most basic, you need to provide three pieces of information to the filter:<\/p>\n<ul>\n<li>&#8216;pattern&#8217;: the regular expression that signals the start of a new event.<\/li>\n<li>&#8216;what&#8217;: the action to take with a line that does or doesn&#8217;t match the pattern.<\/li>\n<li>&#8216;negate&#8217;: how the does\/doesn&#8217;t for &#8216;what&#8217; is decided.<\/li>\n<\/ul>\n<p>When &#8216;negate&#8217; is set to true, read it as &#8220;when my PATTERN doesn&#8217;t match, do WHAT&#8221;; when false, read it as &#8220;when my PATTERN does match, do WHAT&#8221;.<\/p>\n<p>In this example, &#8216;negate&#8217; is true, so we read it as &#8220;when my timestamp pattern doesn&#8217;t match, keep the line with the previous entry&#8221;:<\/p>\n<pre>filter {\r\n    multiline {\r\n      negate =&gt; 'true'\r\n      pattern =&gt; \"^%{TIMESTAMP_ISO8601} \"\r\n      what =&gt; 'previous'\r\n    }\r\n}<\/pre>\n<p>This filter should be used first, so that other filters will see the single event.<\/p>\n<p>Until a new line matches the pattern, logstash is expecting more lines to join, so it won&#8217;t release the combined event. \u00a0There is an enable_flush option, but it should not be used in production. \u00a0In logstash version 1.5, the flush will be &#8220;production ready&#8221;.<\/p>\n<p>When using multiline, you cannot use multiple filter workers, as each worker would be reading a different line. \u00a0If you attempt this configuration, logstash will not start.<\/p>\n<p>If your application writes log entries in a way where they can overlap with each other, the basic filter can&#8217;t help you. \u00a0However, if your system prints a common string in each message (a UUID, etc), you can use that to combine messages. \u00a0See the &#8216;stream_identity&#8217; option.<\/p>\n<p>You should also consider using the multiline{} codec, so that messages are combined in the input{} phase. \u00a0Note that the codec doesn&#8217;t offer the &#8216;stream_identity&#8217; option.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The multiline filter is designed to combine messages that span lines into a single event that can be easily processed with other logstash filters. \u00a0Systems that throw large exceptions (e.g. Java) are the standard use-case for this filter. At the &hellip; <a href=\"http:\/\/svops.com\/blog\/using-the-multiline-filter\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/85"}],"collection":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/comments?post=85"}],"version-history":[{"count":2,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/85\/revisions"}],"predecessor-version":[{"id":87,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/85\/revisions\/87"}],"wp:attachment":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/media?parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/categories?post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/tags?post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}