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