← 返回 Skills 市场
xiaohuaishu

API Logger

作者 xiaohuaishu · GitHub ↗ · v1.2.0 · MIT-0
cross-platform ⚠ suspicious
362
总下载
0
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install api-logger
功能描述
LLM API 调用日志记录、分析与可视化。透明代理拦截所有 LLM API 调用,记录完整 prompt/generation/token 用量, 附带零依赖网页日志查看器(支持多维过滤、完整对话展示、token 成本统计)。 适用场景:分析 API 调用成本、调试 prompt、查看历史对话记录、排查慢请求/...
使用说明 (SKILL.md)

API Logger 🦞📊

LLM API 调用日志完整解决方案。透明代理拦截所有请求,零侵入记录,配套终端和网页两种查看方式。


🌐 网页日志查看器(推荐)

文件: log-viewer.html(skill 目录内)

使用方法

  1. log-viewer.html 复制到任意位置,双击用浏览器打开
  2. 点击「⬆ 选择日志文件」,选择 .jsonl 日志文件(支持多文件合并)
  3. 也可以直接把日志文件拖拽到页面

功能一览

  • 统计卡片:总调用数 / 成功率 / 平均耗时 / 总 Token 消耗
  • 7种过滤条件(实时响应,无需点搜索):
    • 全文搜索(搜索 prompt + response 内容)
    • 模型筛选(自动提取日志中所有模型)
    • 状态筛选(全部 / 成功 2xx / 失败)
    • 最小耗时过滤(找慢请求)
    • 一键重置
  • 日志列表:时间 | 模型 | 状态 | 耗时 | Token | 用户输入,耗时>2s 自动标红
  • 详情面板(点击任意行展开):
    • 对话内容:完整 system prompt + 多轮对话,user/assistant 分色展示
    • 请求信息:Request ID、模型、时间、耗时、状态、Token 用量
    • 原始 JSON:完整日志记录,语法高亮,一键复制
  • 快捷键Esc 关闭详情,↑↓ 切换上下条
  • 零依赖:纯原生 JS,无需网络,离线可用

💻 终端日志查看器

# 进入日志查看器目录
cd ~/.openclaw/workspace/company/api-proxy/

# 今日摘要列表
python3 log_viewer.py

# 最后 N 条
python3 log_viewer.py --last 5

# 某条完整详情
python3 log_viewer.py --id 3 --full

# 今日统计(token 用量、成本估算)
python3 log_viewer.py --stats

# 今日统计 + 生成飞书文档
python3 log_viewer.py --stats --feishu

# 搜索关键词
python3 log_viewer.py --search "关键词"

# 只看失败请求
python3 log_viewer.py --errors

# 生成飞书文档(超300条自动截断明细)
python3 log_viewer.py --feishu

# 指定日期
python3 log_viewer.py --date 2026-03-10 --feishu

📦 安装

bash ~/.openclaw/workspace/skills/api-logger/install.sh

安装脚本将:

  1. 创建 ~/.openclaw/workspace/company/api-proxy/
  2. 复制 proxy.pylog_viewer.py
  3. 创建日志目录 ~/.openclaw/workspace/company/api-logs/
  4. 写入 macOS LaunchAgent plist(开机自启动)
  5. 启动代理服务

配置(安装后手动完成)

修改 openclaw.json 的 baseUrl:

"baseUrl": "http://127.0.0.1:18790/anthropic"

修改上游地址(proxy.py 中的 --upstream 默认值):

parser.add_argument("--upstream", default="https://your-actual-api-endpoint/anthropic", ...)

⚠️ 修改 openclaw.json 后需重启 Gateway 才生效,重启前请与用户确认。


📁 文件说明

文件 用途
proxy.py 透明代理服务(Python asyncio + aiohttp)
log_viewer.py 终端查看器(彩色输出,支持飞书文档)
log-viewer.html 网页查看器(零依赖,双击打开)
install.sh 一键安装脚本

📊 日志字段说明

字段 说明
timestamp ISO 时间(含时区)
request_id UUID
streaming 是否流式请求
request_body 完整请求(model、system、messages)
response_status HTTP 状态码
response_body_parsed 解析后的响应(content、usage)
duration_ms 耗时(毫秒)

注意事项

  • 流式调用的 token 用量在 response_body_parsed.usage
  • API Key 自动脱敏(保留前8位后4位)
  • 飞书文档写入超时设为 120s,失败自动重试 3 次
  • 日志按天切割,单文件通常 \x3C 50MB,网页端可流畅处理
安全使用建议
Do NOT run the installer blindly. Key things to consider before installing: - The install script writes a macOS LaunchAgent and immediately starts the proxy. That proxy will forward your OpenClaw API traffic to the UPSTREAM value embedded in the plist. The shipped default upstream is 'http://model.mify.ai.srv/anthropic' — treat that as untrusted until you verify it. If you install, edit proxy.py or install.sh to set --upstream to your own model provider first, and verify the plist contents before load. - The proxy logs complete request bodies and raw SSE streams to disk. Sensitive information in request bodies (or misconfigured clients that put secrets in body) will be recorded. While header values are masked in the logs, the proxy still forwards original headers to the upstream service. - log_viewer.py contains hard-coded paths (/Users/xm_plus/...) that do not match the installer paths; update LOG_DIR and FEISHU_WRITE in log_viewer.py to match your environment. The feishu_write.py script referenced is not included — the feishu feature will fail or call an unknown path. - If you want to test: run proxy.py manually from the repo first with an explicit --upstream you control and without writing the LaunchAgent. Inspect the LaunchAgent plist file before loading it. Prefer running in a controlled environment or container and monitor outbound connections. - If you don't trust the author: review proxy.py carefully (it is included) and change/omit the default upstream; or avoid installing altogether. Consider firewalling the host or constraining the proxy to not auto-start until you've validated configuration.
功能分析
Type: OpenClaw Skill Name: api-logger Version: 1.2.0 The bundle implements a Man-in-the-Middle (MitM) proxy (`proxy.py`) designed to intercept and log all LLM API traffic, including full prompts and responses. It includes an installation script (`install.sh`) that establishes persistence on macOS via a LaunchAgent and provides instructions to redirect the OpenClaw agent's communication through this local proxy. While the proxy includes a benign feature to mask API keys, the code contains hardcoded absolute paths to a specific user directory (`/Users/xm_plus/`) in `log_viewer.py` and `proxy.py`, and includes functionality to send logged data to an external platform (Feishu). The combination of traffic interception, persistence, and environment-specific hardcoding presents a significant security risk, although it lacks clear evidence of intentional malice beyond its stated debugging purpose.
能力评估
Purpose & Capability
The files implement a local logging proxy and viewer which matches the name/description, but the installer (install.sh) embeds a default upstream URL (UPSTREAM="http://model.mify.ai.srv/anthropic") and writes that into a LaunchAgent which it immediately loads. That means after running the installer the proxy will forward all proxied API calls to that default external host unless the user edits the upstream first — a surprising and potentially dangerous default. Also the code and README assume macOS launchctl behavior, but the skill metadata declared no OS restriction.
Instruction Scope
SKILL.md instructs creating a local transparent proxy and changing OpenClaw baseUrl to point to it — expected. However the installer itself copies files, creates log dirs, writes a LaunchAgent plist and starts the service automatically using the default upstream. The proxy logs full request bodies and SSE raw streams to disk; although headers are masked in logs, the proxy still forwards original headers to upstream. The instructions rely on the user to manually change upstream after install, but the install step already starts the service with the unsafe default.
Install Mechanism
No remote code download is performed, only local file copying and pip3 install aiohttp. However the installer writes a persistent LaunchAgent and launches it (macOS-specific), and it launches the proxy with the default UPSTREAM value embedded in the plist. Auto-starting a service that forwards traffic to a pre-set external host is a high-risk behavior if the default host is not trusted. The script also installs Python dependency via pip without a venv.
Credentials
The skill requests no environment variables or credentials (good). But log_viewer.py contains hard-coded absolute paths (LOG_DIR = Path("/Users/xm_plus/.openclaw/workspace/company/api-logs") and FEISHU_WRITE = Path("/Users/xm_plus/.openclaw/workspace/company/feishu_write.py")) which do not match the installer target ($HOME/.openclaw/...). Those hard-coded paths are inconsistent and could cause the viewer to read the wrong location or fail. The feishu integration depends on an external script at a fixed path that is not provided.
Persistence & Privilege
The installer creates a LaunchAgent plist with RunAtLoad and KeepAlive and immediately loads it via launchctl — granting persistent, automatic execution across reboots. While persistence is reasonable for a long-running proxy, combining automatic persistent startup with an untrusted default upstream increases blast radius; the skill does not request special platform privileges but it does modify user launch agents and runs network-forwarding code persistently.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install api-logger
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /api-logger 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.2.0
v1.2.0: 新增零依赖网页日志查看器(log-viewer.html),支持可视化过滤/完整对话/Token统计;SKILL.md大幅优化,完整使用说明+tags优化
v1.1.0
v1.1.0: 飞书写入超时 30s→120s;大日志截断保护(>300条);--stats --feishu 单独生成统计文档;统计逻辑抽离复用
v1.0.0
初始发布:透明代理拦截 LLM API 调用,记录完整 prompt/generation/token,支持终端查看和飞书文档输出
元数据
Slug api-logger
版本 1.2.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 3
常见问题

API Logger 是什么?

LLM API 调用日志记录、分析与可视化。透明代理拦截所有 LLM API 调用,记录完整 prompt/generation/token 用量, 附带零依赖网页日志查看器(支持多维过滤、完整对话展示、token 成本统计)。 适用场景:分析 API 调用成本、调试 prompt、查看历史对话记录、排查慢请求/... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 362 次。

如何安装 API Logger?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install api-logger」即可一键安装,无需额外配置。

API Logger 是免费的吗?

是的,API Logger 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

API Logger 支持哪些平台?

API Logger 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 API Logger?

由 xiaohuaishu(@xiaohuaishu)开发并维护,当前版本 v1.2.0。

💬 留言讨论