Class: LogStash::Codecs::JSONStream
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::JSONStream
- Defined in:
- lib/logstash/codecs/json_stream.rb
Overview
This codec will decode streamed JSON that is not delimited. Encoding will emit a single JSON string ending in a ‘@delimiter`
Instance Method Summary collapse
Instance Method Details
#decode(concatenated_json, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/logstash/codecs/json_stream.rb', line 23 def decode(concatenated_json, &block) array_json = @converter.convert("[#{concatenated_json.gsub('}{', '},{')}]") parse(array_json, &block) rescue LogStash::Json::ParserError => e @logger.warn("JSON parse error for json stream / concatenated json, original data now in message field", :error => e, :data => concatenated_json) yield LogStash::Event.new("message" => concatenated_json, "tags" => ["_jsonparsefailure"]) rescue StandardError => e # This should NEVER happen. But hubris has been the cause of many pipeline breaking things # If something bad should happen we just don't want to crash logstash here. @logger.error( "An unexpected error occurred parsing JSON data", :data => concatenated_json, :message => e., :class => e.class.name, :backtrace => e.backtrace ) end |
#encode(event) ⇒ Object
41 42 43 |
# File 'lib/logstash/codecs/json_stream.rb', line 41 def encode(event) @logger.error("Encoding is not supported by 'jsonstream' plugin yet") end |
#register ⇒ Object
18 19 20 21 |
# File 'lib/logstash/codecs/json_stream.rb', line 18 def register @converter = LogStash::Util::Charset.new(@charset) @converter.logger = @logger end |