- if stderr_buf
- j[:stderr_buf] << stderr_buf
- if j[:stderr_buf].index "\n"
- lines = j[:stderr_buf].lines("\n").to_a
- if j[:stderr_buf][-1] == "\n"
- j[:stderr_buf] = ''
- else
- j[:stderr_buf] = lines.pop
- end
- lines.each do |line|
- $stderr.print "#{job_uuid} ! " unless line.index(job_uuid)
- $stderr.puts line
- pub_msg = "#{Time.now.ctime.to_s} #{line.strip} \n"
- if not j[:log_truncated]
- j[:stderr_buf_to_flush] << pub_msg
+ if buf
+ # Add to a the buffer
+ streambuf << buf
+
+ # Check for at least one complete line
+ if streambuf.index "\n"
+ lines = streambuf.lines("\n").to_a
+
+ # check if the last line is partial or not
+ j[:buf][stream] = if streambuf[-1] == "\n"
+ # nope
+ ''
+ else
+ # Put the partial line back into the buffer
+ lines.pop
+ end
+
+ # Now spool the lines to the log output buffer
+ lines.each do |line|
+ $stderr.print "#{job_uuid} ! " unless line.index(job_uuid)
+ $stderr.puts line
+ pub_msg = "#{Time.now.ctime.to_s} #{line.strip} \n"
+ if not j[:log_truncated]
+ j[:stderr_buf_to_flush] << pub_msg
+ end