class Fluent::Plugin::TcpInput

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method Fluent::PluginLoggerMixin#configure
# File lib/fluent/plugin/in_tcp.rb, line 42
def configure(conf)
  compat_parameters_convert(conf, :parser)
  super
  @_event_loop_blocking_timeout = @blocking_timeout
  @source_hostname_key ||= @source_host_key if @source_host_key

  @parser = parser_create
end
multi_workers_ready?() click to toggle source
# File lib/fluent/plugin/in_tcp.rb, line 51
def multi_workers_ready?
  true
end
start() click to toggle source
Calls superclass method Fluent::Compat::Input#start
# File lib/fluent/plugin/in_tcp.rb, line 55
def start
  super

  @buffer = ''
  server_create(:in_tcp_server, @port, bind: @bind) do |data, conn|
    @buffer << data
    begin
      pos = 0
      while i = @buffer.index(@delimiter, pos)
        msg = @buffer[pos...i]
        pos = i + @delimiter.length

        @parser.parse(msg) do |time, record|
          unless time && record
            log.warn "pattern not match", message: msg
            next
          end

          tag = extract_tag_from_record(record)
          tag ||= @tag
          time ||= extract_time_from_record(record) || Fluent::EventTime.now
          record[@source_hostname_key] = conn.remote_host if @source_hostname_key
          router.emit(tag, time, record)
        end
      end
      @buffer.slice!(0, pos) if pos > 0
    end
  end
end