Logstash - 问题解析 json_lines 格式

Logstash - Issue parsing json_lines format

可能是 n00b 问题试图让 json_lines 编解码器从文件中读取数据。

这是我的配置文件的样子

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
  }
}   

这是我超级简单的输入文件的样子

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

当我将编解码器切换到 plain 时,文件被读取并按预期写入输出。但无论我做什么,我都无法让 json_lines 编解码器读取和写入这些数据。

我是 logstash 的新手,所以这可能只是一些简单的事情,我只是无法理解。任何帮助将不胜感激!

干杯!

json_lines documentation 上有这个警告:

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.

改用json codec