class LogStash::Codecs::GzipJson

This codec will read gzip encoded json content

Public Class Methods

new(params={}) click to toggle source
Calls superclass method
# File lib/logstash/codecs/gzip_json.rb, line 25
def initialize(params={})
  super(params)
  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end

Public Instance Methods

decode(data) { |event(parse)| ... } click to toggle source
# File lib/logstash/codecs/gzip_json.rb, line 32
def decode(data)
  begin
    @decoder = Zlib::GzipReader.new(StringIO.new(data))
    json_string = @decoder.read    
  rescue Zlib::Error, Zlib::GzipFile::Error=> e     
    @logger.error("Gzip codec: We cannot uncompress the gzip file", :error => e, :data => data)
    raise e
  end    

  begin
    yield LogStash::Event.new(JSON.parse(json_string))
  rescue JSON::ParserError => e
    @logger.info('JSON parse failure. Falling back to plain-text', :error => e, :data => json_string)
    yield LogStash::Event.new('message' => json_string)
  end
  
end