Class: LogStash::Codecs::Line

Inherits:
Base 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

Constants included from LogStash::Config::Mixin

LogStash::Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from LogStash::Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#clone, #initialize, #on_event, #teardown

Methods included from LogStash::Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Codecs::Base

Instance Method Details

#decode(data) ⇒ Object



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

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

#encode(data) ⇒ Object



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

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



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

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/line.rb', line 27

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