feat: 增强日志功能并添加rich依赖
- 添加rich库依赖以改进日志显示 - 在各模块添加详细调试日志,包括消息处理、命令执行和工具调用过程 - 使用RichHandler美化日志输出并抑制第三方库的噪音日志 - 在关键路径添加日志记录,便于问题排查
This commit is contained in:
@@ -53,7 +53,10 @@ async def run_claude(
|
||||
else:
|
||||
args = ["claude"] + base_args
|
||||
|
||||
logger.debug("Running: %s (cwd=%s)", " ".join(args[:6]), cwd)
|
||||
logger.debug(
|
||||
"[worker] cmd=%s session_id=%s resume=%s cwd=%s prompt=%r",
|
||||
" ".join(args[:6]), cc_session_id, resume, cwd, prompt[:120],
|
||||
)
|
||||
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
*args,
|
||||
@@ -69,6 +72,7 @@ async def run_claude(
|
||||
except asyncio.TimeoutError:
|
||||
proc.kill()
|
||||
await proc.communicate()
|
||||
logger.warning("[worker] timed out after %.0fs session_id=%s", timeout, cc_session_id)
|
||||
return f"[Timed out after {timeout:.0f}s]"
|
||||
|
||||
output = stdout_bytes.decode("utf-8", errors="replace")
|
||||
@@ -76,10 +80,12 @@ async def run_claude(
|
||||
|
||||
if proc.returncode != 0:
|
||||
err = stderr_bytes.decode("utf-8", errors="replace").strip()
|
||||
logger.warning("claude -p exited %d: %s", proc.returncode, err[:200])
|
||||
logger.warning("[worker] exit=%d stderr=%r", proc.returncode, err[:200])
|
||||
if not output:
|
||||
output = f"[Error exit {proc.returncode}] {err[:500]}"
|
||||
|
||||
logger.debug("[worker] output (%d chars): %r", len(output), output[:300])
|
||||
|
||||
if len(output) > MAX_OUTPUT_CHARS:
|
||||
output = output[:MAX_OUTPUT_CHARS] + "\n...[truncated]"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user