Spaces:
Sleeping
Sleeping
File size: 924 Bytes
2376461 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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}") |