Spaces:
Sleeping
Sleeping
| import time | |
| import json | |
| import os | |
| class Telemetry: | |
| def __init__(self, agent_id): | |
| self.agent_id = agent_id | |
| self.log_file = f"telemetry_{agent_id}.json" | |
| self._init_log() | |
| def _init_log(self): | |
| if not os.path.exists(self.log_file): | |
| with open(self.log_file, "w") as f: | |
| json.dump({"events": []}, f) | |
| def log(self, event_type, status, details=None): | |
| if details is None: | |
| details = {} | |
| entry = { | |
| "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), | |
| "event_type": event_type, | |
| "status": status, | |
| "details": details, | |
| } | |
| with open(self.log_file, "r") as f: | |
| data = json.load(f) | |
| data["events"].append(entry) | |
| with open(self.log_file, "w") as f: | |
| json.dump(data, f, indent=2) | |
| print(f"[Telemetry] {event_type} - {status} | {details}") |