feat: 接入logger

This commit is contained in:
DLmaster361
2025-08-04 10:46:23 +08:00
parent 92ea6026f8
commit 76438459f7
10 changed files with 45 additions and 222 deletions

View File

View File

@@ -23,6 +23,5 @@ __author__ = "DLmaster361 <DLmaster_361@163.com>"
__license__ = "GPL-3.0 license"
from .config import Config
from .logger import logger
__all__ = ["Config", "logger"]
__all__ = ["Config"]

View File

@@ -34,7 +34,7 @@ from pathlib import Path
from typing import Union, Dict, List, Literal
from .logger import logger
from app.utils import get_logger
from app.models.ConfigBase import *
@@ -593,7 +593,13 @@ class AppConfig(GlobalConfig):
# self.if_ignore_silence = False
# self.if_database_opened = False
self.init_logger()
self.logger = get_logger("配置管理")
self.logger.info("")
self.logger.info("===================================")
self.logger.info("AUTO_MAA 后端应用程序")
self.logger.info(f"版本号: v{self.VERSION}")
self.logger.info(f"根目录: {self.root_path}")
self.logger.info("===================================")
# 检查目录
self.log_path.parent.mkdir(parents=True, exist_ok=True)
@@ -616,38 +622,7 @@ class AppConfig(GlobalConfig):
await self.QueueConfig.connect(self.config_path / "QueueConfig.json")
# self.check_data()
logger.info("程序初始化完成", module="配置管理")
def init_logger(self) -> None:
"""初始化日志记录器"""
logger.add(
sink=self.log_path,
level="DEBUG",
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{extra[module]}</cyan> | <level>{message}</level>",
enqueue=True,
backtrace=True,
diagnose=True,
rotation="1 week",
retention="1 month",
compression="zip",
)
logger.add(
sink=sys.stderr,
level="DEBUG",
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{extra[module]}</cyan> | <level>{message}</level>",
enqueue=True,
backtrace=True,
diagnose=True,
colorize=True,
)
logger.info("", module="配置管理")
logger.info("===================================", module="配置管理")
logger.info("AUTO_MAA 后端", module="配置管理")
logger.info(f"版本号: v{self.VERSION}", module="配置管理")
logger.info(f"根目录: {self.root_path}", module="配置管理")
logger.info("===================================", module="配置管理")
self.logger.info("程序初始化完成")
async def add_script(
self, script: Literal["MAA", "General"]

View File

@@ -1,25 +0,0 @@
# AUTO_MAA:A MAA Multi Account Management and Automation Tool
# Copyright © 2024-2025 DLmaster361
# This file is part of AUTO_MAA.
# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.
# Contact: DLmaster_361@163.com
from loguru import logger as _logger
logger = _logger.patch(lambda record: record["extra"].setdefault("module", "未知模块"))
logger.remove(0)