Sha256: 3c3da612aa1429114612030d8c0860745d8f7ce95961ddbbd277c3d8157b4d0b

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

# encoding: utf-8
require "logstash/codecs/base"
require "logstash/util/charset"

# Line-oriented text data.
#
# Decoding behavior: Only whole line events will be emitted.
#
# Encoding behavior: Each event will be emitted with a trailing newline.
class LogStash::Codecs::Line < LogStash::Codecs::Base
  config_name "line"

  # Set the desired text format for encoding.
  config :format, :validate => :string

  # The character encoding used in this input. Examples include `UTF-8`
  # and `cp1252`
  #
  # This setting is useful if your log files are in `Latin-1` (aka `cp1252`)
  # or in another character set other than `UTF-8`.
  #
  # This only affects "plain" format logs since json is `UTF-8` already.
  config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"

  # Change the delimiter that separates lines
  config :delimiter, :validate => :string, :default => "\n"

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

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

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

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

end # class LogStash::Codecs::Plain

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
logstash-codec-line-3.0.5 lib/logstash/codecs/line.rb
logstash-codec-line-3.0.4 lib/logstash/codecs/line.rb
logstash-codec-line-3.0.3 lib/logstash/codecs/line.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/logstash-codec-line-3.0.2/lib/logstash/codecs/line.rb
logstash-codec-line-3.0.2 lib/logstash/codecs/line.rb
logstash-codec-line-3.0.1 lib/logstash/codecs/line.rb
logstash-codec-line-3.0.0 lib/logstash/codecs/line.rb
logstash-codec-line-2.1.2 lib/logstash/codecs/line.rb
logstash-codec-line-2.1.0 lib/logstash/codecs/line.rb