mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 07:23:03 +08:00
feat(LogManager): 新增日志持久化功能
- 新增 LogManager 单例类,支持日志文件按日期滚动 - 创建 CallerInfoFormatter 自定义格式化器,提取真实调用位置 - 为 MsgBase._showTrace 方法添加日志级别参数,集成日志系统 - 新增 initializeLogManager 初始化函数,日志存储于 AppDataLocation/logs/ - 日志输出格式对齐:[时间] - [类名(15)|级别(8)] - [文件:行号(20:4)] - 消息 - 控制台/INFO级别,全量日志 / DEBUG 级别,错误日志 / ERROR级别 - 全量日志保留7天,错误日志保留14天
This commit is contained in:
+11
-1
@@ -7,9 +7,12 @@ This software is provided "as is", without any warranty of any kind.
|
||||
You may use, modify, and distribute this file under the terms of the MIT License.
|
||||
See the LICENSE file for details.
|
||||
"""
|
||||
import logging
|
||||
import queue
|
||||
import datetime
|
||||
|
||||
from utils.LogManager import getLogger
|
||||
|
||||
|
||||
class MsgBase:
|
||||
"""
|
||||
@@ -38,6 +41,10 @@ class MsgBase:
|
||||
self._class_name = self.__class__.__name__
|
||||
self._input_queue = input_queue
|
||||
self._output_queue = output_queue
|
||||
try:
|
||||
self._logger = getLogger(self._class_name)
|
||||
except RuntimeError:
|
||||
self._logger = None
|
||||
|
||||
|
||||
def _showMsg(
|
||||
@@ -50,11 +57,14 @@ class MsgBase:
|
||||
|
||||
def _showTrace(
|
||||
self,
|
||||
msg: str
|
||||
msg: str,
|
||||
level: int = logging.INFO
|
||||
):
|
||||
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
||||
self._output_queue.put(f"{timestamp}-[{self._class_name:<15}] : {msg}")
|
||||
if self._logger:
|
||||
self._logger.log(level, msg)
|
||||
|
||||
|
||||
def _waitMsg(
|
||||
|
||||
Reference in New Issue
Block a user