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.



1183
1184
1185
1186
1187
1188
# File 'lib/fluent/plugin/in_tail.rb', line 1183

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

Instance Method Details

#on_notify(stat) ⇒ Object



1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
# File 'lib/fluent/plugin/in_tail.rb', line 1190

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