Skip to content

Commit a99a0e7

Browse files
committed
wip: async logging
1 parent 6ec8a3c commit a99a0e7

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

app/api/health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def smtp_check(
8787
"subject": subject,
8888
}
8989

90-
await logger.info("Sending email.", email_data=email_data)
90+
await logger.ainfo("Sending email.", email_data=email_data)
9191

9292
await run_in_threadpool(
9393
smtp.send_email,

app/api/stuff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ async def create_multi_stuff(
2121
db_session.add_all(stuff_instances)
2222
await db_session.commit()
2323
except SQLAlchemyError as ex:
24-
logger.error(f"Error inserting instances of Stuff: {repr(ex)}")
24+
await logger.aerror(f"Error inserting instances of Stuff: {repr(ex)}")
2525
raise HTTPException(
2626
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
2727
) from ex
2828
else:
29-
logger.info(
30-
f"{len(stuff_instances)} instances of Stuff inserted into database."
29+
await logger.ainfo(
30+
f"{len(stuff_instances)} Stuff instances inserted into the database."
3131
)
3232
return True
3333

app/api/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
async def create_user(
1919
payload: UserSchema, request: Request, db_session: AsyncSession = Depends(get_db)
2020
):
21-
logger.info(f"Creating user: {payload}")
21+
await logger.ainfo(f"Creating user: {payload}")
2222
_user: User = User(**payload.model_dump())
2323
await _user.save(db_session)
2424

app/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ async def get_db() -> AsyncGenerator:
2929
try:
3030
yield session
3131
except Exception as e:
32-
logger.error(f"Error getting database session: {e}")
32+
await logger.aerror(f"Error getting database session: {e}")
3333
raise

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def lifespan(app: FastAPI):
3030
min_size=5,
3131
max_size=20,
3232
)
33-
logger.info("Postgres pool created", idle_size=app.postgres_pool.get_idle_size())
33+
await logger.ainfo("Postgres pool created", idle_size=app.postgres_pool.get_idle_size())
3434
yield
3535
finally:
3636
await app.redis.close()

app/models/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def save(self, db_session: AsyncSession):
3030
db_session.add(self)
3131
return await db_session.commit()
3232
except SQLAlchemyError as ex:
33-
logger.error(f"Error inserting instance of {self}: {repr(ex)}")
33+
await logger.aerror(f"Error inserting instance of {self}: {repr(ex)}")
3434
raise HTTPException(
3535
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
3636
) from ex

app/services/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def __call__(self, request: Request):
4040
raise HTTPException(
4141
status_code=403, detail="Invalid token or expired token."
4242
)
43-
logger.info(f"Token verified: {credentials.credentials}")
43+
await logger.ainfo(f"Token verified: {credentials.credentials}")
4444
return credentials.credentials
4545

4646

app/services/scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
async def tick():
1616
async with AsyncSessionFactory() as session:
1717
stmt = text("select 1;")
18-
logger.info(f">>>> Be or not to be...{datetime.now()}")
18+
await logger.ainfo(f">>>> Be or not to be...{datetime.now()}")
1919
result = await session.execute(stmt)
20-
logger.info(f">>>> Result: {result.scalar()}")
20+
await logger.ainfo(f">>>> Result: {result.scalar()}")
2121
return True
2222

2323

app/utils/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __call__(self, *args, **kwargs):
6666
return RotatingBytesLogger(self.handler)
6767

6868

69-
@define(slots=True)
69+
@define
7070
class AppStructLogger(metaclass=SingletonMetaNoArgs):
7171
_logger: structlog.BoundLogger = field(init=False)
7272

0 commit comments

Comments
 (0)