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(log, &on_rotate) ⇒ RotateHandler

Returns a new instance of RotateHandler.



1234
1235
1236
1237
1238
1239
# File 'lib/fluent/plugin/in_tail.rb', line 1234

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

Instance Method Details

#on_notify(stat) ⇒ Object



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
# File 'lib/fluent/plugin/in_tail.rb', line 1241

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

  if @inode != inode || fsize < @fsize
    @on_rotate.call(stat)
  end
  @inode = inode
  @fsize = fsize
rescue
  @log.error $!.to_s
  @log.error_backtrace
end