lib/fluent/plugin/in_tail.rb in fluentd-0.10.8 vs lib/fluent/plugin/in_tail.rb in fluentd-0.10.9
- old
+ new
@@ -40,10 +40,13 @@
if @pos_file
@pf_file = File.open(@pos_file, File::RDWR|File::CREAT)
@pf_file.sync = true
@pf = PositionFile.parse(@pf_file)
+ else
+ $log.warn "'pos_file PATH' parameter is not set to a 'tail' source."
+ $log.warn "this parameter is highly recommended to save the position to resume tailing."
end
configure_parser(conf)
end
@@ -59,11 +62,11 @@
pe = @pf ? @pf[path] : NullPositionEntry.instance
h = Handler.new(path, pe, method(:receive_lines))
@loop.attach h
}
handlers.each {|h|
- h.on_change # initialize call
+ h.on_change(nil, nil) # initialize call # TODO prev, cur
}
@thread = Thread.new(&method(:run))
end
def shutdown
@@ -114,18 +117,18 @@
@pos = @pe.read_pos
else
# seek to the end of file first.
# logs never duplicate but may be lost if fluent is down.
@pos = stat.size
- @pe.update(@inode, stat.size)
+ @pe.update(@inode, @pos)
end
@buffer = ''
@callback = callback
super(path)
end
- def on_change
+ def on_change(prev, cur)
lines = []
inode = nil
File.open(path) {|f|
stat = f.lstat
@@ -168,10 +171,10 @@
@inode = inode
else
@pe.update_pos(@pos)
end
- @callback.call(lines)
+ @callback.call(lines) unless lines.empty?
rescue Errno::ENOENT
# moved or deleted
@pos = 0
# TODO rescue