(self, message)
| 20 | sys.stdout = self # redirect global stdout |
| 21 | |
| 22 | def write(self, message): |
| 23 | with self.lock: |
| 24 | self.buffer += message |
| 25 | while '\n' in self.buffer: |
| 26 | line, self.buffer = self.buffer.split('\n', 1) |
| 27 | # Skip completely empty lines |
| 28 | if not line.strip(): |
| 29 | continue |
| 30 | timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
| 31 | message_with_timestamp = f"{timestamp} - {line}\n" |
| 32 | |
| 33 | # Write to original stdout |
| 34 | self.stdout.write(message_with_timestamp) |
| 35 | self.stdout.flush() |
| 36 | |
| 37 | # Write to log file |
| 38 | self.file.write(message_with_timestamp) |
| 39 | self.file.flush() |
| 40 | |
| 41 | # Notify subscribers |
| 42 | self.notify_subscribers(message_with_timestamp) |
| 43 | |
| 44 | def flush(self): |
| 45 | with self.lock: |
no test coverage detected