feature/docs - add project docstrings & todos & comments #6

Merged
geekiot merged 4 commits from feature/docs into develop 2025-10-24 02:27:50 +05:00
6 changed files with 61 additions and 12 deletions
Showing only changes of commit f605fac47b - Show all commits

View file

@ -1 +1,4 @@
__all__ = []
# TODO: Add automatic import all modules from this folder.

View file

@ -1,6 +1,8 @@
__all__ = []
# TODO: Add automatic import all modules from this folder.
from aiogram.types import Message
from bot.handlers import registry

View file

@ -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 = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level:<8}</level> | "
"<cyan>{process}</cyan>.<cyan>{thread.name}</cyan> | "
"<magenta>{module}.{function}:{line}</magenta> "
"<level>{message}</level>"
)
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 = (
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level:<8}</level> | "
"<cyan>{process}</cyan>.<cyan>{thread.name}</cyan> | "
"<magenta>{module}.{function}:{line}</magenta> "
"<level>{message}</level>"
)
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)

View file

@ -0,0 +1 @@
# TODO: Add database models.

View file

@ -1,3 +1,4 @@
from sqlalchemy.ext.asyncio import AsyncSession
# TODO: Add database session.
session: AsyncSession = ...

View file

@ -3,4 +3,5 @@ __all__ = ["client"]
from redis.asyncio.client import Redis
# TODO: Add redis client.
client: Redis = ...