|
10 | 10 | from typing import Optional, List |
11 | 11 | from collections import deque |
12 | 12 |
|
| 13 | +from webqa_agent.utils.get_log import COLORS |
| 14 | + |
13 | 15 |
|
14 | 16 | @dataclass |
15 | 17 | class TaskInfo: |
@@ -75,6 +77,8 @@ def __init__(self, refresh_interval: float = 0.1): |
75 | 77 | hdr.setStream(self.captured_output) |
76 | 78 | self.logger_handlers.append(hdr) |
77 | 79 |
|
| 80 | + self.log_pattern = re.compile(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d+)(\s+)(\w+)(\s+\[.*?]\s+\[.*?]\s+-\s+)(.*)") |
| 81 | + |
78 | 82 | def __call__(self, name: str): |
79 | 83 | return _Tracker(self, name) |
80 | 84 |
|
@@ -128,9 +132,20 @@ def _render_frame(self): |
128 | 132 | out.write("-" * col + "\n") |
129 | 133 | length = min(self.num_log, len(lines)) |
130 | 134 | for ln in range(length): |
131 | | - line = remove_ansi_escape_sequences(str(lines[-length + ln])) |
132 | | - if len(line) >= col: |
133 | | - out.write(f"{line[:col-3]}"+"...\n") |
| 135 | + line = lines[-length + ln] |
| 136 | + _line = remove_ansi_escape_sequences(str(line)) |
| 137 | + if len(_line) >= col: |
| 138 | + match = self.log_pattern.search(_line[:col - 3]) |
| 139 | + if match: |
| 140 | + timestamp, space1, loglevel, middle, message = match.groups() |
| 141 | + color = COLORS[loglevel] |
| 142 | + end = COLORS['ENDC'] |
| 143 | + colored_loglevel = f"{color}{loglevel}{end}" |
| 144 | + colored_message = f"{color}{message}{end}" |
| 145 | + _line = f"{timestamp}{space1}{colored_loglevel}{middle}{colored_message}" |
| 146 | + out.write(f"{_line}" + "...\n") |
| 147 | + else: |
| 148 | + out.write(f"{_line[:col-3]}"+"...\n") |
134 | 149 | else: |
135 | 150 | out.write(line + "\n") |
136 | 151 | out.flush() |
|
0 commit comments