lib/fluent/plugin/in_tail.rb in fluentd-0.10.16 vs lib/fluent/plugin/in_tail.rb in fluentd-0.10.17
- old
+ new
@@ -29,10 +29,12 @@
config_param :path, :string
config_param :tag, :string
config_param :rotate_wait, :time, :default => 5
config_param :pos_file, :string, :default => nil
+ attr_reader :paths
+
def configure(conf)
super
@paths = @path.split(',').map {|path| path.strip }
if @paths.empty?
@@ -258,28 +260,35 @@
$log.info "following tail of #{io.path}"
@io = io
@pe = pe
@receive_lines = receive_lines
@buffer = ''
+ @iobuf = ''
end
attr_reader :io
def on_notify
lines = []
- while line = @io.gets
- @buffer << line
- @pos = @io.pos
- unless @buffer[@buffer.length-1] == ?\n
+ while true
+ begin
+ if @buffer.empty?
+ @io.read_nonblock(2048, @buffer)
+ else
+ @buffer << @io.read_nonblock(2048, @iobuf)
+ end
+ while line = @buffer.slice!(/.*?\n/m)
+ lines << line
+ end
+ rescue EOFError
break
end
- lines << line
end
unless lines.empty?
- @pe.update_pos(@pos)
@receive_lines.call(lines)
+ @pe.update_pos(@io.pos - @buffer.bytesize)
end
rescue
$log.error $!.to_s
$log.error_backtrace
close