首页 > 解决方案 > logstash - output single event into multiple line output file

问题描述


I have a jdbc input with a select statement. each row in the restult set has 3 columns. c1, c2, c3. the event emitted has the following structure:

{"c1":"v1", "c2":"v2", "c3":"v3", "file_name":"tmp.csv"}

I want to output the values in a file in the following manner:

output file:
v1
v2
v3

this is the output configuration:

file {
                path => "/tmp/%{file_name}"
                codec => plain { format => "%{c1}\n%{c2}\n%{c3}"  }
                write_behavior => "overwrite"
                flush_interval => 0
        }

but what is generated is

outputfile:
v1\nv2\nv3

is the plain codec plugin not the one i need? is there any other codec plugin for the output file plugin that i can use? or is the only option i have is to write my own plugin?
Thanks!

标签: logstash

解决方案


聚会有点晚了,但也许这对其他人有帮助。虽然它看起来很时髦,但您应该能够在格式字符串中简单地按 Enter (使用line编解码器)。

file {
    path => "/tmp/%{file_name}"
    codec => line {
        format => "%{c1}
%{c2}
%{c3}"
    }
    write_behavior => "overwrite"
    flush_interval => 0
}

不是最漂亮的方法,但它有效。不确定是否有更好的方法。


推荐阅读