我正在尝试处理包含纯消息和 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'"}