Class: Fluent::Plugin::BinInput::TailWatcher::IOHandler
- Inherits:
-
TailInput::TailWatcher::IOHandler
- Object
- TailInput::TailWatcher::IOHandler
- Fluent::Plugin::BinInput::TailWatcher::IOHandler
- Defined in:
- lib/fluent/plugin/in_bin.rb
Instance Method Summary collapse
-
#initialize(io, pe, log, read_lines_limit, first = true, &receive_lines) ⇒ IOHandler
constructor
A new instance of IOHandler.
- #on_notify ⇒ Object
Constructor Details
#initialize(io, pe, log, read_lines_limit, first = true, &receive_lines) ⇒ IOHandler
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fluent/plugin/in_bin.rb', line 120 def initialize(io, pe, log, read_lines_limit, first = true, &receive_lines) @log = log @log.info "following #{io.path}" if first @io = io @pe = pe @read_lines_limit = read_lines_limit @receive_lines = receive_lines @lines = [] @io.binmode end |
Instance Method Details
#on_notify ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fluent/plugin/in_bin.rb', line 131 def on_notify begin read_more = false if @lines.empty? begin while true @lines << @io.readpartial(2048) if @lines.size >= @read_lines_limit # not to use too much memory in case the file is very large read_more = true break end end rescue EOFError end end unless @lines.empty? if @receive_lines.call(@lines) @pe.update_pos(@io.pos) @lines.clear else read_more = false end end end while read_more rescue @log.error $!.to_s @log.error_backtrace close end |