How to process multiline log entry with logstash filter?

后端 未结 4 1443
终归单人心
终归单人心 2020-12-14 01:26

Background:

I have a custom generated log file that has the following pattern :

[2014-03-02 17:34:20] - 127.0.0.1|ERROR| E:\\xampp\\htdocs\\test.ph         


        
4条回答
  •  误落风尘
    2020-12-14 01:50

    I went through the source code and found out that :

    • The multiline filter will cancel all the events that are considered to be a follow up of a pending event, then append that line to the original message field, meaning any filters that are after the multiline filter won't apply in this case
    • The only event that will ever pass the filter, is one that is considered to be a new one ( something that start with [ in my case )

    Here is the working code :

    input {
       stdin{}
    }  
    
    filter{
          if "|ERROR|" in [message]{ #if this is the 1st message in many lines message
          grok{
            match => ['message',"\[.+\] - %{IP:ip}\|%{LOGLEVEL:loglevel}\| %{PATH:file}\|%{NUMBER:line}\|%{WORD:tag}\|%{GREEDYDATA:content}"]
          }
    
          mutate {
            replace => [ "message", "%{content}" ] #replace the message field with the content field ( so it auto append later in it )
            remove_field => ["content"] # we no longer need this field
          }
        }
    
        multiline{ #Nothing will pass this filter unless it is a new event ( new [2014-03-02 1.... )
            pattern => "^\["
            what => "previous"
            negate=> true
        }
    
        if "|DEBUG| flush_multi_line" in [message]{
          drop{} # We don't need the dummy line so drop it
        }
    }
    
    output {
      stdout{ debug=>true }
    }
    

    Cheers,

    Abdou

提交回复
热议问题