From 8b62b597e317d2654b92dc7d561a6862b6e7bd1b Mon Sep 17 00:00:00 2001 From: Dmitry Titenkov Date: Fri, 20 Feb 2026 11:50:07 +0300 Subject: [PATCH] =?UTF-8?q?config,=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D1=80=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 0 app/api/__init__.py | 0 app/core/__init__.py | 0 app/core/config.py | 12 ++++++++++++ app/core/logging.py | 28 ++++++++++++++++++++++++++++ app/main.py | 25 +++++++++++++++++++++++++ app/models/__init__.py | 0 app/routers/__init__.py | 0 app/schemas/__init__.py | 0 requirements.txt | 1 + 10 files changed, 66 insertions(+) create mode 100644 app/__init__.py create mode 100644 app/api/__init__.py create mode 100644 app/core/__init__.py create mode 100644 app/core/config.py create mode 100644 app/core/logging.py create mode 100644 app/main.py create mode 100644 app/models/__init__.py create mode 100644 app/routers/__init__.py create mode 100644 app/schemas/__init__.py diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/core/__init__.py b/app/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/core/config.py b/app/core/config.py new file mode 100644 index 0000000..01d5de2 --- /dev/null +++ b/app/core/config.py @@ -0,0 +1,12 @@ +from pydantic_settings import BaseSettings + + +class Settings(BaseSettings): + app_title: str + description: str + database_url: str + + model_config = {"env_file": ".env", "extra": "ignore"} + + +settings = Settings() diff --git a/app/core/logging.py b/app/core/logging.py new file mode 100644 index 0000000..78004f0 --- /dev/null +++ b/app/core/logging.py @@ -0,0 +1,28 @@ +import logging +from logging.handlers import RotatingFileHandler +from pathlib import Path + +LOG_DIR = Path("logs") +LOG_DIR.mkdir(exist_ok=True) + +LOG_FILE = LOG_DIR / "app.log" + + +def setup_logging() -> None: + logging.basicConfig( + level=logging.INFO, + format="%(asctime)s: - |%(levelname)s| %(name)s | %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + handlers=[ + logging.StreamHandler(), + RotatingFileHandler( + filename=LOG_FILE, + maxBytes=1024 * 1024 * 5, + backupCount=5, + encoding="utf-8", + ), + ], + ) + + +logging.getLogger("uvicorn.access").setLevel(logging.WARNING) diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..ba8944f --- /dev/null +++ b/app/main.py @@ -0,0 +1,25 @@ +import logging +from contextlib import asynccontextmanager + +from fastapi import FastAPI + +from app.core.config import settings +from app.core.logging import setup_logging + +setup_logging() + +logger = logging.getLogger(__name__) + + +@asynccontextmanager +async def lifespan(app: FastAPI): + logging.info("Приложение World Flow запущено") + yield + logging.info("Приложение World Flow остановлено") + + +app = FastAPI( + title=settings.app_title, + description=settings.description, + lifespan=lifespan, +) diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index 66b696d..c7e6db8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,7 @@ pathspec==1.0.4 platformdirs==4.9.2 pycodestyle==2.14.0 pydantic==2.12.5 +pydantic-settings==2.13.1 pydantic_core==2.41.5 pyflakes==3.4.0 python-dotenv==1.2.1