feat(logging): add log line formatter

This commit is contained in:
2026-01-02 12:37:19 -05:00
parent 69a65a68a6
commit a668baa4d0
2 changed files with 77 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
"""Logging configuration and utilities."""
from datetime import datetime
def extract_stats(tool_name: str, arguments: dict, result: dict) -> str:
"""Extract meaningful stats from tool call based on tool type."""
@@ -53,3 +55,29 @@ def truncate_token(token: str) -> str:
if len(token) <= 8:
return "***"
return f"{token[:3]}...{token[-3:]}"
def format_tool_log(
agent_name: str,
token: str,
tool: str,
document: str | None,
stats: str,
status: str,
duration_ms: int,
error_message: str | None = None,
) -> str:
"""Format a tool call log line.
Format: YYYY-MM-DD HH:MM:SS | agent (token) | tool | doc | stats | status | duration
"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
truncated = truncate_token(token)
doc = document if document else "-"
line = f"{timestamp} | {agent_name} ({truncated}) | {tool} | {doc} | {stats} | {status} | {duration_ms}ms"
if error_message:
line += f"\n {error_message}"
return line