@hasna/logs 0.3.4 → 0.3.5
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/dist/cli/index.js +34 -3
- package/package.json +1 -1
- package/src/cli/index.ts +24 -3
package/dist/cli/index.js
CHANGED
|
@@ -2137,6 +2137,37 @@ var {
|
|
|
2137
2137
|
} = import__.default;
|
|
2138
2138
|
|
|
2139
2139
|
// src/cli/index.ts
|
|
2140
|
+
var C = {
|
|
2141
|
+
reset: "\x1B[0m",
|
|
2142
|
+
bold: "\x1B[1m",
|
|
2143
|
+
dim: "\x1B[2m",
|
|
2144
|
+
red: "\x1B[31m",
|
|
2145
|
+
yellow: "\x1B[33m",
|
|
2146
|
+
cyan: "\x1B[36m",
|
|
2147
|
+
gray: "\x1B[90m",
|
|
2148
|
+
bgRed: "\x1B[41m\x1B[97m",
|
|
2149
|
+
magenta: "\x1B[35m"
|
|
2150
|
+
};
|
|
2151
|
+
var LEVEL_COLOR = {
|
|
2152
|
+
fatal: C.bgRed,
|
|
2153
|
+
error: C.red,
|
|
2154
|
+
warn: C.yellow,
|
|
2155
|
+
info: "",
|
|
2156
|
+
debug: C.gray
|
|
2157
|
+
};
|
|
2158
|
+
function colorRow(ts, level, svc, msg) {
|
|
2159
|
+
const lc = LEVEL_COLOR[level.toLowerCase()] ?? "";
|
|
2160
|
+
const isTTY = process.stdout.isTTY;
|
|
2161
|
+
if (!isTTY)
|
|
2162
|
+
return `${ts} ${pad(level.toUpperCase(), 5)} ${pad(svc, 12)} ${msg}`;
|
|
2163
|
+
return `${C.dim}${ts}${C.reset} ${lc}${C.bold}${pad(level.toUpperCase(), 5)}${C.reset} ${C.cyan}${pad(svc, 12)}${C.reset} ${msg}`;
|
|
2164
|
+
}
|
|
2165
|
+
function colorLevel(level) {
|
|
2166
|
+
if (!process.stdout.isTTY)
|
|
2167
|
+
return pad(level.toUpperCase(), 5);
|
|
2168
|
+
const lc = LEVEL_COLOR[level.toLowerCase()] ?? "";
|
|
2169
|
+
return `${lc}${C.bold}${pad(level.toUpperCase(), 5)}${C.reset}`;
|
|
2170
|
+
}
|
|
2140
2171
|
function resolveProject(nameOrId) {
|
|
2141
2172
|
if (!nameOrId)
|
|
2142
2173
|
return;
|
|
@@ -2166,7 +2197,7 @@ program2.command("list").description("Search and list logs").option("--project <
|
|
|
2166
2197
|
}
|
|
2167
2198
|
for (const r of rows) {
|
|
2168
2199
|
const meta = r.metadata ? ` ${r.metadata}` : "";
|
|
2169
|
-
console.log(`${r.timestamp
|
|
2200
|
+
console.log(`${colorRow(r.timestamp, r.level, r.service ?? "-", r.message)}${meta}`);
|
|
2170
2201
|
}
|
|
2171
2202
|
console.log(`
|
|
2172
2203
|
${rows.length} log(s)`);
|
|
@@ -2174,7 +2205,7 @@ ${rows.length} log(s)`);
|
|
|
2174
2205
|
program2.command("tail").description("Show most recent logs").option("--project <name|id>", "Project name or ID").option("--n <count>", "Number of logs", "50").action((opts) => {
|
|
2175
2206
|
const rows = tailLogs(getDb(), resolveProject(opts.project), Number(opts.n));
|
|
2176
2207
|
for (const r of rows)
|
|
2177
|
-
console.log(
|
|
2208
|
+
console.log(colorRow(r.timestamp, r.level, r.service ?? "-", r.message));
|
|
2178
2209
|
});
|
|
2179
2210
|
program2.command("summary").description("Error/warn summary by service").option("--project <name|id>", "Project name or ID").option("--since <time>", "Relative time (1h, 24h, 7d)", "24h").action((opts) => {
|
|
2180
2211
|
const summary = summarizeLogs(getDb(), resolveProject(opts.project), parseRelativeTime(opts.since));
|
|
@@ -2183,7 +2214,7 @@ program2.command("summary").description("Error/warn summary by service").option(
|
|
|
2183
2214
|
return;
|
|
2184
2215
|
}
|
|
2185
2216
|
for (const s of summary)
|
|
2186
|
-
console.log(`${
|
|
2217
|
+
console.log(`${colorLevel(s.level)} ${C.cyan}${pad(s.service ?? "-", 15)}${C.reset} count=${s.count} latest=${s.latest}`);
|
|
2187
2218
|
});
|
|
2188
2219
|
program2.command("push <message>").description("Push a log entry").option("--level <level>", "Log level", "info").option("--service <name>").option("--project <name|id>", "Project name or ID").option("--trace <id>", "Trace ID").action((message, opts) => {
|
|
2189
2220
|
const row = ingestLog(getDb(), { level: opts.level, message, service: opts.service, project_id: resolveProject(opts.project), trace_id: opts.trace });
|
package/package.json
CHANGED
package/src/cli/index.ts
CHANGED
|
@@ -9,6 +9,27 @@ import { createPage, createProject, listPages, listProjects, resolveProjectId }
|
|
|
9
9
|
import { runJob } from "../lib/scheduler.ts"
|
|
10
10
|
import type { LogLevel } from "../types/index.ts"
|
|
11
11
|
|
|
12
|
+
// ── Color helpers ──────────────────────────────────────────
|
|
13
|
+
const C = {
|
|
14
|
+
reset: "\x1b[0m", bold: "\x1b[1m", dim: "\x1b[2m",
|
|
15
|
+
red: "\x1b[31m", yellow: "\x1b[33m", cyan: "\x1b[36m", gray: "\x1b[90m",
|
|
16
|
+
bgRed: "\x1b[41m\x1b[97m", magenta: "\x1b[35m",
|
|
17
|
+
};
|
|
18
|
+
const LEVEL_COLOR: Record<string, string> = {
|
|
19
|
+
fatal: C.bgRed, error: C.red, warn: C.yellow, info: "", debug: C.gray,
|
|
20
|
+
};
|
|
21
|
+
function colorRow(ts: string, level: string, svc: string, msg: string): string {
|
|
22
|
+
const lc = LEVEL_COLOR[level.toLowerCase()] ?? "";
|
|
23
|
+
const isTTY = process.stdout.isTTY;
|
|
24
|
+
if (!isTTY) return `${ts} ${pad(level.toUpperCase(), 5)} ${pad(svc, 12)} ${msg}`;
|
|
25
|
+
return `${C.dim}${ts}${C.reset} ${lc}${C.bold}${pad(level.toUpperCase(), 5)}${C.reset} ${C.cyan}${pad(svc, 12)}${C.reset} ${msg}`;
|
|
26
|
+
}
|
|
27
|
+
function colorLevel(level: string): string {
|
|
28
|
+
if (!process.stdout.isTTY) return pad(level.toUpperCase(), 5);
|
|
29
|
+
const lc = LEVEL_COLOR[level.toLowerCase()] ?? "";
|
|
30
|
+
return `${lc}${C.bold}${pad(level.toUpperCase(), 5)}${C.reset}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
/** Resolve a project name or ID from CLI --project flag */
|
|
13
34
|
function resolveProject(nameOrId: string | undefined): string | undefined {
|
|
14
35
|
if (!nameOrId) return undefined;
|
|
@@ -50,7 +71,7 @@ program.command("list")
|
|
|
50
71
|
}
|
|
51
72
|
for (const r of rows) {
|
|
52
73
|
const meta = r.metadata ? ` ${r.metadata}` : ""
|
|
53
|
-
console.log(`${r.timestamp
|
|
74
|
+
console.log(`${colorRow(r.timestamp, r.level, r.service ?? "-", r.message)}${meta}`)
|
|
54
75
|
}
|
|
55
76
|
console.log(`\n${rows.length} log(s)`)
|
|
56
77
|
})
|
|
@@ -62,7 +83,7 @@ program.command("tail")
|
|
|
62
83
|
.option("--n <count>", "Number of logs", "50")
|
|
63
84
|
.action((opts) => {
|
|
64
85
|
const rows = tailLogs(getDb(), resolveProject(opts.project), Number(opts.n))
|
|
65
|
-
for (const r of rows) console.log(
|
|
86
|
+
for (const r of rows) console.log(colorRow(r.timestamp, r.level, r.service ?? "-", r.message))
|
|
66
87
|
})
|
|
67
88
|
|
|
68
89
|
// ── logs summary ──────────────────────────────────────────
|
|
@@ -73,7 +94,7 @@ program.command("summary")
|
|
|
73
94
|
.action((opts) => {
|
|
74
95
|
const summary = summarizeLogs(getDb(), resolveProject(opts.project), parseRelativeTime(opts.since))
|
|
75
96
|
if (!summary.length) { console.log("No errors/warnings in this window."); return }
|
|
76
|
-
for (const s of summary) console.log(`${
|
|
97
|
+
for (const s of summary) console.log(`${colorLevel(s.level)} ${C.cyan}${pad(s.service ?? "-", 15)}${C.reset} count=${s.count} latest=${s.latest}`)
|
|
77
98
|
})
|
|
78
99
|
|
|
79
100
|
// ── logs push ─────────────────────────────────────────────
|