Class: Fluent::Plugin::TailInput::TailWatcher::FIFO
- Inherits:
-
Object
- Object
- Fluent::Plugin::TailInput::TailWatcher::FIFO
- Defined in:
- lib/fluent/plugin/in_tail.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#max_line_size ⇒ Object
readonly
Returns the value of attribute max_line_size.
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
- #convert(s) ⇒ Object
-
#initialize(encoding, log, max_line_size = nil, encoding_to_convert = nil) ⇒ FIFO
constructor
A new instance of FIFO.
- #read_lines(lines) ⇒ Object
- #reading_bytesize ⇒ Object
Constructor Details
#initialize(encoding, log, max_line_size = nil, encoding_to_convert = nil) ⇒ FIFO
Returns a new instance of FIFO.
1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/fluent/plugin/in_tail.rb', line 1044 def initialize(encoding, log, max_line_size=nil, encoding_to_convert=nil) @buffer = ''.force_encoding(encoding) @eol = "\n".encode(encoding).freeze @encoding_to_convert = encoding_to_convert @max_line_size = max_line_size @skip_current_line = false @skipping_current_line_bytesize = 0 @log = log end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
1054 1055 1056 |
# File 'lib/fluent/plugin/in_tail.rb', line 1054 def buffer @buffer end |
#max_line_size ⇒ Object (readonly)
Returns the value of attribute max_line_size.
1054 1055 1056 |
# File 'lib/fluent/plugin/in_tail.rb', line 1054 def max_line_size @max_line_size end |
Instance Method Details
#<<(chunk) ⇒ Object
1056 1057 1058 |
# File 'lib/fluent/plugin/in_tail.rb', line 1056 def <<(chunk) @buffer << chunk end |
#convert(s) ⇒ Object
1060 1061 1062 1063 1064 1065 1066 1067 1068 |
# File 'lib/fluent/plugin/in_tail.rb', line 1060 def convert(s) if @encoding_to_convert s.encode!(@encoding_to_convert) else s end rescue s.encode!(@encoding_to_convert, :invalid => :replace, :undef => :replace) end |
#read_lines(lines) ⇒ Object
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/fluent/plugin/in_tail.rb', line 1070 def read_lines(lines) idx = @buffer.index(@eol) has_skipped_line = false until idx.nil? # Using freeze and slice is faster than slice! # See https://github.com/fluent/fluentd/pull/2527 @buffer.freeze slice_position = idx + 1 rbuf = @buffer.slice(0, slice_position) @buffer = @buffer.slice(slice_position, @buffer.size - slice_position) idx = @buffer.index(@eol) is_long_line = @max_line_size && ( @skip_current_line || rbuf.bytesize > @max_line_size ) if is_long_line @log.warn "received line length is longer than #{@max_line_size}" if @skip_current_line @log.debug("The continuing line is finished. Finally discarded data: ") { convert(rbuf).chomp } else @log.debug("skipped line: ") { convert(rbuf).chomp } end has_skipped_line = true @skip_current_line = false @skipping_current_line_bytesize = 0 next end lines << convert(rbuf) end is_long_current_line = @max_line_size && ( @skip_current_line || @buffer.bytesize > @max_line_size ) if is_long_current_line @log.debug( "The continuing current line length is longer than #{@max_line_size}." + " The received data will be discarded until this line is finished." + " Discarded data: " ) { convert(@buffer).chomp } @skip_current_line = true @skipping_current_line_bytesize += @buffer.bytesize @buffer.clear end return has_skipped_line end |
#reading_bytesize ⇒ Object
1121 1122 1123 1124 |
# File 'lib/fluent/plugin/in_tail.rb', line 1121 def reading_bytesize return @skipping_current_line_bytesize if @skip_current_line @buffer.bytesize end |