1

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?

Community
  • 1
  • 1
nkint
  • 11,513
  • 31
  • 103
  • 174
  • you might need to use codec => "json" in your udp to tell it that the incoming logs are json logs. The default is plain – pandaadb Jul 01 '16 at 10:50
  • @pandaadb Ok, thanks, if you can add it as answer I'll check it as accepted otherway I'll delete the question – nkint Jul 01 '16 at 12:20

1 Answers1

3

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

nkint
  • 11,513
  • 31
  • 103
  • 174
pandaadb
  • 6,306
  • 2
  • 22
  • 41