OpenClaw 日志系统:问题排查必备

2 阅读1分钟

日志看不懂?这篇文章帮你

日志在哪?

~/.openclaw/logs/
├── openclaw.log       # 主日志
├── heartbeat.log      # 心跳日志
├── api.log           # API 日志
└── error.log         # 错误日志

查看日志

# 实时查看
openclaw logs --tail

# 查看最近 100 行
openclaw logs --tail 100

# 只看错误
openclaw logs --level error

# 搜索关键词
openclaw logs --grep "失败"

日志级别

级别说明示例
DEBUG调试信息变量值、执行路径
INFO正常信息启动、请求、完成
WARN警告配置问题、性能问题
ERROR错误API 失败、异常

配置日志级别

logging:
  level: info  # debug/info/warn/error
  file: ~/.openclaw/logs/openclaw.log
  max_size: 10MB
  max_files: 5

常见问题排查

问题 1:启动失败

日志

Error: EADDRINUSE: address already in use :::3000

解决

# 查看占用
lsof -i :3000
# 杀掉进程
kill -9 <PID>

问题 2:API 调用失败

日志

Error: API request failed: 401 Unauthorized

解决

  • 检查 API Key 是否正确
  • 检查是否过期
  • 检查余额

问题 3:心跳不执行

日志

Heartbeat task failed: script not found

解决

  • 检查脚本路径
  • 检查脚本权限

问题 4:内存泄漏

日志

JavaScript heap out of memory

解决

# 增加内存限制
export NODE_OPTIONS="--max-old-space-size=4096"

问题 5:数据库错误

日志

Error: SQLITE_BUSY: database is locked

解决

  • 减少并发
  • 或升级到 PostgreSQL

日志分析技巧

统计错误数量

grep -c "ERROR" ~/.openclaw/logs/openclaw.log

查看最近错误

grep "ERROR" ~/.openclaw/logs/openclaw.log | tail -20

分析性能

grep "响应时间" ~/.openclaw/logs/openclaw.log

日志脱敏

logging:
  redact:
    - api_key
    - password
    - token
    - secret

日志轮转

logging:
  rotation:
    enabled: true
    max_size: 10MB
    max_files: 10
    compress: true

远程日志(可选)

logging:
  remote:
    enabled: true
    url: https://logs.yourcompany.com/api
    level: error

最佳实践

  1. 开发环境:level = debug
  2. 生产环境:level = info
  3. 敏感环境:level = warn + 脱敏
  4. 定期清理:保留 30 天
  5. 监控告警:错误自动通知

💬 你遇到过什么日志问题?评论区分享!

🎯 需要问题排查服务?微信:yang1002378395