【发布时间】:2013-08-16 07:41:44
【问题描述】:
我正在尝试处理日志文件中的条目,该日志文件同时包含普通消息和 json 格式的消息。我最初的想法是 grep 用大括号括起来的消息,并让它们由另一个链式过滤器处理。 Grep 工作正常(与普通消息处理一样),但随后的 json 过滤器报告异常。我在下面附上了logstash的配置、输入和错误信息。
您有什么想法可能是什么问题吗?对于处理来自同一文件的普通和 json 格式的条目有任何替代建议吗?
非常感谢, 约翰内斯
错误信息:
Trouble parsing json {:key=>"@message", :raw=>"{\"time\":\"14.08.2013 10:16:31:799\",\"level\":\"DEBUG\",\"thread\":\"main\",\"clazz\":\"org.springframework.beans.factory.support.DefaultListableBeanFactory\",\"line\":\"214\",\"msg\":\"Returning cached instance of singleton bean 'org.apache.activemq.xbean.XBeanBrokerService#0'\"}", :exception=>#<NoMethodError: undefined method `[]' for nil:NilClass>, :level=>:warn}
logstash 配置:
file {
path => [ "plain.log" ]
type => "plainlog"
format => "plain"
}
}
filter {
# Grep json formatted messages and send them to following json filter
grep {
type => "plainlog"
add_tag => [ "grepped_json" ]
match => [ "@message", "^{.*}" ]
}
json {
tags => [ "grepped_json" ]
source => "@message"
}
}
output {
stdout { debug => true debug_format => "json"}
elasticsearch { embedded => true }
}
来自日志文件的输入(仅一行):
{"time":"14.08.2013 10:16:31:799","level":"DEBUG","thread":"main","clazz":"org.springframework.beans.factory.support.DefaultListableBeanFactory","line":"214","msg":"Returning cached instance of singleton bean 'org.apache.activemq.xbean.XBeanBrokerService#0'"}
【问题讨论】: