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

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

Instance Method Summary collapse

Constructor Details

#initialize(watcher, &on_rotate) ⇒ RotateHandler

Returns a new instance of RotateHandler.



727
728
729
730
731
732
# File 'lib/fluent/plugin/in_tail.rb', line 727

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

Instance Method Details

#on_notify(stat) ⇒ Object



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/fluent/plugin/in_tail.rb', line 734

def on_notify(stat)
  if stat.nil?
    inode = nil
    fsize = 0
  else
    inode = stat.ino
    fsize = stat.size
  end

  begin
    if @inode != inode || fsize < @fsize
      @on_rotate.call(stat)
    end
    @inode = inode
    @fsize = fsize
  end

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