feat: implement unified logging system for GUI components

Add centralized logging mechanism that simultaneously outputs to console
and GUI log components, improving code maintainability and consistency.

Changes:
- Add gui/log_config.py for centralized logging configuration
- Add gui/widgets/log_handler.py as bridge between logging and LogText
- Integrate unified logging into DataExtractionTab and MaterialValidationTab
- Initialize logging system in MainWindow on startup
- Improve error messages in material_status_validator for empty results
- Add documentation for logging mechanism and refactoring

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-24 20:31:59 +08:00
parent 3c45ef58d1
commit 24053c6a3b
9 changed files with 821 additions and 24 deletions

43
gui/log_config.py Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
GUI 日志配置模块
统一配置 GUI 应用和控制台的日志输出
"""
import logging
# 日志格式配置
LOG_FORMAT = '%(asctime)s [%(levelname)s] %(message)s'
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
def setup_gui_logging(level=logging.INFO):
"""
初始化 GUI 应用的日志配置
Args:
level: 日志级别,默认为 INFO
Returns:
logging.Logger: 根 logger
"""
logging.basicConfig(
level=level,
format=LOG_FORMAT,
datefmt=DATE_FORMAT,
force=True # 确保重新配置(即使之前配置过)
)
return logging.getLogger()
def get_logger(name):
"""
获取指定名称的 logger
Args:
name: logger 名称,通常使用 __name__
Returns:
logging.Logger: logger 实例
"""
return logging.getLogger(name)