對(duì)于 json 格式的 log,可以通過(guò) codec 的 json 編碼進(jìn)行解析,但是如果記錄中只有一部分是 json,這時(shí)候就需要在 filter 中使用 json 解碼插件。
插件配置:
filter {
json {
source => "message"
target => "jsoncontent"
}
}
輸出結(jié)果:
{
"@version": "1",
"@timestamp": "2014-11-18T08:11:33.000Z",
"host": "web121.mweibo.tc.sinanode.com",
"message": "{\"uid\":3081609001,\"type\":\"signal\"}",
"jsoncontent": {
"uid": 3081609001,
"type": "signal"
}
}
上面的例子中,解析結(jié)果被放到了 target 所指向的節(jié)點(diǎn)下,如果希望將解析結(jié)果與 log 中其他字段保持在同一層級(jí)輸出,那么只需要去掉 target 即可:
{
"@version": "1",
"@timestamp": "2014-11-18T08:11:33.000Z",
"host": "web121.mweibo.tc.sinanode.com",
"message": "{\"uid\":3081609001,\"type\":\"signal\"}",
"uid": 3081609001,
"type": "signal"
}