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 <noreply@anthropic.com>
This commit is contained in:
parent
f954b7ee38
commit
2f88eb119d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.env
|
.env
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
logs/
|
||||||
|
|||||||
29
run.py
29
run.py
@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", line_buffering=True)
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", line_buffering=True)
|
||||||
|
|
||||||
from airtable_client import AirtableClient
|
from airtable_client import AirtableClient
|
||||||
@ -11,6 +12,26 @@ import config
|
|||||||
from datetime import datetime
|
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 = {
|
ICONOS = {
|
||||||
"PAUSAR": "⛔",
|
"PAUSAR": "⛔",
|
||||||
"SPRINT": "🚀",
|
"SPRINT": "🚀",
|
||||||
@ -115,4 +136,12 @@ def run():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
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()
|
run()
|
||||||
|
finally:
|
||||||
|
tee.close()
|
||||||
|
print(f"\nLog guardado en: {log_path}", file=tee._stdout)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user