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.



1163
1164
1165
1166
1167
1168
# File 'lib/fluent/plugin/in_tail.rb', line 1163

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

Instance Method Details

#on_notify(stat) ⇒ Object



1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/fluent/plugin/in_tail.rb', line 1170

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