2

Probably a n00b issue trying to get the json_lines codec to read data from a file.

Here's what my config file looks like

input {
  file {
    path => ['C:/dev/logstash-5.1.2/data/sample.log']
    start_position => "beginning"
    sincedb_path => 'C:/dev/logstash-5.1.2/data/.sincedb'
    codec => "json_lines"
  }
}
output {  
  file {
    path => ['C:/dev/logstash-5.1.2/data/sample-output.log']
    flush_interval => 0
  }
}   

Here's what my super simple input file looks like

{"id":1,"name":"A green door","price":12.50,"tags":["home","green"]}
{"id":2,"name":"A red door","price":12.50,"tags":["home","red"]}

When I switch the codec to plain the file gets read and output gets written as expected. But no matter what I do I'm unable to get the json_lines codec to read and write this data.

I am pretty new to logstash, so this might just be something simple that I'm just not able to wrap my head around. Any help would be most appreciated!

Cheers!

sgafur
  • 23
  • 1
  • 7

1 Answers1

4

On the json_lines documentation it has this warning:

NOTE: Do not use this codec if your source input is line-oriented JSON, for example, redis or file inputs. Rather, use the json codec. More info: This codec is expecting to receive a stream (string) of newline terminated lines. The file input will produce a line string without a newline. Therefore this codec cannot work with line oriented inputs.

Use the json codec instead.

Will Barnwell
  • 4,049
  • 21
  • 34
  • 1
    Thank you! I was confused by the "Reads newline-delimited JSON" description on the codecs page of the user guide.. – sgafur Feb 03 '17 at 21:26