diff --git a/app/api/health.py b/app/api/health.py index 04ff174..a725f4f 100644 --- a/app/api/health.py +++ b/app/api/health.py @@ -87,7 +87,7 @@ async def smtp_check( "subject": subject, } - await logger.info("Sending email.", email_data=email_data) + await logger.ainfo("Sending email.", email_data=email_data) await run_in_threadpool( smtp.send_email, diff --git a/app/api/stuff.py b/app/api/stuff.py index 07b39d8..0f73b92 100644 --- a/app/api/stuff.py +++ b/app/api/stuff.py @@ -21,13 +21,13 @@ async def create_multi_stuff( db_session.add_all(stuff_instances) await db_session.commit() except SQLAlchemyError as ex: - logger.error(f"Error inserting instances of Stuff: {repr(ex)}") + await logger.aerror(f"Error inserting instances of Stuff: {repr(ex)}") raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex) ) from ex else: - logger.info( - f"{len(stuff_instances)} instances of Stuff inserted into database." + await logger.ainfo( + f"{len(stuff_instances)} Stuff instances inserted into the database." ) return True diff --git a/app/api/user.py b/app/api/user.py index 0d5b3bb..a22c7c6 100644 --- a/app/api/user.py +++ b/app/api/user.py @@ -18,7 +18,7 @@ router = APIRouter(prefix="/v1/user") async def create_user( payload: UserSchema, request: Request, db_session: AsyncSession = Depends(get_db) ): - logger.info(f"Creating user: {payload}") + await logger.ainfo(f"Creating user: {payload}") _user: User = User(**payload.model_dump()) await _user.save(db_session) diff --git a/app/database.py b/app/database.py index c900087..035691f 100644 --- a/app/database.py +++ b/app/database.py @@ -29,5 +29,5 @@ async def get_db() -> AsyncGenerator: try: yield session except Exception as e: - logger.error(f"Error getting database session: {e}") + await logger.aerror(f"Error getting database session: {e}") raise diff --git a/app/main.py b/app/main.py index 70ca866..f1c0ffd 100644 --- a/app/main.py +++ b/app/main.py @@ -30,7 +30,7 @@ async def lifespan(app: FastAPI): min_size=5, max_size=20, ) - logger.info("Postgres pool created", idle_size=app.postgres_pool.get_idle_size()) + await logger.ainfo("Postgres pool created", idle_size=app.postgres_pool.get_idle_size()) yield finally: await app.redis.close() diff --git a/app/models/base.py b/app/models/base.py index 6f114b4..f66a98f 100644 --- a/app/models/base.py +++ b/app/models/base.py @@ -30,7 +30,7 @@ class Base(DeclarativeBase): db_session.add(self) return await db_session.commit() except SQLAlchemyError as ex: - logger.error(f"Error inserting instance of {self}: {repr(ex)}") + await logger.aerror(f"Error inserting instance of {self}: {repr(ex)}") raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex) ) from ex diff --git a/app/services/auth.py b/app/services/auth.py index 3509f8a..23a4452 100644 --- a/app/services/auth.py +++ b/app/services/auth.py @@ -40,7 +40,7 @@ class AuthBearer(HTTPBearer): raise HTTPException( status_code=403, detail="Invalid token or expired token." ) - logger.info(f"Token verified: {credentials.credentials}") + await logger.ainfo(f"Token verified: {credentials.credentials}") return credentials.credentials diff --git a/app/services/scheduler.py b/app/services/scheduler.py index 31a5673..b290376 100644 --- a/app/services/scheduler.py +++ b/app/services/scheduler.py @@ -15,9 +15,9 @@ logger = AppLogger().get_logger() async def tick(): async with AsyncSessionFactory() as session: stmt = text("select 1;") - logger.info(f">>>> Be or not to be...{datetime.now()}") + await logger.ainfo(f">>>> Be or not to be...{datetime.now()}") result = await session.execute(stmt) - logger.info(f">>>> Result: {result.scalar()}") + await logger.ainfo(f">>>> Result: {result.scalar()}") return True diff --git a/app/utils/logging.py b/app/utils/logging.py index e153a8c..23af6fd 100644 --- a/app/utils/logging.py +++ b/app/utils/logging.py @@ -66,7 +66,7 @@ class RotatingBytesLoggerFactory: return RotatingBytesLogger(self.handler) -@define(slots=True) +@define class AppStructLogger(metaclass=SingletonMetaNoArgs): _logger: structlog.BoundLogger = field(init=False)