lib/fluent/plugin/exception_detector.rb in fluent-plugin-detect-exceptions-xiniaoyun-0.0.1 vs lib/fluent/plugin/exception_detector.rb in fluent-plugin-detect-exceptions-xiniaoyun-0.0.2

- old
+ new

@@ -235,14 +235,15 @@ # TraceAccumulator 'learns' the field name from the first record by checking # for some pre-defined common field names of text logs. # The named parameters max_lines and max_bytes limit the maximum amount # of data to be buffered. The default value 0 indicates 'no limit'. def initialize(message_field, languages, max_lines: 0, max_bytes: 0, - &emit_callback) + join_separator: '', &emit_callback) @exception_detector = Fluent::ExceptionDetector.new(*languages) @max_lines = max_lines @max_bytes = max_bytes + @join_separator = join_separator @message_field = message_field @messages = [] @buffer_start_time = Time.now @buffer_size = 0 @first_record = nil @@ -271,14 +272,11 @@ when 0 return when 1 @emit.call(@first_timestamp, @first_record) else - combined_message = @messages.each_with_object([]) do |line, memo| - memo << LINE_SEPARATOR unless memo.empty? || memo[-1].end_with?("\n") - memo << line - end.join + combined_message = @messages.join(@join_separator) if @message_field.nil? output_record = combined_message else output_record = @first_record output_record[@message_field] = combined_message @@ -334,10 +332,10 @@ end end def add(time_sec, record, message) if @messages.empty? - @first_record = record + @first_record = record unless @message_field.nil? @first_timestamp = time_sec @buffer_start_time = Time.now end unless message.nil? @messages << message