How to write multiline if-else statements inside <record> in Fluentd record_transformer? - Stack Overflow

I am trying to use the record_transformer filter plugin in Fluentd to modify log records. Specifically,

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742347982a4426933.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信