You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
512 B

import os
import json
from datetime import datetime
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LOG_DIR = os.path.join(BASE_DIR, "logs")
LOG_FILE = os.path.join(LOG_DIR, "app.log")
def log_event(data: dict):
try:
os.makedirs(LOG_DIR, exist_ok=True)
data["timestamp"] = datetime.utcnow().isoformat()
with open(LOG_FILE, "a") as f:
f.write(json.dumps(data) + "\n")
except Exception as e:
print(f"❌ Logging failed: {e}")