diff --git a/src/__init__.py b/src/__init__.py index c0077af..b3ea362 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,10 +1,11 @@ """ -pliblog - 简易,现代化具有色彩的日志记录器 / Easy, Modern and colorful Logger +py-logiliteal - 简易,现代化具有色彩的日志记录器 +py-logiliteal's config settings, used to set py-logiliteal's global config """ # encoding = utf-8 # python 3.13.5 -from .utils import get_config, set_config, reset_config, get_asctime, get_date, get_time, get_weekday, fmt_console, fmt_placeholder, fmt_message, fmt_level_name +from .utils import get_config, set_config, reset_config, get_asctime, get_date, get_time, get_weekday, fmt_console, fmt_placeholder, fmt_message, fmt_level_name, get_style, set_style, reset_style from .levels import Logger __all__ = [ @@ -19,5 +20,7 @@ __all__ = [ "fmt_placeholder", "fmt_message", "fmt_level_name", - "Logger" + "set_color", + "set_bg_color", + "Logger" # 日志记录器非实例化 ] \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py index b956acf..3ac00f7 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,5 +1,6 @@ """ -工具函数 / Utility functions +工具函数 +Utility functions """ # encoding = utf-8 # python 3.13.5 @@ -7,6 +8,7 @@ from .configs import get_config, set_config, reset_config from .time import get_asctime, get_date, get_time, get_weekday from .fmt import fmt_console, fmt_placeholder, fmt_message, fmt_level_name +from .styles import set_color, set_bg_color __all__ = [ "get_config", @@ -20,4 +22,6 @@ __all__ = [ "fmt_placeholder", "fmt_message", "fmt_level_name", + "set_color", + "set_bg_color", ] \ No newline at end of file diff --git a/src/utils/configs.py b/src/utils/configs.py index c7d2cfb..d2abb78 100644 --- a/src/utils/configs.py +++ b/src/utils/configs.py @@ -1,6 +1,6 @@ """ -pliblog的配置设置,用于设置pliblog的全局配置 -pliblog's config settings, used to set pliblog's global config +py-logiliteal的配置设置,用于设置py-logiliteal的全局配置 +py-logiliteal's config settings, used to set py-logiliteal's global config """ # encoding = utf-8 @@ -26,7 +26,7 @@ DEFAULT_CONFIG = { } from typing import Union, Optional -import logging +from logging import error, info import json def get_config(select: str = None) -> Union[dict, str, bool, int, None]: @@ -48,10 +48,10 @@ def get_config(select: str = None) -> Union[dict, str, bool, int, None]: return DEFAULT_CONFIG[select] return DEFAULT_CONFIG except KeyError as e: - logging.error(f"配置项 '{select}' 不存在") + error(f"配置项 '{select}' 不存在") return None except Exception as e: - logging.error(f"读取配置文件失败: {e}") + error(f"读取配置文件失败: {e}") return None import shutil @@ -84,7 +84,7 @@ def set_config(select: str, value: Union[dict, str, bool, int, None]) -> tuple[b with open(DEFAULT_CONFIG_PATH, "r", encoding="utf-8") as f: verify_config = json.load(f) if verify_config.get(select) != value: - + error(f"配置项 '{select}' 设置失败,值为 {value}") shutil.move(backup_path, DEFAULT_CONFIG_PATH) return False, f"配置项 '{select}' 设置失败,已恢复备份" @@ -92,13 +92,13 @@ def set_config(select: str, value: Union[dict, str, bool, int, None]) -> tuple[b return True, f"配置项 '{select}' 设置成功" except json.JSONDecodeError as e: - logging.error(f"配置文件格式错误: {e}") + error(f"配置文件格式错误: {e}") return False, f"配置文件格式错误: {str(e)}" except PermissionError: - logging.error(f"没有权限操作配置文件: {DEFAULT_CONFIG_PATH}") + error(f"没有权限操作配置文件: {DEFAULT_CONFIG_PATH}") return False, "没有权限操作配置文件" except Exception as e: - logging.error(f"设置配置文件失败: {e}") + error(f"设置配置文件失败: {e}") if Path(backup_path).exists(): shutil.move(backup_path, DEFAULT_CONFIG_PATH) @@ -128,11 +128,11 @@ def reset_config() -> tuple[bool, Optional[str]]: json.dump(DEFAULT_CONFIG, f, indent=4) return True except PermissionError: - logging.error(f"权限不足,无法操作配置文件: {DEFAULT_CONFIG_PATH}") + error(f"权限不足,无法操作配置文件: {DEFAULT_CONFIG_PATH}") return False, "权限不足,无法重置配置" except json.JSONDecodeError: - logging.error("配置文件格式错误,无法解析") + error("配置文件格式错误,无法解析") return False, "配置文件格式错误,无法重置" except Exception as e: - logging.error(f"重置配置文件失败: {e}") + error(f"重置配置文件失败: {e}") return False, f"重置配置失败: {str(e)}" diff --git a/src/utils/fmt.py b/src/utils/fmt.py index 5e46a72..942cfa2 100644 --- a/src/utils/fmt.py +++ b/src/utils/fmt.py @@ -1,6 +1,6 @@ """ -pliblog的格式化工具,用于格式化日志输出 -pliblog's formatter, used to format log output +py-logiliteal的格式化工具,用于格式化日志输出 +py-logiliteal's formatter, used to format log output """ # encoding = utf-8 diff --git a/src/utils/styles.py b/src/utils/styles.py index 82e2f70..2996f4c 100644 --- a/src/utils/styles.py +++ b/src/utils/styles.py @@ -1,6 +1,6 @@ """ -pliblog的样式工具,用于格式化日志输出 -pliblog's style tools, used to format log output +py-logiliteal的样式工具,用于格式化日志输出 +py-logiliteal's style tools, used to format log output """ # encoding = utf-8