mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: use yaml and envs to load config
This commit is contained in:
parent
0782e2c419
commit
dee9ae6cf3
8 changed files with 181 additions and 6 deletions
|
|
@ -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
24
src/core/events/logs.py
Normal 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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue