Class: LogStash::Codecs::CompressSpooler

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

Constant Summary

Constants included from LogStash::Config::Mixin

LogStash::Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from LogStash::Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#clone, #flush, #initialize, #on_event

Methods included from LogStash::Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Codecs::Base

Instance Method Details

#decode(data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/codecs/compress_spooler.rb', line 18

def decode(data)
  z = Zlib::Inflate.new
  data = MessagePack.unpack(z.inflate(data))
  z.finish
  z.close
  data.each do |event|
    event = LogStash::Event.new(event)
    event["@timestamp"] = Time.at(event["@timestamp"]).utc if event["@timestamp"].is_a? Float
    yield event
  end
end

#encode(data) ⇒ Object



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

def encode(data)
  if @buffer.length >= @spool_size
    z = Zlib::Deflate.new(@compress_level)
    @on_event.call z.deflate(MessagePack.pack(@buffer), Zlib::FINISH)
    z.close
    @buffer.clear
  else
    data["@timestamp"] = data["@timestamp"].to_f
    @buffer << data.to_hash
  end
end

#registerObject



11
12
13
14
15
# File 'lib/logstash/codecs/compress_spooler.rb', line 11

def register
  require "msgpack"
  require "zlib"
  @buffer = []
end

#teardownObject



44
45
46
47
48
49
# File 'lib/logstash/codecs/compress_spooler.rb', line 44

def teardown
  if !@buffer.nil? and @buffer.length > 0
    @on_event.call @buffer
  end
  @buffer.clear
end