add rich logger

This commit is contained in:
grillazz 2021-09-01 09:48:28 +02:00
parent ec71ff58b1
commit b25e833f21
2 changed files with 8 additions and 8 deletions

View File

@ -1,10 +1,11 @@
import logging
import os import os
from functools import lru_cache from functools import lru_cache
from pydantic import BaseSettings from pydantic import BaseSettings
log = logging.getLogger(__name__) from the_app.utils import get_logger
logger = get_logger(__name__)
class Settings(BaseSettings): class Settings(BaseSettings):
@ -41,5 +42,5 @@ class Settings(BaseSettings):
@lru_cache() @lru_cache()
def get_settings(): def get_settings():
log.info("Loading config settings from the environment...") logger.info("Loading config settings from the environment...")
return Settings() return Settings()

View File

@ -1,13 +1,12 @@
import logging
from fastapi import FastAPI from fastapi import FastAPI
from the_app.api.nonsense import router as nonsense_router from the_app.api.nonsense import router as nonsense_router
from the_app.api.stuff import router as stuff_router from the_app.api.stuff import router as stuff_router
from the_app.database import engine from the_app.database import engine
from the_app.models.base import Base from the_app.models.base import Base
from the_app.utils import get_logger
log = logging.getLogger(__name__) logger = get_logger(__name__)
app = FastAPI(title="Stuff And Nonsense", version="0.2") app = FastAPI(title="Stuff And Nonsense", version="0.2")
@ -22,10 +21,10 @@ async def start_db():
@app.on_event("startup") @app.on_event("startup")
async def startup_event(): async def startup_event():
log.info("Starting up...") logger.info("Starting up...")
await start_db() await start_db()
@app.on_event("shutdown") @app.on_event("shutdown")
async def shutdown_event(): async def shutdown_event():
log.info("Shutting down...") logger.info("Shutting down...")