diff --git a/src/bot/handlers/callbacks/__init__.py b/src/bot/handlers/callbacks/__init__.py index a9a2c5b..fa969e2 100644 --- a/src/bot/handlers/callbacks/__init__.py +++ b/src/bot/handlers/callbacks/__init__.py @@ -1 +1,4 @@ __all__ = [] + + +# TODO: Add automatic import all modules from this folder. diff --git a/src/bot/handlers/commands/__init__.py b/src/bot/handlers/commands/__init__.py index 897cbe5..5e9d7fa 100644 --- a/src/bot/handlers/commands/__init__.py +++ b/src/bot/handlers/commands/__init__.py @@ -1,6 +1,8 @@ __all__ = [] +# TODO: Add automatic import all modules from this folder. + from aiogram.types import Message from bot.handlers import registry diff --git a/src/config/utils.py b/src/config/utils.py index 884006d..c944472 100644 --- a/src/config/utils.py +++ b/src/config/utils.py @@ -8,7 +8,42 @@ from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict +# Constant paths for project. +LOG_DIR = Path("logs") +LOG_DIR.mkdir(parents=True, exist_ok=True) + +# Log format for loguru logger. +LOG_FORMAT = ( + "{time:YYYY-MM-DD HH:mm:ss} | " + "{level:<8} | " + "{process}.{thread.name} | " + "{module}.{function}:{line} – " + "{message}" +) + + class Settings(BaseSettings): + """ + Class to specify env settings for the project. + + The .env file is located in the project root. + + Env Vars: + bot_token (str): + Telegram API bot token. + listen_logging (bool): + intercepting logs from logging. + Defaults to False. + file_log_level (Literal): + logging level for the .log file. + "DEBUG", "INFO", "WARNING" or "ERROR". + Defaults to "DEBUG". + console_log_level (Literal): + logging level for the console. + "DEBUG", "INFO", "WARNING" or "ERROR". + Defaults to "INFO". + """ + bot_token: str = Field(frozen=True) listen_logging: bool = Field( @@ -43,20 +78,18 @@ class Settings(BaseSettings): ) -LOG_DIR = Path("logs") -LOG_DIR.mkdir(parents=True, exist_ok=True) - -LOG_FORMAT = ( - "{time:YYYY-MM-DD HH:mm:ss} | " - "{level:<8} | " - "{process}.{thread.name} | " - "{module}.{function}:{line} – " - "{message}" -) - - class InterceptHandler(logging.Handler): + """ + Class for intercepting logs from logging, including Aiogram. + """ + def emit(self, record: logging.LogRecord) -> None: + """ + Try to intercepting logs from logging. + + Args: + record (logging.LogRecord): record from logging. + """ try: level = loguru_logger.level(record.levelname).name except ValueError: @@ -82,6 +115,14 @@ def configure_logger( listen_logging: bool, console_log_level: str, ) -> None: + """ + Configure loguru logger. + + Args: + file_log_level (str): logging level for the .log file. + listen_logging (bool): intercepting logs from logging. + console_log_level (str): logging level for the console. + """ if listen_logging: logging.root.handlers.clear() logging.root.setLevel(logging.DEBUG) diff --git a/src/database/models.py b/src/database/models.py index e69de29..c855580 100644 --- a/src/database/models.py +++ b/src/database/models.py @@ -0,0 +1 @@ +# TODO: Add database models. diff --git a/src/database/session.py b/src/database/session.py index 7431e3b..abdcd2d 100644 --- a/src/database/session.py +++ b/src/database/session.py @@ -1,3 +1,4 @@ from sqlalchemy.ext.asyncio import AsyncSession +# TODO: Add database session. session: AsyncSession = ... diff --git a/src/redis_client/__init__.py b/src/redis_client/__init__.py index 4c9e398..c020937 100644 --- a/src/redis_client/__init__.py +++ b/src/redis_client/__init__.py @@ -3,4 +3,5 @@ __all__ = ["client"] from redis.asyncio.client import Redis +# TODO: Add redis client. client: Redis = ...