Skip to content

调试与测试

本页介绍 OpenClaw 的调试工具和测试方法。

日志系统

启用详细日志

bash
# 启动 Gateway 时启用
openclaw gateway --verbose

# 设置日志级别
openclaw gateway --log-level debug

日志位置

~/.openclaw/logs/
├── gateway.log      # Gateway 主日志
├── agent.log        # Agent 日志
└── channel.log      # 渠道日志

实时查看日志

bash
# 使用 tail
tail -f ~/.openclaw/logs/gateway.log

# 使用 grep 过滤
tail -f ~/.openclaw/logs/gateway.log | grep ERROR

诊断命令

Doctor

bash
openclaw doctor

输出示例:

✓ Node.js version: 24.0.0
✓ Gateway running: true
✓ Config valid: true
✓ Channels connected: telegram, discord
⚠ API key missing: anthropic

健康检查

bash
# Gateway 健康检查
curl http://localhost:18789/health

# WebSocket 连接测试
openclaw gateway --test-ws

测试工具

发送测试消息

bash
# 发送测试消息到 AI
openclaw agent --message "测试消息" --test

# 测试特定渠道
openclaw agent --message "测试" --channel telegram --to +1234567890

模型测试

bash
# 测试模型连接
openclaw model test --model anthropic/claude-opus-4-6

# 列出可用模型
openclaw model list

渠道测试

bash
# 测试 Telegram
openclaw channel test telegram

# 测试 WhatsApp
openclaw channel test whatsapp

调试技巧

会话调试

bash
# 查看当前会话
openclaw session list

# 查看会话详情
openclaw session show <session-id>

# 导出会话日志
openclaw session export <session-id>

配置验证

bash
# 验证配置文件
openclaw config validate

# 显示当前配置
openclaw config show

网络调试

bash
# 测试 WebSocket 连接
wscat -c ws://localhost:18789

# 测试 API 端点
curl -v http://localhost:18789/api/health

开发调试

开发模式

bash
# 启用开发模式
openclaw gateway --dev

# 热重载
openclaw gateway --watch

断点调试

使用 Node.js 调试器:

bash
# 启用调试端口
NODE_OPTIONS='--inspect' openclaw gateway

# 然后在 Chrome DevTools 中连接
# chrome://inspect

性能分析

bash
# 启用性能分析
openclaw gateway --profile

# 查看分析结果
openclaw profile show

错误追踪

常见错误码

错误码说明解决方案
E001配置文件无效检查 JSON 语法
E002端口被占用更改端口或终止占用进程
E003模型 API 错误检查 API Key 和余额
E004渠道连接失败检查 Token 和网络
E005权限不足检查文件权限

错误报告

提交错误报告时请包含:

  1. 系统信息

    bash
    uname -a
    node -v
    openclaw --version
  2. 诊断输出

    bash
    openclaw doctor > doctor.txt
  3. 错误日志

    bash
    tail -100 ~/.openclaw/logs/gateway.log > error.log
  4. 重现步骤

文档基于官方 docs.openclaw.ai 翻译与整理,供全球用户使用。