# File lib/fluent/plugin/in_tail.rb, line 611 def initialize(io, pe, log, read_lines_limit, first = true, &receive_lines) @log = log @log.info "following tail of #{io.path}" if first @io = io @pe = pe @read_lines_limit = read_lines_limit @receive_lines = receive_lines @buffer = ''.force_encoding('ASCII-8BIT') @iobuf = ''.force_encoding('ASCII-8BIT') @lines = [] end
# File lib/fluent/plugin/in_tail.rb, line 667 def close @io.close unless @io.closed? end
# File lib/fluent/plugin/in_tail.rb, line 626 def on_notify begin read_more = false if @lines.empty? begin while true if @buffer.empty? @io.readpartial(2048, @buffer) else @buffer << @io.readpartial(2048, @iobuf) end while idx = @buffer.index("\n".freeze) @lines << @buffer.slice!(0, idx + 1) end 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 - @buffer.bytesize) @lines.clear else read_more = false end end end while read_more rescue @log.error $!.to_s @log.error_backtrace close end