| 59 | self.current_line_content = "" # Represents the current state of the line to be logged |
| 60 | |
| 61 | def write(self, data_chunk): |
| 62 | self.original_stream.write(data_chunk) # Pass through to console |
| 63 | |
| 64 | if data_chunk.endswith("\\r") and "\\n" not in data_chunk: |
| 65 | self.current_line_content = data_chunk[:-1] # Store without the trailing \\r |
| 66 | return |
| 67 | |
| 68 | full_buffer = self.current_line_content + data_chunk |
| 69 | lines_to_process = full_buffer.split("\\n") |
| 70 | |
| 71 | for i in range(len(lines_to_process) - 1): |
| 72 | line = lines_to_process[i] |
| 73 | final_content_of_line = line |
| 74 | last_cr = line.rfind("\\r") |
| 75 | if last_cr != -1: |
| 76 | final_content_of_line = line[last_cr + 1 :] |
| 77 | |
| 78 | escaped_log = final_content_of_line.replace("{", "{{").replace("}", "}}") |
| 79 | if final_content_of_line.strip() or line: |
| 80 | self.log_method(escaped_log, raw=True) |
| 81 | |
| 82 | self.current_line_content = lines_to_process[-1] |
| 83 | |
| 84 | def flush(self): |
| 85 | self.original_stream.flush() |