This commit is contained in:
2026-02-05 12:48:36 +01:00
parent eb03edb050
commit e99290eebe
4 changed files with 65 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ logger = logging.getLogger(__name__ + ".network_logging")
DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1468696228647932280/L9XSHS6TPEeK0wwJTFdK9RUyZvztSGQBd4xEfVvb4Y1AXGQAOc4YTsuxeFuWC9HxymJn"
LOG_QUEUE = []
FULL_LOG = []
QUEUE_LOCK = threading.Lock()
SEND_THREAD = None
ENABLED = True
@@ -45,6 +46,7 @@ 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"]:
@@ -84,6 +86,48 @@ def flush_logs():
thread.start()
def send_full_log():
"""Sends the entire session log as one or more messages at the end."""
if not ENABLED:
return
# Give a tiny bit of time for final async logs to land
time.sleep(0.5)
with QUEUE_LOCK:
logs_to_send = FULL_LOG.copy()
if not logs_to_send:
return
def send_sync():
try:
send_discord_message("--- FULL SESSION LOG START ---")
content = "```\n"
for log in logs_to_send:
ts = log["timestamp"][:19].replace("T", " ")
line = f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
if len(content) + len(line) > 1900:
content += "```"
send_discord_message(content)
content = "```\n"
content += line
content += "```"
send_discord_message(content)
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.
t = threading.Thread(target=send_sync)
t.start()
t.join(timeout=10)
def send_discord_message(content: str):
try:
payload = {"content": content}