Class: LogStash::Codecs::JSONLines
- Defined in:
- lib/logstash/codecs/json_lines.rb
Overview
This codec will decode streamed JSON that is newline delimited. For decoding JSON payload in the redis input for example, use the json codec instead. Encoding will emit a single JSON string ending in a ānā
Constant Summary
Constants included from LogStash::Config::Mixin
LogStash::Config::Mixin::CONFIGSORT
Instance Attribute Summary
Attributes included from LogStash::Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #encode(data) ⇒ Object
-
#initialize(params = {}) ⇒ JSONLines
constructor
A new instance of JSONLines.
Methods inherited from Base
#clone, #flush, #on_event, #teardown
Methods included from LogStash::Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
Instance Method Details
#decode(data) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/logstash/codecs/json_lines.rb', line 33 def decode(data) @lines.decode(data) do |event| begin yield LogStash::Event.new(JSON.parse(event["message"])) rescue JSON::ParserError => e @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => data) yield LogStash::Event.new("message" => data) end end end |
#encode(data) ⇒ Object
46 47 48 49 50 |
# File 'lib/logstash/codecs/json_lines.rb', line 46 def encode(data) # Tack on a \n for now because previously most of logstash's JSON # outputs emitted one per line, and whitespace is OK in json. @on_event.call(data.to_json + "\n") end |