Sha256: 9aa53be08e5811bbfc0e0925b39b0acc1f860df9ef03c53f2daf1be27eb224ba

Contents?: true

Size: 783 Bytes

Versions: 3

Compression:

Stored size: 783 Bytes

Contents

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

class LogStash::Codecs::Spool < LogStash::Codecs::Base
  config_name 'spool'
  milestone 1
  config :spool_size, :validate => :number, :default => 50

  attr_reader :buffer

  public
  def decode(data)
    data.each do |event|
      yield event
    end
  end # def decode

  public
  def encode(event)
    @buffer ||= []
    #buffer size is hard coded for now until a
    #better way to pass args into codecs is implemented
    if @buffer.length >= @spool_size
      @on_event.call @buffer
      @buffer = []
    else
      @buffer << event
    end
  end # def encode

  public
  def teardown
    if !@buffer.nil? and @buffer.length > 0
      @on_event.call @buffer
    end
    @buffer = []
  end
end # class LogStash::Codecs::Spool

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
logstash-codec-spool-0.1.2 lib/logstash/codecs/spool.rb
logstash-codec-spool-0.1.1 lib/logstash/codecs/spool.rb
logstash-codec-spool-0.1.0 lib/logstash/codecs/spool.rb