diff --git a/config.json b/config.json index 976d981..fa9c7e5 100644 --- a/config.json +++ b/config.json @@ -1,14 +1,14 @@ { "file_level": "DEBUG", "file_name": "pliblog.log", - "file_path": "./", - "file_format": "{asctime} | {levelname} | {prefix} {message}", + "file_path": "./logs", + "file_format": "{asctime} {levelname} | {prefix}{message}", "file_encoding": "utf-8", "enable_console": true, "enable_file": true, "console_color": true, - "console_level": "INFO", - "console_format": "{asctime} | {levelname} | {prefix} {message}", + "console_level": "DEBUG", + "console_format": "{asctime} {levelname} | {prefix}{message}", "console_prefix": "Auto", "console_encoding": "utf-8", "date_format": "%Y-%m-%d %H:%M:%S", @@ -18,5 +18,12 @@ "WARN": "WARN", "ERRO": "ERRO", "CRIT": "CRIT" + }, + "level_color": { + "DEBUG": "#c1d5ff", + "INFO": "#c1f8ff", + "WARN": "#fff600", + "ERRO": "#ffa000", + "CRIT": "#ff8181" } } \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py index 5d5d190..158d0f7 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -4,10 +4,18 @@ pliblog - 简易,现代化具有色彩的日志记录器 / Easy, Modern and colo # encoding = utf-8 # python 3.13.5 -from .utils import get_config, set_config, reset_config +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 __all__ = [ "get_config", "set_config", - "reset_config" + "reset_config", + "get_asctime", + "get_date", + "get_time", + "get_weekday", + "fmt_console", + "fmt_placeholder", + "fmt_message", + "fmt_level_name", ] \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 3044bb3..b956acf 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -5,9 +5,19 @@ # python 3.13.5 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 __all__ = [ "get_config", "set_config", - "reset_config" + "reset_config", + "get_asctime", + "get_date", + "get_time", + "get_weekday", + "fmt_console", + "fmt_placeholder", + "fmt_message", + "fmt_level_name", ] \ No newline at end of file diff --git a/src/utils/configs.py b/src/utils/configs.py index bddfe7f..3e1c2e4 100644 --- a/src/utils/configs.py +++ b/src/utils/configs.py @@ -6,23 +6,23 @@ pliblog's config settings, used to set pliblog's global config # encoding = utf-8 # python 3.13.5 -# Default Config Path DEFAULT_CONFIG_PATH = "config.json" DEFAULT_CONFIG = { "file_level": "DEBUG", "file_name": "pliblog.log", "file_path": "./logs", - "file_format": "{asctime} | {levelname} | {prefix} {message}", + "file_format": "{asctime} {levelname} | {prefix}{message}", "file_encoding": "utf-8", "enable_console": True, "enable_file": True, "console_color": True, "console_level": "INFO", - "console_format": "{asctime} | {levelname} | {prefix} {message}", + "console_format": "{asctime} {levelname} | {prefix}{message}", "console_prefix": "Auto", "console_encoding": "utf-8", "date_format": "%Y-%m-%d %H:%M:%S", - "level_name": {"DEBUG": "DEBUG", "INFO": "INFO", "WARN": "WARN", "ERRO": "ERRO", "CRIT": "CRIT"} + "level_name": {"DEBUG": "DEBUG", "INFO": "INFO", "WARN": "WARN", "ERRO": "ERRO", "CRIT": "CRIT"}, + "level_color": {"DEBUG": "#c1d5ff", "INFO": "#c1ffff", "WARN": "#fff600", "ERRO": "#ffa000", "CRIT": "#ff8181"}, } from typing import Union, Optional @@ -119,9 +119,10 @@ def reset_config() -> tuple[bool, Optional[str]]: json.dump(DEFAULT_CONFIG, f, indent=4) return True, "配置文件不存在,已创建默认配置" - from datetime import datetime - timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - backup_path = f"{DEFAULT_CONFIG_PATH}.backup.{timestamp}" + from .time import get_asctime + timestamp = get_asctime() + backup_path = f"{DEFAULT_CONFIG_PATH}_{timestamp}.backup.json" + backup_path = backup_path.replace(":", "-") shutil.copy2(DEFAULT_CONFIG_PATH, backup_path) with open(DEFAULT_CONFIG_PATH, "w", encoding="utf-8") as f: json.dump(DEFAULT_CONFIG, f, indent=4)