EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Logstash Tutorial Logstash Multiline
Secondary Sidebar
Logstash Tutorial
  • Basic
    • What is Logstash?
    • Kibana Logstash
    • Logstash Alternatives
    • Logstash if field exists
    • Logstash Test Config
    • Logstash Date Filter
    • Logstash Version
    • Logstash Filter
    • Logstash Pipeline
    • Logstash Port
    • Logstash Filter JSON
    • Logstash JDBC
    • Logstash Timestamp
    • Logstash Multiline
    • Logstash split
    • Logstash Codec
    • Logstash HTTP input
    • Logstash Filebeat
    • Logstash if
    • Logstash File Input
    • Logstash mutate
    • Logstash Syslog
    • Logstash AWS
    • Logstash.yml
    • Logstash Install Plugin
    • Logstash Geoip
    • Logstash add field
    • Logstash Multiple Pipelines
    • Logstash TCP input
    • Logstash Multiple Outputs
    • Logstash Stdout
    • Logstash Pipeline Configuration
    • Logstash Monitoring
    • LogstashEncoder
    • Logstash CSV
    • Logstash Cluster
    • Logstash Debug

Logstash Multiline

Logstash Multiline

Introduction to Logstash Multiline

Logstash Multiline codec is the plugin available in logstash which was released in September 2021 and the latest version of this plugin available is version 3.1.1 which actually helps us in collapsing the messages that are in multiline format and then result into a single event combining and merging all of the messages. In this article, we will have a deeper study of what logstash multiline is and will try to understand it by using the subtopics which include What is logstash multiline, logstash multiline codec, logstash multiline configuration, and conclusion about the same.

What is logstash multiline?

Logstash multiline is the available functionality in which there are certain scenarios in which events generated are in such a manner that contains the text of multiple lines which are also referred to as multiline events. For handling this type of event in logstash, there needs to be a mechanism using which it will be able to tell which lines inside the event belong to the single event. Proper event ordering needs to be followed as the processing of multiline events is a very critical and complex job. That is why the processing of order arrangement is done at an early stage inside the pipelines.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

This is where multiline codec comes into the picture which is a tool for the management of multiline events that processes during the stage of the logstash pipeline.

Logstash Multiline code

Logstash multiline codec is the tool that takes into consideration particular set of rules which makes it possible to merge lines that come from a single input source. It merges all the multiline messages into a single event. The main motive of the logstash multiline codec is to allow the task of combining the multiline messages that come from files and result into a single event. Let us consider an example to understand this which makes it possible to combine messages of the stack trace and java exceptions resulting to a single event.
The configuration for setting the multiline codec plugin will look as shown below –

Input{
Stdin{
Codec => multiline {
Pattern => “regexp”
What => “next” or “previous”
Negate => “false” or “true”
}
}
}

You need to make sure that the part of the multiline event which is a field should satisfy the pattern specified. The what attribute helps in the specification of the relation of multiline events. The attribute negates here can have either true or false value which when not specified is treated to be false. This field means that if the message does not match with the filter for multiline then it will contain a pattern in it and vice versa.

Considering an example to understand this most of the stack traces of java have messages of multiline format and also, they began from the left side of the data containing all the lines properly well-indented. Hence, in such case, we can specify the pattern as “^\s” and what can be given a value of “previous” inside the codec=> multiline for standard input which means that if the line contains the whitespace at the start of it then it will be from the previous line.

Before we go and dive into the configurations and available options, let’s have a look at one example where we will be considering the lines which do not begin with the date and the previous line to be merged. For this, our configurations of the file for the input section will be as shown below –

Input {
File {
Codec => multiline {
Negate => true
Pattern => “^ % {TIMESTAMP_ISO8601}”
What => “previous”
}
Path => “/etc/logs/sampleEducbaApp.log”
}
}

The output of configurations inside the file along with indentation will look as shown below –

1

This methodology has one more application where it is used quite commonly which is in C programming language when you have to implement line continuations along with backslashes in it then we can set the configurations for multiline logstash using codec as shown below –

Input {
Stdin {
Codec => multiline {
What => “next”
Pattern => “\\$”
}
}
}

Which is the file looks as shown below –

This configuration specifies that if any of the specified lines ends along with the presence of backslash then that particular line should be combined along with the line that will be followed.

logstash multiline configuration

There are certain configuration options that you can specify to define the behavior and working of logstash codec configurations. The below table includes the configuration options for logstash multiline codec –

Configuration setting Type of Input Optional/ Required
Charset String value from the particular set of values mentioned in documents as it defines the standards followed by the character set. For a complete list of supported string values, please refer to this link. Optional
Auto flush interval An integer that is the number value Optional
Max bytes Byte value Optional
Pattern String Required
What String value which can have either “next” or “previous” value set to it. Required
Pattern dir It should be an array value Optional
Max lines Number value Optional
Ecs compatibility String value Optional
Negate Boolean value Optional
Multiline tag String value Optional
  • Auto_flush_interval – This configuration will allow you to convert a particular event in the case when a new line that is matching is discovered or new data is not appended for the specified second’s value. The default value corresponds to no.
  • Pattern – It is the regular expression value that is used for the purpose of matching the parts of lines.
  • What – Whenever a match is found for the pattern then recognize if the event is a part of the previous or next event.
  • Patterns_dir – If you might be adding some more patterns then you can make use of this configuration as shipping of a bunch of patterns is carried out by default by logstash.

Conclusion

Logstash multiline is the case where some of the events of logstash may generate the messages that are of multiline. In case to handle this, there is an in-built plugin available in logstash named multiline codec logstash plugin which helps in specifying the behavior of multiline event processing and handling of same.

Recommended Articles

This is a guide to Logstash Multiline. Here we discuss the Introduction, What is logstash multiline? Examples with code implementation. You may also have a look at the following articles to learn more –

  1. Logstash Version
  2. Logstash Alternatives
  3. Kibana Logstash
  4. What is Logstash?
Popular Course in this category
Kibana Training (1 Course, 3 Project)
  1 Online Courses |  3 Hands-on Project |  14+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more