Switch to systemd-boot, full log sending, and offline install fix

This commit is contained in:
2026-02-05 12:59:24 +01:00
parent e99290eebe
commit be674e89e0
3 changed files with 334 additions and 58 deletions

View File

@@ -11,25 +11,12 @@ DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1468696228647932280/L9XS
LOG_QUEUE = []
FULL_LOG = []
QUEUE_LOCK = threading.Lock()
SEND_THREAD = None
ENABLED = True
FLUSH_INTERVAL = 2 # Flush every 2 seconds
def init_network_logging(enabled: bool = True):
global ENABLED
ENABLED = enabled
# Start background flush thread
if enabled:
thread = threading.Thread(target=_background_flush, daemon=True)
thread.start()
def _background_flush():
"""Background thread to flush logs periodically"""
while True:
time.sleep(FLUSH_INTERVAL)
flush_logs()
def log_to_discord(level: str, message: str, module: str = "general"):
@@ -45,45 +32,12 @@ def log_to_discord(level: str, message: str, module: str = "general"):
}
with QUEUE_LOCK:
LOG_QUEUE.append(log_entry)
FULL_LOG.append(log_entry)
# Flush immediately for important events
if level.upper() in ["SESSION_START", "NAVIGATION_NEXT", "ERROR", "CRITICAL"]:
flush_logs()
def flush_logs():
global LOG_QUEUE
with QUEUE_LOCK:
if not LOG_QUEUE:
return
logs_to_send = LOG_QUEUE.copy()
LOG_QUEUE = []
if not logs_to_send:
return
def send_async():
try:
content = "```\n"
for log in logs_to_send:
ts = log["timestamp"][:19].replace("T", " ")
content += (
f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
)
if len(content) > 1800:
content += "```"
send_discord_message(content)
content = "```\n"
content += "```"
if len(content) > 10:
send_discord_message(content)
except Exception as e:
print(f"Failed to send logs to Discord: {e}")
thread = threading.Thread(target=send_async, daemon=True)
thread.start()
# Deprecated: No partial flushing anymore
pass
def send_full_log():
@@ -102,7 +56,7 @@ def send_full_log():
def send_sync():
try:
send_discord_message("--- FULL SESSION LOG START ---")
# send_discord_message("--- FULL SESSION LOG START ---")
content = "```\n"
for log in logs_to_send:
ts = log["timestamp"][:19].replace("T", " ")
@@ -117,15 +71,14 @@ def send_full_log():
content += "```"
send_discord_message(content)
send_discord_message("--- FULL SESSION LOG END ---")
# send_discord_message("--- FULL SESSION LOG END ---")
except Exception as e:
print(f"Failed to send full log to Discord: {e}")
# For full log, we can run it in a thread but wait for it if we're exiting?
# Usually better to wait a bit or just run it.
# For full log, we run it in a thread but wait for it
t = threading.Thread(target=send_sync)
t.start()
t.join(timeout=10)
t.join(timeout=30)
def send_discord_message(content: str):