loga-cli 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/bin/loga.js +23 -0
- package/install.js +77 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# loga-cli
|
|
2
|
+
|
|
3
|
+
日志分析 CLI —— 给 AI 助手(Claude Code / Codex / Openclaw / Hermes)排查 OpenObserve 线上报错、追 trace、定位代码。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -g loga-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
安装时按你的系统自动下载对应二进制(Windows / macOS / Linux,x64 / arm64)。
|
|
12
|
+
|
|
13
|
+
> 没有 Node 也能装,用 curl:
|
|
14
|
+
> ```bash
|
|
15
|
+
> curl -fsSL https://loga-cli.990203.xyz/install.sh | sh # macOS / Linux
|
|
16
|
+
> irm https://loga-cli.990203.xyz/install.ps1 | iex # Windows PowerShell
|
|
17
|
+
> ```
|
|
18
|
+
|
|
19
|
+
## 配置(每人填自己的账号)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
loga install # 按提示填你自己的 OpenObserve 账号密码(地址已内置;只存本机、不上传)
|
|
23
|
+
loga status # 验证
|
|
24
|
+
loga scan --minutes 30
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
默认查线上环境;查测试环境给命令加 `--env test`。
|
|
28
|
+
|
|
29
|
+
## 常用
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
loga scan --minutes 30 # 全局报错体检
|
|
33
|
+
loga detail --app <服务id> # 单服务详细报错
|
|
34
|
+
loga trace --id <trace_id> # 追链路
|
|
35
|
+
loga help # 完整工作流
|
|
36
|
+
```
|
package/bin/loga.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 薄壳:把参数原样转发给 postinstall 下载好的真二进制(bin/loga-bin)。
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
const isWin = process.platform === "win32";
|
|
8
|
+
const bin = path.join(__dirname, isWin ? "loga-bin.exe" : "loga-bin");
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(bin)) {
|
|
11
|
+
console.error(
|
|
12
|
+
"[loga] 未找到二进制,安装可能未完成。重装:npm i -g loga-cli" +
|
|
13
|
+
"\n[loga] 或用 curl:curl -fsSL https://loga-cli.990203.xyz/install.sh | sh"
|
|
14
|
+
);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const r = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
19
|
+
if (r.error) {
|
|
20
|
+
console.error(`[loga] 启动失败:${r.error.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
process.exit(r.status === null ? 1 : r.status);
|
package/install.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// postinstall:按当前平台从 CDN 下载对应 loga 二进制(gzip 压缩),解压到 bin/loga-bin。
|
|
2
|
+
// 不把二进制塞进 npm 包——保持包体积极小,复用已有下载站。
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const zlib = require("zlib");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
const BASE_URL = "https://loga-cli.990203.xyz";
|
|
9
|
+
|
|
10
|
+
// 平台 + 架构 → 下载站上的二进制文件名。
|
|
11
|
+
function resolveBinName() {
|
|
12
|
+
const platform = process.platform; // 'darwin' | 'linux' | 'win32'
|
|
13
|
+
const arch = process.arch; // 'x64' | 'arm64' | ...
|
|
14
|
+
const archMap = { x64: "amd64", arm64: "arm64" };
|
|
15
|
+
const a = archMap[arch];
|
|
16
|
+
if (platform === "win32") {
|
|
17
|
+
// Windows 仅提供 amd64。
|
|
18
|
+
if (arch !== "x64") return null;
|
|
19
|
+
return "loga-windows-amd64.exe";
|
|
20
|
+
}
|
|
21
|
+
if (platform === "darwin" && a) return `loga-darwin-${a}`;
|
|
22
|
+
if (platform === "linux" && a) return `loga-linux-${a}`;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function download(url) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
https
|
|
29
|
+
.get(url, (res) => {
|
|
30
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
31
|
+
// 跟随重定向
|
|
32
|
+
download(res.headers.location).then(resolve, reject);
|
|
33
|
+
res.resume();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (res.statusCode !== 200) {
|
|
37
|
+
reject(new Error(`下载失败 HTTP ${res.statusCode}: ${url}`));
|
|
38
|
+
res.resume();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const chunks = [];
|
|
42
|
+
res.on("data", (c) => chunks.push(c));
|
|
43
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
44
|
+
})
|
|
45
|
+
.on("error", reject);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function main() {
|
|
50
|
+
const binName = resolveBinName();
|
|
51
|
+
if (!binName) {
|
|
52
|
+
console.error(
|
|
53
|
+
`[loga] 暂无适配 ${process.platform}/${process.arch} 的预编译二进制。` +
|
|
54
|
+
`\n[loga] 可改用 curl 安装:curl -fsSL ${BASE_URL}/install.sh | sh`
|
|
55
|
+
);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const isWin = process.platform === "win32";
|
|
60
|
+
const outDir = path.join(__dirname, "bin");
|
|
61
|
+
const outBin = path.join(outDir, isWin ? "loga-bin.exe" : "loga-bin");
|
|
62
|
+
const url = `${BASE_URL}/${binName}.gz`;
|
|
63
|
+
|
|
64
|
+
console.log(`[loga] 下载 ${binName}(gzip 压缩,约 3MB)...`);
|
|
65
|
+
const gz = await download(url);
|
|
66
|
+
const raw = zlib.gunzipSync(gz);
|
|
67
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
68
|
+
fs.writeFileSync(outBin, raw);
|
|
69
|
+
if (!isWin) fs.chmodSync(outBin, 0o755);
|
|
70
|
+
console.log(`[loga] 已安装。运行 loga install 配置你自己的账号(只存本机、不上传)。`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch((e) => {
|
|
74
|
+
console.error(`[loga] 安装失败:${e.message}`);
|
|
75
|
+
console.error(`[loga] 可改用 curl 安装:curl -fsSL ${BASE_URL}/install.sh | sh`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "loga-cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "日志分析 CLI —— 给 AI 助手排查 OpenObserve 线上报错、追 trace、定位代码。安装后跑 loga install 配你自己的账号。",
|
|
5
|
+
"bin": {
|
|
6
|
+
"loga": "bin/loga.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/loga.js",
|
|
13
|
+
"install.js"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=14"
|
|
17
|
+
},
|
|
18
|
+
"os": [
|
|
19
|
+
"darwin",
|
|
20
|
+
"linux",
|
|
21
|
+
"win32"
|
|
22
|
+
],
|
|
23
|
+
"cpu": [
|
|
24
|
+
"x64",
|
|
25
|
+
"arm64"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"loga",
|
|
29
|
+
"openobserve",
|
|
30
|
+
"log",
|
|
31
|
+
"cli",
|
|
32
|
+
"trace"
|
|
33
|
+
],
|
|
34
|
+
"license": "UNLICENSED",
|
|
35
|
+
"private": false
|
|
36
|
+
}
|