diff --git a/core/config.py b/core/config.py index 6d3bbc7..db17f44 100644 --- a/core/config.py +++ b/core/config.py @@ -7,15 +7,11 @@ from typing import ( ) import dotenv -from pydantic import ( - AnyUrl, - BaseModel, - Field, - validator, -) +from pydantic import AnyUrl, BaseModel, Field from utils.const import PROJECT_ROOT from utils.models.base import Settings +from utils.typedefs import NaturalNumber __all__ = ["BotConfig", "config", "JoinGroups"] @@ -67,15 +63,9 @@ class LoggerConfig(Settings): render_keywords: List[str] = ["BOT"] locals_max_length: int = 10 locals_max_string: int = 80 - locals_max_depth: Optional[int] = None + locals_max_depth: Optional[NaturalNumber] = None filtered_names: List[str] = ["uvicorn"] - @validator("locals_max_depth", pre=True, check_fields=False) - def locals_max_depth_validator(cls, value) -> Optional[int]: # pylint: disable=R0201 - if int(value) <= 0: - return None - return value - class Config(Settings.Config): env_prefix = "logger_" diff --git a/utils/typedefs.py b/utils/typedefs.py index 4b0bed6..f8ff02e 100644 --- a/utils/typedefs.py +++ b/utils/typedefs.py @@ -4,6 +4,7 @@ from types import TracebackType from typing import Any, Callable, Dict, Optional, Tuple, Type, Union from httpx import URL +from pydantic import ConstrainedInt __all__ = [ "StrOrPath", @@ -14,6 +15,7 @@ __all__ = [ "JSONDict", "JSONType", "LogFilterType", + "NaturalNumber", ] StrOrPath = Union[str, Path] @@ -26,3 +28,7 @@ JSONDict = Dict[str, Any] JSONType = Union[JSONDict, list] LogFilterType = Union[Filter, Callable[[LogRecord], int]] + + +class NaturalNumber(ConstrainedInt): + ge = 0