Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""
Logging model for storing application logs.

The ``Journal`` model used to live here too but was moved to
``journal.py`` for discoverability — it's unrelated to the
``ResearchLog`` table this file owns. Compat imports of
``from ...database.models.logs import Journal`` still work via the
re-export below.
"""

from sqlalchemy import (
    Column,
    ForeignKey,
    Index,
    Integer,
    Sequence,
    String,
    Text,
)
from sqlalchemy_utc import UtcDateTime, utcnow

from .base import Base
from .journal import Journal  # noqa: F401 — compat re-export


class ResearchLog(Base):
    """
    Logging table for all research operations.

    All logging from research operations, including debug messages,
    errors, and milestones are stored here.
    """

    __tablename__ = "app_logs"
    __table_args__ = (
        Index(
            "ix_app_logs_research_id_timestamp_id",
            "research_id",
            "timestamp",
            "id",
        ),
    )

    id = Column(Integer, Sequence("reseach_log_id_seq"), primary_key=True)

    timestamp = Column(UtcDateTime, server_default=utcnow(), nullable=False)
    message = Column(Text, nullable=False)
    # Module that the log message came from.
    module = Column(Text, nullable=False)
    # Function that the log message came from.
    function = Column(Text, nullable=False)
    # Line number that the log message came from.
    line_no = Column(Integer, nullable=False)
    # Log level.
    level = Column(String(32), nullable=False)
    research_id = Column(
        String(36),  # UUID as string
        ForeignKey("research_history.id", ondelete="CASCADE"),
        nullable=True,
        index=True,
    )

    def __repr__(self):
        return f"<ResearchLog({self.level}: '{self.message[:50]}...')>"