mirror of
https://github.com/creyD/apilog.git
synced 2026-04-12 19:30:29 +02:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from enum import Enum as pyenum
|
|
|
|
from creyPY.fastapi.models.base import Base
|
|
from sqlalchemy import JSON, Column, Enum, ForeignKey, String
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
|
|
class TransactionType(pyenum):
|
|
CREATE = "create"
|
|
UPDATE = "update"
|
|
DELETE = "delete"
|
|
UNDEFINED = "undefined"
|
|
|
|
|
|
class LogType(pyenum):
|
|
INFO = "info"
|
|
WARNING = "warning"
|
|
ERROR = "error"
|
|
CRITICAL = "critical"
|
|
|
|
|
|
class LogEntry(Base):
|
|
application = Column(
|
|
UUID(as_uuid=True), ForeignKey("application.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
environment = Column(String(64), nullable=True, default="prod")
|
|
# type of the log entry
|
|
l_type = Column(Enum(LogType), nullable=False, default=LogType.INFO)
|
|
# type of the transaction
|
|
t_type = Column(Enum(TransactionType), nullable=False, default=TransactionType.UNDEFINED)
|
|
# a custom logmessage
|
|
message = Column(String(512), nullable=True)
|
|
# author ID i.e. auth0 user sub
|
|
author = Column(String(512), nullable=False, default="system")
|
|
# optional reference to the object (like object ID)
|
|
object_reference = Column(String(512), nullable=True)
|
|
# for irreversible operations, store the object state before the operation
|
|
previous_object = Column(JSON, nullable=True)
|