diff --git a/aocsync.py b/aocsync.py index 8100d2b..0ef7156 100755 --- a/aocsync.py +++ b/aocsync.py @@ -477,7 +477,8 @@ class CargoAOCRunner: @staticmethod def run_benchmarks(repo_path: Path, year: int, user: str = "unknown", - repo_url: str = "", is_multi_year: bool = False) -> List[PerformanceResult]: + repo_url: str = "", is_multi_year: bool = False, + log_file: Optional[Path] = None) -> List[PerformanceResult]: """Run cargo aoc benchmarks and parse results Args: @@ -486,6 +487,7 @@ class CargoAOCRunner: user: User name for the results repo_url: Repository URL for linking is_multi_year: True if this is a multi-year repo (repo_path is already the year directory) + log_file: Optional path to log file to append cargo aoc output to """ results = [] repo_path = Path(repo_path) @@ -528,6 +530,26 @@ class CargoAOCRunner: timeout=300 # 5 minute timeout per day ) + # Write to log file if provided + if log_file: + timestamp = datetime.now().isoformat() + with open(log_file, 'a', encoding='utf-8') as f: + f.write(f"\n{'='*80}\n") + f.write(f"[{timestamp}] {user} - Year {year} - Day {day}\n") + f.write(f"Command: {' '.join(cmd)}\n") + f.write(f"Working Directory: {work_dir}\n") + f.write(f"Return Code: {result.returncode}\n") + f.write(f"{'='*80}\n") + if result.stdout: + f.write("STDOUT:\n") + f.write(result.stdout) + f.write("\n") + if result.stderr: + f.write("STDERR:\n") + f.write(result.stderr) + f.write("\n") + f.write(f"{'='*80}\n\n") + if result.returncode != 0: logger.warning(f"cargo aoc failed for day {day} in {work_dir}: {result.stderr}") continue @@ -549,9 +571,19 @@ class CargoAOCRunner: results.extend(day_results) except subprocess.TimeoutExpired: - logger.error(f"Timeout running cargo aoc for day {day}") + error_msg = f"Timeout running cargo aoc for day {day}" + logger.error(error_msg) + if log_file: + timestamp = datetime.now().isoformat() + with open(log_file, 'a', encoding='utf-8') as f: + f.write(f"\n[{timestamp}] ERROR: {error_msg}\n") except Exception as e: - logger.error(f"Error running cargo aoc for day {day}: {e}") + error_msg = f"Error running cargo aoc for day {day}: {e}" + logger.error(error_msg) + if log_file: + timestamp = datetime.now().isoformat() + with open(log_file, 'a', encoding='utf-8') as f: + f.write(f"\n[{timestamp}] ERROR: {error_msg}\n") return results @@ -1043,6 +1075,10 @@ class HTMLGenerator: for part in day.values(): users_with_data.update(part.keys()) + # Check if log file exists + log_file_path = Path(config.output_dir) / 'cargo-aoc.log' + log_file_exists = log_file_path.exists() + html = f"""
@@ -1445,6 +1481,7 @@ class HTMLGenerator:Users: """ + ', '.join(sorted(users)) + """
+ """ + (f'' if log_file_exists else '') + """