mirror of
https://github.com/Nanaloveyuki/py-logiliteal.git
synced 2025-09-05 11:06:22 +00:00
🚚 重命名pliblog
到py-logiliteal
This commit is contained in:
@ -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
|
# encoding = utf-8
|
||||||
# python 3.13.5
|
# 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
|
from .levels import Logger
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -19,5 +20,7 @@ __all__ = [
|
|||||||
"fmt_placeholder",
|
"fmt_placeholder",
|
||||||
"fmt_message",
|
"fmt_message",
|
||||||
"fmt_level_name",
|
"fmt_level_name",
|
||||||
"Logger"
|
"set_color",
|
||||||
|
"set_bg_color",
|
||||||
|
"Logger" # 日志记录器非实例化
|
||||||
]
|
]
|
@ -1,5 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
工具函数 / Utility functions
|
工具函数
|
||||||
|
Utility functions
|
||||||
"""
|
"""
|
||||||
# encoding = utf-8
|
# encoding = utf-8
|
||||||
# python 3.13.5
|
# python 3.13.5
|
||||||
@ -7,6 +8,7 @@
|
|||||||
from .configs import get_config, set_config, reset_config
|
from .configs import get_config, set_config, reset_config
|
||||||
from .time import get_asctime, get_date, get_time, get_weekday
|
from .time import get_asctime, get_date, get_time, get_weekday
|
||||||
from .fmt import fmt_console, fmt_placeholder, fmt_message, fmt_level_name
|
from .fmt import fmt_console, fmt_placeholder, fmt_message, fmt_level_name
|
||||||
|
from .styles import set_color, set_bg_color
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"get_config",
|
"get_config",
|
||||||
@ -20,4 +22,6 @@ __all__ = [
|
|||||||
"fmt_placeholder",
|
"fmt_placeholder",
|
||||||
"fmt_message",
|
"fmt_message",
|
||||||
"fmt_level_name",
|
"fmt_level_name",
|
||||||
|
"set_color",
|
||||||
|
"set_bg_color",
|
||||||
]
|
]
|
@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
pliblog的配置设置,用于设置pliblog的全局配置
|
py-logiliteal的配置设置,用于设置py-logiliteal的全局配置
|
||||||
pliblog's config settings, used to set pliblog's global config
|
py-logiliteal's config settings, used to set py-logiliteal's global config
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# encoding = utf-8
|
# encoding = utf-8
|
||||||
@ -26,7 +26,7 @@ DEFAULT_CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
import logging
|
from logging import error, info
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def get_config(select: str = None) -> Union[dict, str, bool, int, None]:
|
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[select]
|
||||||
return DEFAULT_CONFIG
|
return DEFAULT_CONFIG
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logging.error(f"配置项 '{select}' 不存在")
|
error(f"配置项 '{select}' 不存在")
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"读取配置文件失败: {e}")
|
error(f"读取配置文件失败: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
import shutil
|
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:
|
with open(DEFAULT_CONFIG_PATH, "r", encoding="utf-8") as f:
|
||||||
verify_config = json.load(f)
|
verify_config = json.load(f)
|
||||||
if verify_config.get(select) != value:
|
if verify_config.get(select) != value:
|
||||||
|
error(f"配置项 '{select}' 设置失败,值为 {value}")
|
||||||
shutil.move(backup_path, DEFAULT_CONFIG_PATH)
|
shutil.move(backup_path, DEFAULT_CONFIG_PATH)
|
||||||
return False, f"配置项 '{select}' 设置失败,已恢复备份"
|
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}' 设置成功"
|
return True, f"配置项 '{select}' 设置成功"
|
||||||
|
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
logging.error(f"配置文件格式错误: {e}")
|
error(f"配置文件格式错误: {e}")
|
||||||
return False, f"配置文件格式错误: {str(e)}"
|
return False, f"配置文件格式错误: {str(e)}"
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logging.error(f"没有权限操作配置文件: {DEFAULT_CONFIG_PATH}")
|
error(f"没有权限操作配置文件: {DEFAULT_CONFIG_PATH}")
|
||||||
return False, "没有权限操作配置文件"
|
return False, "没有权限操作配置文件"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"设置配置文件失败: {e}")
|
error(f"设置配置文件失败: {e}")
|
||||||
|
|
||||||
if Path(backup_path).exists():
|
if Path(backup_path).exists():
|
||||||
shutil.move(backup_path, DEFAULT_CONFIG_PATH)
|
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)
|
json.dump(DEFAULT_CONFIG, f, indent=4)
|
||||||
return True
|
return True
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
logging.error(f"权限不足,无法操作配置文件: {DEFAULT_CONFIG_PATH}")
|
error(f"权限不足,无法操作配置文件: {DEFAULT_CONFIG_PATH}")
|
||||||
return False, "权限不足,无法重置配置"
|
return False, "权限不足,无法重置配置"
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
logging.error("配置文件格式错误,无法解析")
|
error("配置文件格式错误,无法解析")
|
||||||
return False, "配置文件格式错误,无法重置"
|
return False, "配置文件格式错误,无法重置"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"重置配置文件失败: {e}")
|
error(f"重置配置文件失败: {e}")
|
||||||
return False, f"重置配置失败: {str(e)}"
|
return False, f"重置配置失败: {str(e)}"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
pliblog的格式化工具,用于格式化日志输出
|
py-logiliteal的格式化工具,用于格式化日志输出
|
||||||
pliblog's formatter, used to format log output
|
py-logiliteal's formatter, used to format log output
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# encoding = utf-8
|
# encoding = utf-8
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
pliblog的样式工具,用于格式化日志输出
|
py-logiliteal的样式工具,用于格式化日志输出
|
||||||
pliblog's style tools, used to format log output
|
py-logiliteal's style tools, used to format log output
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# encoding = utf-8
|
# encoding = utf-8
|
||||||
|
Reference in New Issue
Block a user