Class: LogStash::Codecs::JSONLines
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::JSONLines
- Defined in:
- lib/logstash/codecs/json_lines.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#decode(data, &block) ⇒ Object
39 40 41 42 43 |
# File 'lib/logstash/codecs/json_lines.rb', line 39 def decode(data, &block) @buffer.extract(data).each do |line| parse(@converter.convert(line), &block) end end |
#encode(event) ⇒ Object
45 46 47 48 49 |
# File 'lib/logstash/codecs/json_lines.rb', line 45 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) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/logstash/codecs/json_lines.rb', line 51 def flush(&block) remainder = @buffer.flush if !remainder.empty? parse(@converter.convert(remainder), &block) end end |
#register ⇒ Object
33 34 35 36 37 |
# File 'lib/logstash/codecs/json_lines.rb', line 33 def register @buffer = FileWatch::BufferedTokenizer.new(@delimiter) @converter = LogStash::Util::Charset.new(@charset) @converter.logger = @logger end |