2022-10-23 09:15:09 +00:00
|
|
|
from multiprocessing import RLock as Lock
|
|
|
|
from pathlib import Path
|
2024-11-30 14:11:02 +00:00
|
|
|
from typing import List, Literal, Optional, Union, ClassVar
|
2022-10-23 09:15:09 +00:00
|
|
|
|
2024-11-30 14:11:02 +00:00
|
|
|
from pydantic_settings import BaseSettings
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
from utils.const import PROJECT_ROOT
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
__all__ = ("LoggerConfig",)
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LoggerConfig(BaseSettings):
|
2024-11-30 14:11:02 +00:00
|
|
|
_lock: ClassVar[Lock] = Lock()
|
|
|
|
_instance: ClassVar[Optional["LoggerConfig"]] = None
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
def __new__(cls, *args, **kwargs) -> "LoggerConfig":
|
|
|
|
with cls._lock:
|
|
|
|
if cls._instance is None:
|
2024-11-30 14:11:02 +00:00
|
|
|
cls.model_rebuild()
|
2023-03-14 01:27:22 +00:00
|
|
|
result = super(LoggerConfig, cls).__new__(cls) # pylint: disable=E1120
|
2022-10-23 09:15:09 +00:00
|
|
|
result.__init__(*args, **kwargs)
|
|
|
|
cls._instance = result
|
|
|
|
return cls._instance
|
|
|
|
|
2023-03-21 05:53:56 +00:00
|
|
|
name: str = "PaiGram-logger"
|
|
|
|
"""logger 名称"""
|
2022-10-23 09:15:09 +00:00
|
|
|
level: Optional[Union[str, int]] = None
|
2023-03-21 05:53:56 +00:00
|
|
|
"""logger 的 level"""
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
debug: bool = False
|
2023-03-21 05:53:56 +00:00
|
|
|
"""是否 debug"""
|
2023-03-14 01:27:22 +00:00
|
|
|
width: Optional[int] = None
|
2023-03-21 05:53:56 +00:00
|
|
|
"""输出时的宽度"""
|
2022-10-23 09:15:09 +00:00
|
|
|
keywords: List[str] = []
|
2023-03-21 05:53:56 +00:00
|
|
|
"""高亮的关键字"""
|
2022-10-23 09:15:09 +00:00
|
|
|
time_format: str = "[%Y-%m-%d %X]"
|
2023-03-21 05:53:56 +00:00
|
|
|
"""时间格式"""
|
2022-10-23 09:15:09 +00:00
|
|
|
capture_warnings: bool = True
|
2023-03-21 05:53:56 +00:00
|
|
|
"""是否捕获 warning"""
|
|
|
|
color_system: Literal["auto", "standard", "256", "truecolor", "windows"] = "auto"
|
|
|
|
"""颜色模式: 自动、标准、256色、真彩、Windows模式"""
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
log_path: Union[str, Path] = "./logs"
|
2023-03-21 05:53:56 +00:00
|
|
|
"""log 所保存的路径,项目根目录的相对路径"""
|
2022-10-23 09:15:09 +00:00
|
|
|
project_root: Union[str, Path] = PROJECT_ROOT
|
2023-03-21 05:53:56 +00:00
|
|
|
"""项目根目录"""
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
traceback_max_frames: int = 20
|
|
|
|
traceback_locals_max_depth: Optional[int] = None
|
|
|
|
traceback_locals_max_length: int = 10
|
|
|
|
traceback_locals_max_string: int = 80
|