Spaces:
Running
Running
File size: 586 Bytes
e92a066 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# utils/logger.py
import json
from datetime import datetime
from pathlib import Path
LOG_FILE = Path("logs.json")
def log_request(endpoint: str, query: str):
log_entry = {
"timestamp": datetime.utcnow().isoformat(),
"endpoint": endpoint,
"query": query
}
if not LOG_FILE.exists():
with open(LOG_FILE, "w") as f:
json.dump([log_entry], f, indent=2)
else:
with open(LOG_FILE, "r+") as f:
data = json.load(f)
data.append(log_entry)
f.seek(0)
json.dump(data, f, indent=2) |