Exception handling improved

This commit is contained in:
Dirk Alders 2025-08-01 07:32:23 +02:00
parent 554f19fc6c
commit c10d8911ce

View File

@ -1,6 +1,6 @@
import logging
import os
import pickle
import re
import socket
import struct
import threading
@ -12,6 +12,10 @@ from textual.widgets import Footer, Header, Input, RichLog, Checkbox, Select
from mytui import MultiSelect
# File for logging errors
LOG_FILE = os.path.join(os.path.dirname(__file__), 'error.log')
logging.basicConfig(filename=LOG_FILE, level=logging.ERROR, format="%(message)s", filemode="w")
# Mapping von Log-Level-Namen zu Farben für die Anzeige
LEVEL_STYLES = {
"CRITICAL": "bold white on red",
@ -54,8 +58,8 @@ class LogReceiver(threading.Thread):
self.app.call_from_thread(self.app.add_log, log_record)
except Exception as e:
logging.basicConfig(filename="server_error.log", level=logging.DEBUG)
logging.error(f"LogReceiver-Fehler: {e}", exc_info=True)
logging.exception("LogReceiver-Error...")
self.app.exit(return_code=1)
class LogViewerApp(App):
@ -174,3 +178,6 @@ class LogViewerApp(App):
if __name__ == "__main__":
app = LogViewerApp()
app.run()
if app.return_code != 0:
with open(LOG_FILE, "r") as fh:
print(fh.read())