From 62d0af9fe38b19a372d7288800aca1bcc0337dc6 Mon Sep 17 00:00:00 2001 From: Vitali Graf Date: Sun, 28 Dec 2025 13:59:05 +0100 Subject: [PATCH] Feature: Log-Ausgabe in Datei und Konsole MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Erweitert Logging-Konfiguration für besseres Debugging: Änderungen: - Logs werden in Datei UND Konsole ausgegeben - Log-Datei: ~/.config/DocuMentor/logs/documentor_TIMESTAMP.log - Konsole: Nur INFO und höher (für Live-Monitoring) - Datei: Alles ab DEBUG (für detaillierte Analyse) - Automatischer Timestamp im Dateinamen - UTF-8 Encoding für deutsche Umlaute Log-Verzeichnis: - Linux: ~/.config/DocuMentor/logs/ - Windows: %APPDATA%\DocuMentor\logs\ - macOS: ~/Library/Application Support/DocuMentor/logs/ Beispiel: documentor_20251228_134000.log Nützlich für: - Performance-Analyse des Saxon-Worker-Pools - Debugging von Transformations-Problemen - Nachverfolgung von Batch-Operationen 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/main.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 0c2599c..c1a1b31 100644 --- a/src/main.py +++ b/src/main.py @@ -10,12 +10,39 @@ from conf import app_settings def main(): """Haupteinstiegspunkt der Anwendung.""" - # Logging konfigurieren - logging.basicConfig( - level=logging.DEBUG, - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - datefmt='%H:%M:%S' - ) + # Logging konfigurieren - sowohl Datei als auch Konsole + from datetime import datetime + + # Log-Verzeichnis erstellen (im selben Verzeichnis wie config.json) + from conf import config_path + + log_dir = config_path.parent / "logs" + log_dir.mkdir(exist_ok=True) + + # Log-Dateiname mit Timestamp + timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + log_file = log_dir / f"documentor_{timestamp}.log" + + # Root-Logger konfigurieren + logger = logging.getLogger() + logger.setLevel(logging.DEBUG) + + # Formatter für alle Handler + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%H:%M:%S") + + # Handler 1: Datei (alles ab DEBUG) + file_handler = logging.FileHandler(log_file, encoding="utf-8") + file_handler.setLevel(logging.DEBUG) + file_handler.setFormatter(formatter) + logger.addHandler(file_handler) + + # Handler 2: Konsole (alles ab INFO) + console_handler = logging.StreamHandler(sys.stdout) + console_handler.setLevel(logging.INFO) + console_handler.setFormatter(formatter) + logger.addHandler(console_handler) + + logging.info(f"Logging initialisiert: {log_file}") # QApplication-Instanz erstellen app = QApplication(sys.argv)