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.

Constant Summary collapse

MESSAGE_FIELD =
"message".freeze

Instance Method Summary collapse

Instance Method Details

#decode(data) ⇒ Object



37
38
39
# File 'lib/logstash/codecs/line.rb', line 37

def decode(data)
  @buffer.extract(data).each { |line| yield LogStash::Event.new(MESSAGE_FIELD => @converter.convert(line)) }
end

#encode(event) ⇒ Object



48
49
50
51
# File 'lib/logstash/codecs/line.rb', line 48

def encode(event)
  encoded = @format ? event.sprintf(@format) : event.to_s
  @on_event.call(event, encoded + @delimiter)
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_FIELD => @converter.convert(remainder)))
  end
end

#registerObject



30
31
32
33
34
35
# File 'lib/logstash/codecs/line.rb', line 30

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