# -*- coding: utf-8 -*- """ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/27 上午9:12 @Author : snowykami @Email : snowykami@outlook.com @File : log.py @Software: PyCharm """ import sys import loguru logger = loguru.logger # DEBUG日志格式 debug_format: str = ( "{time:YYYY-MM-DD HH:mm:ss} " "[{level.icon}] " "<{name}.{module}.{function}:{line}> " "{message}" ) # 默认日志格式 default_format: str = ( "{time:MM-DD HH:mm:ss} " "[{level.icon}] " "<{name}> " "{message}" ) def get_format(level: str) -> str: if level == "DEBUG": return debug_format else: return default_format def init_log(config: dict): """ 在语言加载完成后执行 Returns: """ logger.remove() logger.add( sys.stdout, level=0, diagnose=False, format=get_format(config.get("log_level", "INFO")), ) show_icon = config.get("log_icon", True) logger.level("DEBUG", color="", icon=f"{'🐛' if show_icon else ''}试") logger.level("INFO", color="", icon=f"{'ℹ️' if show_icon else ''}讯") logger.level("SUCCESS", color="", icon=f"{'✅' if show_icon else ''}警") logger.level("WARNING", color="", icon=f"{'⚠️' if show_icon else ''}误") logger.level("ERROR", color="", icon=f"{'⭕' if show_icon else ''}成") init_log(config={})