mirror of
https://github.com/Nanaloveyuki/py-logiliteal.git
synced 2025-09-01 00:56:23 +00:00
⚡️ 使用env.py
用来存储常量和可变常量
This commit is contained in:
@ -6,9 +6,10 @@ Utility functions
|
||||
# python 3.13.5
|
||||
|
||||
from .configs import get_config, set_config, reset_config, create_backup
|
||||
from .time import get_asctime, get_date, get_time, get_weekday
|
||||
from .fmt import fmt_console, fmt_placeholder, fmt_message, fmt_level_name
|
||||
from .time import get_asctime, get_date, get_time, get_weekday, _get_time
|
||||
from .formats import fmt_console, fmt_content, fmt_file, fmt_level_list, fmt_level_name_to_number, fmt_level_number_to_name, fmt_placeholder, fmt_regex, add_placeholder, remove_placeholder, get_placeholder
|
||||
from .styles import set_color, set_bg_color, set_style
|
||||
from .env import _placeholder, _level_name_map, DEFAULT_CONFIG
|
||||
|
||||
__all__ = [
|
||||
"get_config",
|
||||
@ -19,11 +20,22 @@ __all__ = [
|
||||
"get_date",
|
||||
"get_time",
|
||||
"get_weekday",
|
||||
"_get_time",
|
||||
"fmt_console",
|
||||
"fmt_content",
|
||||
"fmt_file",
|
||||
"fmt_level_list",
|
||||
"fmt_level_name_to_number",
|
||||
"fmt_level_number_to_name",
|
||||
"fmt_placeholder",
|
||||
"fmt_message",
|
||||
"fmt_level_name",
|
||||
"fmt_regex",
|
||||
"add_placeholder",
|
||||
"remove_placeholder",
|
||||
"get_placeholder",
|
||||
"set_color",
|
||||
"set_bg_color",
|
||||
"set_style",
|
||||
"_placeholder",
|
||||
"_level_name_map",
|
||||
"DEFAULT_CONFIG",
|
||||
]
|
||||
|
@ -46,26 +46,7 @@ def get_config_path():
|
||||
return xdg_config_path
|
||||
|
||||
DEFAULT_CONFIG_PATH = get_config_path()
|
||||
DEFAULT_CONFIG = {
|
||||
"file_level": "DEBUG",
|
||||
"file_name": "latest.log",
|
||||
"file_path": "./logs",
|
||||
"file_format": "{asctime} {levelname} | {prefix}{message}{suffix}",
|
||||
"file_encoding": "utf-8",
|
||||
"enable_console": True,
|
||||
"enable_file": True,
|
||||
"console_color": True,
|
||||
"console_level": "DEBUG",
|
||||
"console_format": "{set_color(time, await get_config('time_color'))} {levelname} | {prefix}{message}{suffix}",
|
||||
"console_encoding": "utf-8",
|
||||
"asctime_format": "%Y-%m-%d %H:%M:%S",
|
||||
"time_format": "%H:%M:%S",
|
||||
"date_format": "%Y-%m-%d",
|
||||
"weekday_format": "%A",
|
||||
"level_nickname": {"DEBUG": "DEBUG", "INFO": "INFO", "WARN": "WARN", "ERRO": "ERRO", "CRIT": "CRIT"},
|
||||
"level_color": {"DEBUG": "#c1d5ff", "INFO": "#c1ffff", "WARN": "#fff600", "ERRO": "#ffa000", "CRIT": "#ff8181"},
|
||||
"time_color": "#28ffb6",
|
||||
}
|
||||
|
||||
|
||||
g_config_cache = None
|
||||
g_config_mtime = 0
|
||||
|
@ -0,0 +1,48 @@
|
||||
"""
|
||||
环境变量或常量与配置文件
|
||||
"""
|
||||
|
||||
# 默认配置
|
||||
DEFAULT_CONFIG = {
|
||||
"file_level": "DEBUG",
|
||||
"file_name": "latest.log",
|
||||
"file_path": "./logs",
|
||||
"file_format": "{asctime} {levelname} | {prefix}{message}{suffix}",
|
||||
"file_encoding": "utf-8",
|
||||
"enable_console": True,
|
||||
"enable_file": True,
|
||||
"console_color": True,
|
||||
"console_level": "DEBUG",
|
||||
"console_format": "{set_color(time, await get_config('time_color'))} {levelname} | {prefix}{message}{suffix}",
|
||||
"console_encoding": "utf-8",
|
||||
"asctime_format": "%Y-%m-%d %H:%M:%S",
|
||||
"time_format": "%H:%M:%S",
|
||||
"date_format": "%Y-%m-%d",
|
||||
"weekday_format": "%A",
|
||||
"level_nickname": {"DEBUG": "DEBUG", "INFO": "INFO", "WARN": "WARN", "ERRO": "ERRO", "CRIT": "CRIT"},
|
||||
"level_color": {"DEBUG": "#c1d5ff", "INFO": "#c1ffff", "WARN": "#fff600", "ERRO": "#ffa000", "CRIT": "#ff8181"},
|
||||
"time_color": "#28ffb6",
|
||||
}
|
||||
|
||||
# 占位符
|
||||
_placeholder: dict[str, str | bytes] = {
|
||||
"asctime": "{get_asctime()}",
|
||||
"time": "{get_time()}",
|
||||
"weekday": "{get_weekday()}",
|
||||
"date": "{get_date()}",
|
||||
"levelname": "{await fmt_level_number_to_name(level_number)}",
|
||||
"level_number": "{await fmt_level_name_to_number(levelname)}",
|
||||
"message": "{message}",
|
||||
"prefix": "{prefix}",
|
||||
"suffix": "{suffix}",
|
||||
}
|
||||
|
||||
# 日志级别映射
|
||||
_level_name_map: dict[str, int | float] = {
|
||||
"DEBUG": 0,
|
||||
"INFO": 10,
|
||||
"WARN": 20,
|
||||
"ERRO": 30,
|
||||
"CRIT": 40,
|
||||
"UNKN": -1,
|
||||
}
|
@ -7,29 +7,7 @@ from .time import get_asctime, get_time, get_weekday, get_date
|
||||
from .styles import set_color
|
||||
from .configs import get_config
|
||||
from .regex import process_color_formatting, process_html_styles, process_links, process_markdown_formats, process_special_tags
|
||||
|
||||
# 占位符
|
||||
_placeholder: dict[str, str | bytes] = {
|
||||
"asctime": "{get_asctime()}",
|
||||
"time": "{get_time()}",
|
||||
"weekday": "{get_weekday()}",
|
||||
"date": "{get_date()}",
|
||||
"levelname": "{await fmt_level_number_to_name(level_number)}",
|
||||
"level_number": "{await fmt_level_name_to_number(levelname)}",
|
||||
"message": "{message}",
|
||||
"prefix": "{prefix}",
|
||||
"suffix": "{suffix}",
|
||||
}
|
||||
|
||||
# 日志级别映射
|
||||
_level_name_map: dict[str, int | float] = {
|
||||
"DEBUG": 0,
|
||||
"INFO": 10,
|
||||
"WARN": 20,
|
||||
"ERRO": 30,
|
||||
"CRIT": 40,
|
||||
"UNKN": -1,
|
||||
}
|
||||
from .env import _placeholder, _level_name_map
|
||||
|
||||
async def fmt_level_number_to_name(level_number: int | float) -> str:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user