Class: Fluent::TailInput::TailWatcher::RotateHandler
- Inherits:
-
Object
- Object
- Fluent::TailInput::TailWatcher::RotateHandler
- Defined in:
- lib/fluent/plugin/in_tail.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(path, &on_rotate) ⇒ RotateHandler
constructor
A new instance of RotateHandler.
- #on_notify ⇒ Object
Constructor Details
#initialize(path, &on_rotate) ⇒ RotateHandler
Returns a new instance of RotateHandler.
1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/fluent/plugin/in_tail.rb', line 1178 def initialize(path, &on_rotate) @path = path @inode = nil @fsize = -1 # first @on_rotate = on_rotate @log = $log end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
1186 1187 1188 |
# File 'lib/fluent/plugin/in_tail.rb', line 1186 def log @log end |
Instance Method Details
#on_notify ⇒ Object
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 |
# File 'lib/fluent/plugin/in_tail.rb', line 1188 def on_notify begin io = File.open(@path) stat = io.stat 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 @on_rotate.call(io) io = nil end @inode = inode @fsize = fsize ensure io.close if io end rescue @log.error $!.to_s @log.error_backtrace end |