mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
wip: async logging
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user