class Fluent::Plugin::BinInput::TailWatcher::IOHandler

Public Class Methods

new(io, pe, log, read_lines_limit, first = true, &receive_lines) click to toggle source
# File lib/fluent/plugin/in_bin.rb, line 120
def initialize(io, pe, log, read_lines_limit, first = true, &receive_lines)
  @log = log
  @log.info "following #{io.path}" if first
  @io = io
  @pe = pe
  @read_lines_limit = read_lines_limit
  @receive_lines = receive_lines
  @lines = []
  @io.binmode
end

Public Instance Methods

on_notify() click to toggle source
# File lib/fluent/plugin/in_bin.rb, line 131
def on_notify
  begin
    read_more = false

    if @lines.empty?
      begin
        while true
          @lines << @io.readpartial(2048)
          if @lines.size >= @read_lines_limit
            # not to use too much memory in case the file is very large
            read_more = true
            break
          end
        end
      rescue EOFError
      end
    end

    unless @lines.empty?
      if @receive_lines.call(@lines)
        @pe.update_pos(@io.pos)
        @lines.clear
      else
        read_more = false
      end
    end
  end while read_more

rescue
  @log.error $!.to_s
  @log.error_backtrace
  close
end