Sha256: 462fbbf98b413c9d56ec9e8db9dfba2945ff32b3193720afddd68a46d87a6a47

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

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

class LogStash::Codecs::Spool < LogStash::Codecs::Base
  config_name 'spool'
  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 close
    if !@buffer.nil? and @buffer.length > 0
      @on_event.call @buffer
    end
    @buffer = []
  end
end # class LogStash::Codecs::Spool

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-codec-spool-2.0.2 lib/logstash/codecs/spool.rb
logstash-codec-spool-2.0.1 lib/logstash/codecs/spool.rb