Sha256: 871bdb62ad6a25df2f6f9eb9a13082bbc99ca7a9340868b85d4e48b7990c2e44

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8
require "logstash/codecs/base"
require "logstash/codecs/plain"
require "logstash/json"
require "zlib"

# This codec will read gzip encoded content
class LogStash::Codecs::GzipLines < LogStash::Codecs::Base
  config_name "gzip_lines"


  # 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 initialize(params={})
    super(params)
    @converter = LogStash::Util::Charset.new(@charset)
    @converter.logger = @logger
  end

  public
  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 # def decode
end # class LogStash::Codecs::GzipLines

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
logstash-codec-gzip_lines-3.0.3 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-3.0.2 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-3.0.1 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-3.0.0 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-2.0.4 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-2.0.2 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-2.0.1 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-0.1.5 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-0.1.4 lib/logstash/codecs/gzip_lines.rb
logstash-codec-gzip_lines-0.1.3 lib/logstash/codecs/gzip_lines.rb