added logging config. Not active yet

This commit is contained in:
Jonas Linter
2025-10-09 11:06:22 +02:00
parent ac57999a85
commit 162ef39013
3 changed files with 20 additions and 10 deletions

View File

@@ -164,12 +164,12 @@ async def lifespan(app: FastAPI):
try:
config = load_config()
except Exception as e:
_LOGGER.error(f"Failed to load config: {e!s}")
except Exception:
_LOGGER.exception("Failed to load config: ")
config = {}
DATABASE_URL = get_database_url(config)
engine = create_async_engine(DATABASE_URL, echo=True)
engine = create_async_engine(DATABASE_URL, echo=False)
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
app.state.engine = engine

View File

@@ -1,12 +1,8 @@
import os
from pathlib import Path
from annotatedyaml.loader import (
Secrets,
)
from annotatedyaml.loader import (
load_yaml as load_annotated_yaml,
)
from annotatedyaml.loader import Secrets
from annotatedyaml.loader import load_yaml as load_annotated_yaml
from voluptuous import (
PREVENT_EXTRA,
All,
@@ -21,6 +17,15 @@ from voluptuous import (
database_schema = Schema({Required("url"): str}, extra=PREVENT_EXTRA)
logger_schema = Schema(
{
Required("level"): str,
Optional("file"): str, # If not provided, log to console
},
extra=PREVENT_EXTRA,
)
hotel_auth_schema = Schema(
{
Required("hotel_id"): str,
@@ -42,6 +47,7 @@ config_schema = Schema(
{
Required("database"): database_schema,
Required("alpine_bits_auth"): basic_auth_schema,
Optional("logger", default={"level": "INFO", "file": None}): logger_schema,
},
extra=PREVENT_EXTRA,
)
@@ -52,7 +58,7 @@ DEFAULT_CONFIG_FILE = "config.yaml"
class Config:
def __init__(
self,
config_folder: str | Path = None,
config_folder: str | Path | None = None,
config_name: str = DEFAULT_CONFIG_FILE,
testing_mode: bool = False,
):