admin管理员组

文章数量:1332890

I am trying to use the record_transformer filter plugin in Fluentd to modify log records. Specifically, I want to include a field where the value is determined by a multiline Ruby if-else statement. However, it seems that the block does not support multiline code or throws errors when I try to format my logic in multiple lines for readability.

For example, I tried the following configuration:

<filter my_tag>
  @type record_transformer
  enable_ruby
  <record>
    new_field ${if record["key"] == "value1"
                  "output1"
                elsif record["key"] == "value2"
                  "output2"
                else
                  "default_output"
                end}
  </record>
</filter>

This gives me an error.

<record>
  new_field ${if record["key"] == "value1"; "output1"; elsif record["key"] == "value2"; "output2"; else; "default_output"; end}
</record>

This single-line format is hard to read and maintain when the logic becomes more complex.

  1. Is there a workaround to make multiline logic work in ?
  2. Should I use a different plugin for this type of transformation? If so, what would be a good alternative?

本文标签: How to write multiline ifelse statements inside ltrecordgt in Fluentd recordtransformerStack Overflow