Class: LogStash::Codecs::Line

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

Overview

Line-oriented text data.

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



34
35
36
37
38
# File 'lib/logstash/codecs/line.rb', line 34

def decode(data)
  @buffer.extract(data).each do |line|
    yield LogStash::Event.new("message" => @converter.convert(line))
  end
end

#encode(event) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/logstash/codecs/line.rb', line 49

def encode(event)
  if event.is_a? LogStash::Event and @format
    @on_event.call(event, event.sprintf(@format) + NL)
  else
    @on_event.call(event, event.to_s + NL)
  end
end

#flush(&block) ⇒ Object



41
42
43
44
45
46
# File 'lib/logstash/codecs/line.rb', line 41

def flush(&block)
  remainder = @buffer.flush
  if !remainder.empty?
    block.call(LogStash::Event.new("message" => @converter.convert(remainder)))
  end
end

#registerObject



26
27
28
29
30
31
# File 'lib/logstash/codecs/line.rb', line 26

def register
  require "logstash/util/buftok"
  @buffer = FileWatch::BufferedTokenizer.new
  @converter = LogStash::Util::Charset.new(@charset)
  @converter.logger = @logger
end