Update 2025-04-24_11:44:19

This commit is contained in:
oib
2025-04-24 11:44:23 +02:00
commit e748c737f4
3408 changed files with 717481 additions and 0 deletions

19
log.py Normal file
View File

@ -0,0 +1,19 @@
# log.py — Logging of abuse or violations in dicta2stream
from datetime import datetime
import os
from datetime import datetime
def log_violation(event: str, ip: str, uid: str, reason: str):
timestamp = datetime.utcnow().isoformat()
log_dir = os.path.join(os.path.dirname(__file__), "log")
os.makedirs(log_dir, exist_ok=True)
log_path = os.path.join(log_dir, "log.txt")
log_entry = f"[{timestamp}] {event} IP={ip} UID={uid} REASON={reason}\n"
with open(log_path, "a") as f:
f.write(log_entry)
# If DEBUG mode, also print to stdout
if os.getenv("DEBUG", "0") in ("1", "true", "True"): # Set DEBUG=1 in .env to enable
print(f"[DEBUG] {log_entry.strip()}")