Class: Fluent::TailInput::TailWatcher::IOHandler
- Inherits:
-
Object
- Object
- Fluent::TailInput::TailWatcher::IOHandler
- Defined in:
- lib/fluent/plugin/in_tail.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io, pe, log, &receive_lines) ⇒ IOHandler
constructor
A new instance of IOHandler.
- #on_notify ⇒ Object
Constructor Details
#initialize(io, pe, log, &receive_lines) ⇒ IOHandler
1109 1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'lib/fluent/plugin/in_tail.rb', line 1109 def initialize(io, pe, log, &receive_lines) @log = log @log.info "following tail of #{io.path}" @io = io @pe = pe @receive_lines = receive_lines @buffer = ''.force_encoding('ASCII-8BIT') @iobuf = ''.force_encoding('ASCII-8BIT') end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
1119 1120 1121 |
# File 'lib/fluent/plugin/in_tail.rb', line 1119 def io @io end |
Instance Method Details
#close ⇒ Object
1158 1159 1160 |
# File 'lib/fluent/plugin/in_tail.rb', line 1158 def close @io.close unless @io.closed? end |
#on_notify ⇒ Object
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 |
# File 'lib/fluent/plugin/in_tail.rb', line 1121 def on_notify begin lines = [] read_more = false begin while true if @buffer.empty? @io.read_nonblock(2048, @buffer) else @buffer << @io.read_nonblock(2048, @iobuf) end while line = @buffer.slice!(/.*?\n/m) lines << line end if lines.size >= MAX_LINES_AT_ONCE # not to use too much memory in case the file is very large read_more = true break end end rescue EOFError end unless lines.empty? @receive_lines.call(lines) @pe.update_pos(@io.pos - @buffer.bytesize) end end while read_more rescue @log.error $!.to_s @log.error_backtrace close end |