如何排除 <match> 中的模式以获得流畅的配置?

How to exclude pattern in <match> for fluentd config?

除了 match 中的一个模式外,我想输出全部为 null。例如,我知道有一些方法可以通过@labels 做到这一点,但我确实想排除 match 中的模式。

我想这样做:

<match {all tags except **events**}>

我做了什么:

我知道我可以像这样在 匹配 中使用 Ruby 表达式:

<match #{tag.match(/^.*event.*$/) ? "fake_tag" : "**"}>
  @type null
</match>

逻辑: "If current tag has pattern - set fake_tag for skip this match, else set ** for output all in null"

但是这个表达式不起作用,因为ENV中没有变量$tag。据我了解 Ruby 表达式不能使用 ${tag}.

这样的配置变量

也许我可以在 匹配 步骤之前设置 ENV 变量?

像这样:

<filter **event**>
  #{ENV["FLUENTD_TAG"] = ${tag}}
</filter>

<match #{FLUENTD_TAG.match(/^.*event.*$/) ? "fake_tag" : "**"}>
  @type null
</match>

这些是我的想法,但也许有更简单的方法。

问题是 - 如何排除 match 中的模式? :-)

放弃一个,留下其他一切:

<match what.you.want.to.drop>
  @type null
</match>
<match **>
  # process everything else
</match>

除一个以外的所有内容:

<match what.you.want.to.stay>
  # process here or send to a label
</match>
<match **> # Optional block. It will be dropped anyways if no other matches, but with a warning printed to a fluentd log.
  # Drop everything else explicitly to avoid warning.
  @type null
</match>