wip: uvicorn logging conf to json

This commit is contained in:
Jakub Miazek
2024-08-17 10:45:51 +02:00
parent a58e98c4b1
commit 6f0b097d2d
9 changed files with 166 additions and 57 deletions

View File

@@ -21,6 +21,7 @@ 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)}")
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex

View File

@@ -5,6 +5,9 @@ from fastapi import HTTPException, status
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import declared_attr, DeclarativeBase
from app.utils.logging import AppLogger
logger = AppLogger().get_logger()
class Base(DeclarativeBase):
@@ -26,6 +29,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)}")
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
) from ex

View File

@@ -20,5 +20,5 @@ class AppLogger(metaclass=SingletonMeta):
class RichConsoleHandler(RichHandler):
def __init__(self, width=200, style=None, **kwargs):
super().__init__(
console=Console(color_system="256", width=width, style=style), **kwargs
console=Console(color_system="256", width=width, style=style, stderr=True), **kwargs
)