删除包含哈希字符的日志行

问题描述 投票:8回答:2

在我的Logstash发货人中,我想过滤掉用散列字符注释的行:

#This log row should be dropped.
But one this should not.

我能够使用grep过滤器,但因为它不鼓励(将退役),我试图得到一个grok过滤器来做它。此过滤器无效:

grok {
  match => ["message", "^#.*"]
  drop_if_match => true
}

我也尝试将正则表达式放在自定义模式文件中,但没有帮助。有任何想法吗?

regex logging logstash logstash-grok
2个回答
21
投票

如果您感兴趣,甚至更简单:

filter {
    if ([message] =~ /^#/) {
        drop{}
    }
}

Logstash的最后几个版本更加强调分支逻辑directly in the config files。需要一点点习惯,但是一旦你这么做就很方便。


2
投票

正确答案是drop_if_match=>true中有一个错误(Logstash v1.2.2)。使用此类变通方法:

grok {
  ...
  add_tag => ["some_comment"]
}
if "some_comment" in [tags] {
  drop {}
}
© www.soinside.com 2019 - 2024. All rights reserved.