MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / get_logs

Method get_logs

src/core/database.py:1551–1609  ·  view source on GitHub ↗

Get request logs with token info, optionally including payload fields

(self, limit: int = 100, token_id: Optional[int] = None, include_payload: bool = False)

Source from the content-addressed store, hash-verified

1549 await db.commit()
1550
1551 async def get_logs(self, limit: int = 100, token_id: Optional[int] = None, include_payload: bool = False):
1552 """Get request logs with token info, optionally including payload fields"""
1553 async with self._connect() as db:
1554 db.row_factory = aiosqlite.Row
1555 payload_columns = "rl.request_body, rl.response_body," if include_payload else ""
1556 response_excerpt_column = "substr(COALESCE(rl.response_body, ''), 1, 2048) as response_body_excerpt,"
1557 has_status_text = await self._column_exists(db, "request_logs", "status_text")
1558 has_progress = await self._column_exists(db, "request_logs", "progress")
1559 has_updated_at = await self._column_exists(db, "request_logs", "updated_at")
1560 status_text_column = "rl.status_text," if has_status_text else "'' as status_text,"
1561 progress_column = "rl.progress," if has_progress else "0 as progress,"
1562 updated_at_column = "rl.updated_at," if has_updated_at else "rl.created_at as updated_at,"
1563
1564 if token_id:
1565 cursor = await db.execute(f"""
1566 SELECT
1567 rl.id,
1568 rl.token_id,
1569 rl.operation,
1570 {payload_columns}
1571 {response_excerpt_column}
1572 rl.status_code,
1573 rl.duration,
1574 {status_text_column}
1575 {progress_column}
1576 rl.created_at,
1577 {updated_at_column}
1578 t.email as token_email,
1579 t.name as token_username
1580 FROM request_logs rl
1581 LEFT JOIN tokens t ON rl.token_id = t.id
1582 WHERE rl.token_id = ?
1583 ORDER BY rl.created_at DESC
1584 LIMIT ?
1585 """, (token_id, limit))
1586 else:
1587 cursor = await db.execute(f"""
1588 SELECT
1589 rl.id,
1590 rl.token_id,
1591 rl.operation,
1592 {payload_columns}
1593 {response_excerpt_column}
1594 rl.status_code,
1595 rl.duration,
1596 {status_text_column}
1597 {progress_column}
1598 rl.created_at,
1599 {updated_at_column}
1600 t.email as token_email,
1601 t.name as token_username
1602 FROM request_logs rl
1603 LEFT JOIN tokens t ON rl.token_id = t.id
1604 ORDER BY rl.created_at DESC
1605 LIMIT ?
1606 """, (limit,))
1607
1608 rows = await cursor.fetchall()

Callers 1

get_logsFunction · 0.80

Calls 2

_connectMethod · 0.95
_column_existsMethod · 0.95

Tested by

no test coverage detected