class LogStash::Codecs::GZIP

This codec may be used to decode gzip data from string.

If this codec recieves a payload from an input that is not valid GZIP, then it will fall back to plain text and add a tag `_gzipparsefailure`. Upon a GZIP failure, the payload will be stored in the `message` field.

Constants

MESSAGE_FIELD

Public Instance Methods

decode(data) { |event(MESSAGE_FIELD => convert)| ... } click to toggle source
# File lib/logstash/codecs/gzip.rb, line 35
def decode(data)
  begin
    decoded = Zlib::GzipReader.new(StringIO.new(data)).read
    yield LogStash::Event.new(MESSAGE_FIELD => @converter.convert(decoded))
  rescue Zlib::Error, Zlib::GzipFile::Error=> e
    @logger.info? && @logger.info("Gzip codec: GZIP parse failure. Falling back to plain-text", :error => e, :data => data)
    yield LogStash::Event.new(MESSAGE_FIELD => @converter.convert(data), "tags" => ["_gzipparsefailure"])
  end
end
register() click to toggle source
# File lib/logstash/codecs/gzip.rb, line 29
def register
  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end