class LogStash::Codecs::JSONLines
This codec will decode streamed JSON that is newline delimited. Encoding will emit a single JSON string ending in a `@delimiter` 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.
Public Instance Methods
decode(data, &block)
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 58 def decode(data, &block) @buffer.extract(data).each do |line| parse_json(@converter.convert(line), &block) end end
encode(event)
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 64 def encode(event) # Tack on a @delimiter for now because previously most of logstash's JSON # outputs emitted one per line, and whitespace is OK in json. @on_event.call(event, "#{event.to_json}#{@delimiter}") end
flush(&block)
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 70 def flush(&block) remainder = @buffer.flush if !remainder.empty? parse_json(@converter.convert(remainder), &block) end end
register()
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 52 def register @buffer = FileWatch::BufferedTokenizer.new(@delimiter) @converter = LogStash::Util::Charset.new(@charset) @converter.logger = @logger end
Private Instance Methods
parse_json(json) { |event| ... }
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 79 def parse_json(json) events_from_json(json, targeted_event_factory).each { |event| yield event } rescue => e @logger.warn("JSON parse error, original data now in message field", message: e.message, exception: e.class, data: json) yield parse_json_error_event(json) end
parse_json_error_event(json)
click to toggle source
# File lib/logstash/codecs/json_lines.rb, line 86 def parse_json_error_event(json) event_factory.new_event("message" => json, "tags" => ["_jsonparsefailure"]) end