代码之家  ›  专栏  ›  技术社区  ›  rohansingh

如何在Logstash配置文件中包含过滤器?

  •  0
  • rohansingh  · 技术社区  · 8 年前

    第一行表示自定义日志,而第二行表示JSON格式的日志。

    现在,我想编写一个过滤器,它将根据内容解析日志,并最终将所有JSON格式日志指向一个名为jsonformat的文件。日志和其他日志放在一个单独的文件中。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Val    8 年前

    您可以利用 json

    input {
       file {
           path => "/Users/mysystem/Desktop/abc.log"
           start_position => beginning
           ignore_older => 0
       }
    }
    filter {
       json {
         source => "message"
       }
    }
    output {
      # this condition will be true if the log line is not valid JSON
      if "_jsonparsefailure" in [tags] {
        file {
           path => "/Users/mysystem/Desktop/nonjson.log"
        }
      }
      # this condition will be true if the log line is valid JSON
      else {
        file {
           path => "/Users/mysystem/Desktop/jsonformat.log"
        }
      }
    }