class LogStash::Codecs::LineEOF

Line-oriented text data with EOF(end of file) recognition.

Decoding behavior: Only whole line events will be emitted.

Encoding behavior: Each event will be emitted with a trailing newline.

Public Instance Methods

decode(data) { |event| ... } click to toggle source
# File lib/logstash/codecs/lineeof.rb, line 35
def decode(data)
  lines = @buffer.extract(data)
  lines.each_with_index do |line, index|
    event = LogStash::Event.new("message" => @converter.convert(line))
    #if end of file is reached?
    event.tag("eof") if index == lines.size - 1 && data.length < 32768
    yield event
  end
end
encode(data) click to toggle source
# File lib/logstash/codecs/lineeof.rb, line 54
def encode(data)
  if data.is_a? LogStash::Event and @format
    @on_event.call(data.sprintf(@format) + "\n")
  else
    @on_event.call(data.to_s + "\n")
  end
end
flush(&block) click to toggle source
# File lib/logstash/codecs/lineeof.rb, line 46
def flush(&block)
  remainder = @buffer.flush
  if !remainder.empty?
    block.call(LogStash::Event.new({"message" => remainder}))
  end
end
register() click to toggle source
# File lib/logstash/codecs/lineeof.rb, line 27
def register
  require "logstash/util/buftok"
  @buffer = FileWatch::BufferedTokenizer.new
  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end