调试与测试
本页介绍 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 | 权限不足 | 检查文件权限 |
错误报告
提交错误报告时请包含:
系统信息
bashuname -a node -v openclaw --version诊断输出
bashopenclaw doctor > doctor.txt错误日志
bashtail -100 ~/.openclaw/logs/gateway.log > error.log重现步骤