Analyze downloaded logs for errors. Args: log_file: Path to downloaded log file
(self, log_file: Path)
| 304 | return None |
| 305 | |
| 306 | def analyze_logs(self, log_file: Path) -> None: |
| 307 | """Analyze downloaded logs for errors. |
| 308 | |
| 309 | Args: |
| 310 | log_file: Path to downloaded log file |
| 311 | """ |
| 312 | print(f"Analyzing logs from: {log_file}\n") |
| 313 | |
| 314 | try: |
| 315 | with open(log_file, "r", encoding="utf-8") as f: |
| 316 | lines = f.readlines() |
| 317 | |
| 318 | # Process logs line by line |
| 319 | error_buffer: list[str] = [] |
| 320 | context_buffer: list[str] = [] |
| 321 | in_error_context = False |
| 322 | lines_after_error = 0 |
| 323 | current_job = "Unknown" |
| 324 | |
| 325 | for line in lines: |
| 326 | line = line.rstrip() |
| 327 | |
| 328 | # Extract job name from log line |
| 329 | job_match = re.match(r"^([\w\s/]+)\t", line) |
| 330 | if job_match: |
| 331 | current_job = job_match.group(1).strip() |
| 332 | |
| 333 | # Keep context buffer |
| 334 | context_buffer.append(line) |
| 335 | if len(context_buffer) > self.context_lines: |
| 336 | context_buffer.pop(0) |
| 337 | |
| 338 | # Check if line should be excluded (tool warnings) |
| 339 | is_excluded = any( |
| 340 | re.search(pattern, line, re.IGNORECASE) |
| 341 | for pattern in self.EXCLUDE_PATTERNS |
| 342 | ) |
| 343 | |
| 344 | # Check if line matches error pattern |
| 345 | is_error = any( |
| 346 | re.search(pattern, line, re.IGNORECASE) |
| 347 | for pattern in self.ERROR_PATTERNS |
| 348 | ) |
| 349 | |
| 350 | # Check if line matches critical pattern |
| 351 | is_critical = any( |
| 352 | re.search(pattern, line, re.IGNORECASE) |
| 353 | for pattern in self.CRITICAL_PATTERNS |
| 354 | ) |
| 355 | |
| 356 | if is_error and not in_error_context: |
| 357 | # Start new error context |
| 358 | in_error_context = True |
| 359 | lines_after_error = 0 |
| 360 | |
| 361 | # Add context before error |
| 362 | error_buffer.extend(context_buffer[:-1]) # All but current line |
| 363 | error_buffer.append(line) |
no test coverage detected