Class: LogStash::Codecs::GzipLines

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/codecs/gzip_lines.rb

Overview

This codec will read gzip encoded content

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ GzipLines

Returns a new instance of GzipLines.



24
25
26
27
28
# File 'lib/logstash/codecs/gzip_lines.rb', line 24

def initialize(params={})
  super(params)
  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end

Instance Method Details

#decode(data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/logstash/codecs/gzip_lines.rb', line 31

def decode(data)
  @decoder = Zlib::GzipReader.new(data)

  begin
    @decoder.each_line do |line|
      yield LogStash::Event.new("message" => @converter.convert(line))
    end
  rescue Zlib::Error, Zlib::GzipFile::Error=> e
    file = data.is_a?(String) ? data : data.class

    @logger.error("Gzip codec: We cannot uncompress the gzip file", :filename => file)
    raise e
  end
end