Coverage for src/local_deep_research/database/models/logs.py: 94%

16 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-03 23:15 +0000

1""" 

2Logging model for storing application logs. 

3 

4The ``Journal`` model used to live here too but was moved to 

5``journal.py`` for discoverability — it's unrelated to the 

6``ResearchLog`` table this file owns. Compat imports of 

7``from ...database.models.logs import Journal`` still work via the 

8re-export below. 

9""" 

10 

11from sqlalchemy import ( 

12 Column, 

13 ForeignKey, 

14 Integer, 

15 Sequence, 

16 String, 

17 Text, 

18) 

19from sqlalchemy_utc import UtcDateTime, utcnow 

20 

21from .base import Base 

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

23 

24 

25class ResearchLog(Base): 

26 """ 

27 Logging table for all research operations. 

28 

29 All logging from research operations, including debug messages, 

30 errors, and milestones are stored here. 

31 """ 

32 

33 __tablename__ = "app_logs" 

34 

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

36 

37 timestamp = Column(UtcDateTime, server_default=utcnow(), nullable=False) 

38 message = Column(Text, nullable=False) 

39 # Module that the log message came from. 

40 module = Column(Text, nullable=False) 

41 # Function that the log message came from. 

42 function = Column(Text, nullable=False) 

43 # Line number that the log message came from. 

44 line_no = Column(Integer, nullable=False) 

45 # Log level. 

46 level = Column(String(32), nullable=False) 

47 research_id = Column( 

48 String(36), # UUID as string 

49 ForeignKey("research_history.id", ondelete="CASCADE"), 

50 nullable=True, 

51 index=True, 

52 ) 

53 

54 def __repr__(self): 

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