nkint nkint - 5 months ago 45
JSON Question

Send JSON from log4js to logstash and fields

I'm using log4js to log my application and I'd like to send logs to logstash.

Here is a defalt appender for log4js from here:

"appenders": [
{
"type": "console"
},
{
"host": "127.0.0.1",
"port": 5000,
"type": "logstashUDP"
}
]


and here is the logstash configuration file:

input {
udp {
port => 5000
type => "json"
}
}

filter {
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}

output {
stdout {}
}


Sending logs works correctly but I'm sending JSON log and in logstash I see a field for each charachter of the 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":"\"", ...


I'm new to logstash but I like to group all fields in a big string. How can I do it?

Answer

in order for your input to know that it is json, you will need to add a codec to it:

input {
  udp {
    port => 5000
    type => "json"
    codec => "json"
  }
}

Regards,

Artur