概述


一、日志文件位置

~/.openclaw/logs/
├── gateway.log      # Gateway 主日志
├── error.log        # 错误日志
├── audit.log        # 审计日志
└── access.log       # 访问日志

二、查看日志命令

查看最近日志

# 查看最后 100 行
tail -100 ~/.openclaw/logs/gateway.log

# 实时查看 tail -f ~/.openclaw/logs/gateway.log

# 只看错误 tail -100 ~/.openclaw/logs/error.log

搜索关键词

# 搜索包含"error"的行
grep "error" ~/.openclaw/logs/gateway.log

# 搜索某个用户的所有日志 grep "ou_用户Id" ~/.openclaw/logs/gateway.log


三、诊断命令

完整诊断

openclaw doctor

输出示例:

✅ Gateway: OK (running on port 18789)
✅ Config: OK (valid JSON)
✅ MiniMax: OK (connected)
✅ DeepSeek: OK (connected)
✅ Feishu: OK (token valid)
✅ Skills: OK (5 loaded)
⚠️ Rate Limit: 80% used today

检查 Gateway 状态

openclaw gateway status

检查 Skills 状态

openclaw skills list

四、常见问题诊断

问题 1:AI 不回复

诊断步骤:

# 1. 检查 Gateway 是否运行
openclaw gateway status

# 2. 检查渠道连接 openclaw doctor

# 3. 查看最近日志 tail -50 ~/.openclaw/logs/gateway.log

问题 2:消息发送失败

诊断步骤:

# 1. 检查网络
curl -I https://api.minimaxi.com

# 2. 检查 API Key openclaw config show | grep API_KEY

# 3. 查看错误日志 tail -100 ~/.openclaw/logs/error.log

问题 3:Skill 不触发

诊断步骤:

# 1. 检查 Skill 是否加载
openclaw skills list

# 2. 检查 Skill 文件 ls -la ~/.openclaw/workspace/skills/你的Skill/

# 3. 搜索相关日志 grep "你的Skill" ~/.openclaw/logs/gateway.log


五、日志级别

级别说明记录内容
DEBUG调试信息详细执行过程
INFO一般信息正常运行日志
WARN警告信息潜在问题
ERROR错误信息错误详情

六、设置日志级别

# 临时设置 DEBUG 级别
openclaw gateway start --log-level debug

# 永久设置(在配置文件中) { "logging": { "level": "info", "file": "~/.openclaw/logs/gateway.log" } }


七、导出日志

# 导出最近一天的日志
tail -10000 ~/.openclaw/logs/gateway.log > ~/logs-today.txt

# 导出错误日志 grep "ERROR" ~/.openclaw/logs/gateway.log > ~/errors.txt


八、常见错误代码

错误代码含义解决方法
E001Gateway 未运行openclaw gateway start
E002配置文件错误检查 JSON 格式
E003API Key 无效更换 API Key
E004网络超时检查网络连接
E005Skill 加载失败检查 Skill 文件
E401未授权检查权限配置

九、自动监控

配置自动告警:

"monitoring": {
  "enabled": true,
  "alertOnError": true,
  "alertChannels": ["飞书群"],
  "alertThreshold": {
    "errorRate": 0.05,
    "responseTime": 10000
  }
}

十、下一步学什么

  • 第七章:实战案例 → 综合运用所有知识
  • 附录 A.1 术语表 → 遇到不懂的名词

学会看日志,80%的问题都能自己解决!

常见问题

Q: 日志保留多久?
A: 可配置,通常建议保留 7-30 天。