From 2f88eb119dea0f1baaf6740ed1eaf4e957dd9a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20G=C3=B3mez?= Date: Fri, 17 Apr 2026 16:13:43 +0200 Subject: [PATCH] Add execution logging to logs/ directory Each run saves a timestamped log file (logs/YYYYMMDD_HHMMSS.log) with full output. logs/ is gitignored. Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 1 + run.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cff5543..2bb5881 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env __pycache__/ *.pyc +logs/ diff --git a/run.py b/run.py index c6355e1..ab5d42b 100644 --- a/run.py +++ b/run.py @@ -1,5 +1,6 @@ import sys import io +import os sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", line_buffering=True) from airtable_client import AirtableClient @@ -11,6 +12,26 @@ import config from datetime import datetime +class Tee: + """Escribe simultáneamente en consola y en archivo de log.""" + def __init__(self, filepath): + os.makedirs(os.path.dirname(filepath), exist_ok=True) + self._file = open(filepath, "w", encoding="utf-8") + self._stdout = sys.stdout + + def write(self, data): + self._stdout.write(data) + self._file.write(data) + + def flush(self): + self._stdout.flush() + if not self._file.closed: + self._file.flush() + + def close(self): + self._file.close() + + ICONOS = { "PAUSAR": "⛔", "SPRINT": "🚀", @@ -115,4 +136,12 @@ def run(): if __name__ == "__main__": - run() + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + log_path = os.path.join("logs", f"{timestamp}.log") + tee = Tee(log_path) + sys.stdout = tee + try: + run() + finally: + tee.close() + print(f"\nLog guardado en: {log_path}", file=tee._stdout)