xmpp-api/src/xmpp_api/main.py
Alexander PapaTutuWawa 98a329ed74
Some checks failed
ci/woodpecker/push/check Pipeline failed
Add basic logging
2025-04-21 13:32:38 +02:00

36 lines
844 B
Python

import os
import logging
from fastapi import FastAPI
from sqlmodel import SQLModel
from xmpp_api.config.config import load_config
from xmpp_api.db import get_engine
from xmpp_api.xmpp.component import XmppApiComponent
import xmpp_api.api.routers.v1 as api_v1
app = FastAPI()
app.include_router(api_v1.router)
@app.on_event("startup")
def startup():
# Setup logging
logging.basicConfig(
level=(
logging.DEBUG
if os.environ.get("XMPP_API__LOG_LEVEL") == "DEBUG"
else logging.INFO
),
)
# TODO: This is kinda ugly
config = load_config()
engine = app.dependency_overrides.get(get_engine, get_engine)(config)
SQLModel.metadata.create_all(engine)
# App startup is done. Connect to the XMPP server
instance = XmppApiComponent.of(config)
instance.run()