class Fluent::Plugin::TailInput::TailWatcher::IOHandler
Attributes
io[R]
pe[RW]
Public Class Methods
new(io, pe, log, read_lines_limit, first = true, &receive_lines)
click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 546 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
Public Instance Methods
close()
click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 602 def close @io.close unless @io.closed? end
on_notify()
click to toggle source
# File lib/fluent/plugin/in_tail.rb, line 561 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 line = @buffer.slice!(/.*?\n/m) @lines << line 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