Class: LogStash::Codecs::JSONLines
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::JSONLines
- Extended by:
- PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
- Includes:
- PluginMixins::ECSCompatibilitySupport, PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter, PluginMixins::EventSupport::FromJsonHelper
- 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
58 59 60 61 62 |
# 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) ⇒ Object
64 65 66 67 68 |
# 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) ⇒ Object
70 71 72 73 74 75 |
# 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 ⇒ Object
52 53 54 55 56 |
# 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 |