Class: LogStash::Codecs::LineEOF

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

Overview

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.

Instance Method Summary collapse

Instance Method Details

#decode(data) ⇒ Object



35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



54
55
56
57
58
59
60
# 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) ⇒ Object



46
47
48
49
50
51
# 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

#registerObject



27
28
29
30
31
32
# 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