logstash-将单个事件输出到多行输出文件

时间:2018-11-22 09:27:40

标签: logstash


我有一个带select语句的jdbc输入。恢复结果集中的每一行都有3列。 type Node struct { Coeff int Power int next *Node } // Add coeff^power to a polynomial func (n *Node) AddTerm(coeff int, power int) { for t := n; t != nil; t = t.next { if t.Power == power { t.Coeff += coeff return } } n.next = &Node{coeff, power, n.next} } // Add a polynomial m to the polynomial func (n *Node) AddPolynomial(m *Node) { for t := m; t != nil; t = t.next { n.AddTerm(t.Coeff, t.Power) } } // The string representation of the polynomial func (n *Node) String() string { buff := strings.Builder{} for t := n; t != nil; t = t.next { fmt.Fprintf(&buff, " + %d^%d", t.Coeff, t.Power) } return buff.String()[3:] } // Add two polynomials together creating a new one func Add(a *Node, b *Node) *Node { c := &Node{} c.AddPolynomial(a) c.AddPolynomial(b) return c } func main() { p1 := &Node{} p1.AddTerm(5, 2) p1.AddTerm(4, 1) p1.AddTerm(3, 0) fmt.Println(p1) p2 := &Node{} p2.AddTerm(4, 1) p2.AddTerm(2, 0) fmt.Println(p2) p3 := Add(p1, p2) fmt.Println(p3) } c1c2。发出的事件具有以下结构:

c3

我想通过以下方式在文件中输出值:

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

这是输出配置:

output file:
v1
v2
v3

但是生成的是

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

不是普通的编解码器插件吗?我可以使用输出文件插件的其他编解码器插件吗?还是我唯一的选择就是编写自己的插件?
谢谢!

2 个答案:

答案 0 :(得分:0)

参加聚会有点晚,但这也许对其他人有所帮助。尽管它看起来很时髦,但是您只需在格式字符串中按Enter(使用line编解码器)就可以摆脱困境。

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

不是最漂亮的方法,但它可以工作。不确定是否有更好的方法。

答案 1 :(得分:-1)