feat: use yaml and envs to load config

This commit is contained in:
swve 2023-03-24 22:50:08 +01:00
parent 0782e2c419
commit dee9ae6cf3
8 changed files with 181 additions and 6 deletions

View file

@ -1,6 +1,7 @@
from typing import Callable
from fastapi import FastAPI
from src.core.events.database import close_database, connect_to_db
from src.core.events.logs import create_logs_dir
def startup_app(app: FastAPI) -> Callable:
@ -8,6 +9,9 @@ def startup_app(app: FastAPI) -> Callable:
# Connect to database
await connect_to_db(app)
# Create logs directory
await create_logs_dir()
return start_app

24
src/core/events/logs.py Normal file
View file

@ -0,0 +1,24 @@
import logging
import os
async def create_logs_dir():
if not os.path.exists("logs"):
os.mkdir("logs")
# Initiate logging
async def init_logging():
await create_logs_dir()
# Logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
handlers=[
logging.FileHandler("logs/learnhouse.log"),
logging.StreamHandler()
]
)
logging.info("Logging initiated")