Capture logs

This commit is contained in:
Bill Thiede 2025-12-04 10:21:29 -08:00
parent 09dabcab66
commit e800d681ae

View File

@ -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"""<!DOCTYPE html>
<html lang="en">
<head>
@ -1445,6 +1481,7 @@ class HTMLGenerator:
<div class="controls">
<p><strong>Users:</strong> """ + ', '.join(sorted(users)) + """</p>
""" + (f'<p><a href="cargo-aoc.log" target="_blank">📋 View Cargo AOC Logs</a></p>' if log_file_exists else '') + """
</div>
"""
@ -1798,8 +1835,12 @@ class AOCSync:
repo_url: str = "", is_multi_year: bool = False):
"""Run benchmarks and store results"""
logger.info(f"Running benchmarks for {user} year {year} in {repo_path}")
# Create log file path in output directory
log_file = Path(self.config.output_dir) / 'cargo-aoc.log'
log_file.parent.mkdir(parents=True, exist_ok=True)
results = CargoAOCRunner.run_benchmarks(repo_path, year=year, user=user,
repo_url=repo_url, is_multi_year=is_multi_year)
repo_url=repo_url, is_multi_year=is_multi_year,
log_file=log_file)
# Store results
for result in results:
@ -1846,6 +1887,7 @@ class AOCSync:
try:
# Build rsync command
# Use trailing slash on source to sync contents, not the directory itself
# This will include all files including cargo-aoc.log
source = str(output_dir) + "/"
cmd = ['rsync', '-avz', '--delete', source, destination]