Class: Fluent::TailInput::TailWatcher::RotateHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(path, log, &on_rotate) ⇒ RotateHandler

Returns a new instance of RotateHandler.



653
654
655
656
657
658
659
# File 'lib/fluent/plugin/in_tail.rb', line 653

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

Instance Method Details

#on_notifyObject



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/fluent/plugin/in_tail.rb', line 661

def on_notify
  begin
    stat = FileWrapper.stat(@path)
    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
      begin
        io = FileWrapper.open(@path)
      rescue Errno::ENOENT
      end
      @on_rotate.call(io)
    end
    @inode = inode
    @fsize = fsize
  end

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