33 lines
927 B
Python
33 lines
927 B
Python
from sqlalchemy import Column, String, DateTime, Integer, ForeignKey, Text, Enum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import enum
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class LogLevel(str, enum.Enum):
|
|
DEBUG = "debug"
|
|
INFO = "info"
|
|
WARNING = "warning"
|
|
ERROR = "error"
|
|
CRITICAL = "critical"
|
|
|
|
|
|
class Log(Base):
|
|
__tablename__ = "logs"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
device_id = Column(String, ForeignKey("devices.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# Log details
|
|
level = Column(Enum(LogLevel), default=LogLevel.INFO)
|
|
message = Column(Text, nullable=False)
|
|
source = Column(String, nullable=True) # Component or module that generated the log
|
|
|
|
# Timestamp
|
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Relationship
|
|
device = relationship("Device", back_populates="logs")
|