class LogStash::Codecs::CompressSpooler
Public Instance Methods
decode(data) { |event| ... }
click to toggle source
# 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)
click to toggle source
# 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
register()
click to toggle source
# File lib/logstash/codecs/compress_spooler.rb, line 11 def register require "msgpack" require "zlib" @buffer = [] end
teardown()
click to toggle source
# 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