Sha256: e15ca7d4c025ded00872fca9be89ccb2da24e586a1fef0b51b248770c0e28499
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
# encoding: utf-8 require "logstash/codecs/base" require "logstash/codecs/line" require "json" # The codec should be used to decode full json messages. # If you are streaming JSON messages delimited by '\n' then # see the json_lines codec. # Encoding will result in a single json string. class LogStash::Codecs::JSON < LogStash::Codecs::Base config_name "json" milestone 3 # The character encoding used in this codec. Examples include "UTF-8" and # "CP1252" # # JSON requires valid UTF-8 strings, but in some cases, software that # emits JSON does so in another encoding (nxlog, for example). In # weird cases like this, you can set the charset setting to the # actual encoding of the text and logstash will convert it for you. # # For nxlog users, you'll want to set this to "CP1252" config :charset, :validate => ::Encoding.name_list, :default => "UTF-8" public def decode(data) begin yield LogStash::Event.new(JSON.parse(data)) 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 # def decode public def encode(data) @on_event.call(data.to_json) end # def encode end # class LogStash::Codecs::JSON
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
logstash-lib-1.3.2 | lib/logstash/codecs/json.rb |