Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions example/fastapi-app/bootstrap/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from fastapi_startkit.logging import LogProvider
from providers.fastapi_provider import FastAPIProvider
from config.fastapi import FastAPIConfig
from config.logging import LoggingConfig

app: Application = Application(
base_path=str(Path.cwd()), # This always gives path relative to the execution.
base_path=str(Path(__file__).parent.parent),
providers=[
LogProvider,
(LogProvider, LoggingConfig),
(FastAPIProvider, FastAPIConfig),
]
],
)
4 changes: 1 addition & 3 deletions example/fastapi-app/config/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@dataclasses.dataclass
class FastAPIConfig:
app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://localhost"))
host: str = dataclasses.field(default_factory=lambda: env("APP_HOST", "127.0.0.1"))
port: int = dataclasses.field(default_factory=lambda: env("APP_PORT", 8000))
app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://127.0.0.1:8000"))
reload: bool = dataclasses.field(default_factory=lambda: env("APP_RELOAD", True))
reload_dirs: list | None = None
reload_excludes: list = dataclasses.field(
Expand Down
38 changes: 21 additions & 17 deletions example/fastapi-app/config/logging.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# config/logging.py
DEFAULT = 'stack'
import dataclasses

CHANNELS = {
'daily': {
'driver': 'daily',
'level': 'debug',
'path': 'storage/logs'
},
'terminal': {
'driver': 'terminal',
'level': 'info',
},
'stack': {
'driver': 'stack',
'channels': ['daily', 'terminal']
}
}
from fastapi_startkit.environment import env
from fastapi_startkit.logging.config import DailyChannel, StackChannel, TerminalChannel


@dataclasses.dataclass
class LoggingConfig:
default: str = dataclasses.field(default_factory=lambda: env("LOG_CHANNEL", "stack"))

channels: dict = dataclasses.field(
default_factory=lambda: {
"stack": StackChannel(driver="stack", channels=["daily", "terminal"]),
"daily": DailyChannel(
level=env("LOG_DAILY_LEVEL", "debug"),
path=env("LOG_DAILY_PATH", "storage/logs"),
),
"terminal": TerminalChannel(
level=env("LOG_TERMINAL_LEVEL", "info"),
),
}
)
1 change: 1 addition & 0 deletions example/fastapi-app/providers/fastapi_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi_startkit.fastapi import FastAPIProvider as BaseFastapiProvider
from routes.api import public


class FastAPIProvider(BaseFastapiProvider):
def boot(self) -> None:
super().boot()
Expand Down
4 changes: 3 additions & 1 deletion example/fastapi-app/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public = APIRouter()


@public.get("/")
async def index():
Logger.info("Welcome to FastAPI StartKit!")
Expand All @@ -13,9 +14,10 @@ async def index():
return {
"message": "Welcome to FastAPI StartKit!",
"version": "1.0.0",
"docs": "/docs"
"docs": "/docs",
}


@public.get("/health")
async def health():
Logger.info("Health check passed")
Expand Down
11 changes: 6 additions & 5 deletions example/fastapi-app/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fastapi_startkit/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading