2022-10-23 09:15:09 +00:00
|
|
|
from multiprocessing import RLock as Lock
|
|
|
|
from pathlib import Path
|
2023-03-14 01:27:22 +00:00
|
|
|
from typing import List, Optional, Union
|
2022-10-23 09:15:09 +00:00
|
|
|
|
|
|
|
from pydantic import BaseSettings
|
|
|
|
|
|
|
|
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):
|
|
|
|
_lock = Lock()
|
|
|
|
_instance: Optional["LoggerConfig"] = None
|
|
|
|
|
|
|
|
def __new__(cls, *args, **kwargs) -> "LoggerConfig":
|
|
|
|
with cls._lock:
|
|
|
|
if cls._instance is None:
|
|
|
|
cls.update_forward_refs()
|
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
|
|
|
|
|
|
|
|
name: str = "logger"
|
|
|
|
level: Optional[Union[str, int]] = None
|
|
|
|
|
|
|
|
debug: bool = False
|
2023-03-14 01:27:22 +00:00
|
|
|
width: Optional[int] = None
|
2022-10-23 09:15:09 +00:00
|
|
|
keywords: List[str] = []
|
|
|
|
time_format: str = "[%Y-%m-%d %X]"
|
|
|
|
capture_warnings: bool = True
|
|
|
|
|
|
|
|
log_path: Union[str, Path] = "./logs"
|
|
|
|
project_root: Union[str, Path] = PROJECT_ROOT
|
|
|
|
|
|
|
|
traceback_max_frames: int = 20
|
|
|
|
traceback_locals_max_depth: Optional[int] = None
|
|
|
|
traceback_locals_max_length: int = 10
|
|
|
|
traceback_locals_max_string: int = 80
|