Class: Fluent::TailPathInput::TailWatcher::RotateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_tailpath.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, &on_rotate) ⇒ RotateHandler

Returns a new instance of RotateHandler.



358
359
360
361
362
363
# File 'lib/fluent/plugin/in_tailpath.rb', line 358

def initialize(path, &on_rotate)
  @path = path
  @inode = nil
  @fsize = -1  # first
  @on_rotate = on_rotate
end

Instance Method Details

#on_notifyObject



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/fluent/plugin/in_tailpath.rb', line 365

def on_notify
  begin
    io = File.open(@path)
    stat = io.stat
    inode = stat.ino
    fsize = stat.size
  rescue Errno::ENOENT
    # moved or deleted
    inode = nil
    fsize = 0
  end

  begin
    if @inode != inode || fsize < @fsize
      # rotated or truncated
      @on_rotate.call(io)
      io = nil
    end

    @inode = inode
    @fsize = fsize
  ensure
    io.close if io
  end

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