从 log4js 发送 JSON 到 logstash 和字段
Send JSON from log4js to logstash and fields
我正在使用 log4js 记录我的应用程序,我想将日志发送到 logstash。
这是 log4js 的默认附加程序 :
"appenders": [
{
"type": "console"
},
{
"host": "127.0.0.1",
"port": 5000,
"type": "logstashUDP"
}
]
这是 logstash 配置文件:
input {
udp {
port => 5000
type => "json"
}
}
filter {
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
stdout {}
}
发送日志工作正常,但我正在发送 JSON 日志,在 logstash 中,我看到 json.
的每个字符都有一个字段
2016-07-01T10:29:36.161Z 127.0.0.1
{"@version":"1","@timestamp":"2016-07-01T10:29:36.160Z","message":"My
message...","fields":{"0":"{","1":"\n","2":" ","3":" ","4":"\"", ...
我是 logstash 的新手,但我喜欢将所有字段分组到一个大字符串中。我该怎么做?
为了让您的输入知道它是 json,您需要向其添加编解码器:
input {
udp {
port => 5000
type => "json"
codec => "json"
}
}
此致,
亚瑟
我正在使用 log4js 记录我的应用程序,我想将日志发送到 logstash。
这是 log4js 的默认附加程序
"appenders": [
{
"type": "console"
},
{
"host": "127.0.0.1",
"port": 5000,
"type": "logstashUDP"
}
]
这是 logstash 配置文件:
input {
udp {
port => 5000
type => "json"
}
}
filter {
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
stdout {}
}
发送日志工作正常,但我正在发送 JSON 日志,在 logstash 中,我看到 json.
的每个字符都有一个字段2016-07-01T10:29:36.161Z 127.0.0.1 {"@version":"1","@timestamp":"2016-07-01T10:29:36.160Z","message":"My message...","fields":{"0":"{","1":"\n","2":" ","3":" ","4":"\"", ...
我是 logstash 的新手,但我喜欢将所有字段分组到一个大字符串中。我该怎么做?
为了让您的输入知道它是 json,您需要向其添加编解码器:
input {
udp {
port => 5000
type => "json"
codec => "json"
}
}
此致,
亚瑟