@hasna/logs 0.3.2 → 0.3.3
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 +18 -11
- package/dist/export-c3eqjste.js +10 -0
- package/dist/health-9792c1rc.js +8 -0
- package/dist/index-fzmz9aqs.js +1241 -0
- package/dist/index-re3ntm60.js +48 -0
- package/dist/index-xjn8gam3.js +39 -0
- package/dist/jobs-ypmmc2ma.js +22 -0
- package/dist/mcp/index.js +2 -2
- package/dist/query-shjjj67k.js +14 -0
- package/dist/server/index.js +3 -3
- package/package.json +1 -1
- package/src/cli/index.ts +17 -7
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __returnValue = (v) => v;
|
|
34
|
+
function __exportSetter(name, newValue) {
|
|
35
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
36
|
+
}
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, {
|
|
40
|
+
get: all[name],
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
set: __exportSetter.bind(all, name)
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
var __require = import.meta.require;
|
|
47
|
+
|
|
48
|
+
export { __toESM, __commonJS, __export, __require };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
__require
|
|
4
|
+
} from "./index-re3ntm60.js";
|
|
5
|
+
|
|
6
|
+
// src/lib/health.ts
|
|
7
|
+
var startTime = Date.now();
|
|
8
|
+
function getHealth(db) {
|
|
9
|
+
const projects = db.prepare("SELECT COUNT(*) as c FROM projects").get().c;
|
|
10
|
+
const total_logs = db.prepare("SELECT COUNT(*) as c FROM logs").get().c;
|
|
11
|
+
const scheduler_jobs = db.prepare("SELECT COUNT(*) as c FROM scan_jobs WHERE enabled = 1").get().c;
|
|
12
|
+
const open_issues = db.prepare("SELECT COUNT(*) as c FROM issues WHERE status = 'open'").get().c;
|
|
13
|
+
const levelRows = db.prepare("SELECT level, COUNT(*) as c FROM logs GROUP BY level").all();
|
|
14
|
+
const logs_by_level = Object.fromEntries(levelRows.map((r) => [r.level, r.c]));
|
|
15
|
+
const oldest = db.prepare("SELECT MIN(timestamp) as t FROM logs").get();
|
|
16
|
+
const newest = db.prepare("SELECT MAX(timestamp) as t FROM logs").get();
|
|
17
|
+
let db_size_bytes = null;
|
|
18
|
+
try {
|
|
19
|
+
const dbPath = process.env.LOGS_DB_PATH;
|
|
20
|
+
if (dbPath) {
|
|
21
|
+
const { statSync } = __require("fs");
|
|
22
|
+
db_size_bytes = statSync(dbPath).size;
|
|
23
|
+
}
|
|
24
|
+
} catch {}
|
|
25
|
+
return {
|
|
26
|
+
status: "ok",
|
|
27
|
+
uptime_seconds: Math.floor((Date.now() - startTime) / 1000),
|
|
28
|
+
db_size_bytes,
|
|
29
|
+
projects,
|
|
30
|
+
total_logs,
|
|
31
|
+
logs_by_level,
|
|
32
|
+
oldest_log: oldest.t,
|
|
33
|
+
newest_log: newest.t,
|
|
34
|
+
scheduler_jobs,
|
|
35
|
+
open_issues
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { getHealth };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createJob,
|
|
4
|
+
createScanRun,
|
|
5
|
+
deleteJob,
|
|
6
|
+
finishScanRun,
|
|
7
|
+
getJob,
|
|
8
|
+
listJobs,
|
|
9
|
+
listScanRuns,
|
|
10
|
+
updateJob
|
|
11
|
+
} from "./index-3dr7d80h.js";
|
|
12
|
+
import"./index-re3ntm60.js";
|
|
13
|
+
export {
|
|
14
|
+
updateJob,
|
|
15
|
+
listScanRuns,
|
|
16
|
+
listJobs,
|
|
17
|
+
getJob,
|
|
18
|
+
finishScanRun,
|
|
19
|
+
deleteJob,
|
|
20
|
+
createScanRun,
|
|
21
|
+
createJob
|
|
22
|
+
};
|
package/dist/mcp/index.js
CHANGED
|
@@ -35,12 +35,12 @@ import {
|
|
|
35
35
|
} from "../index-rbrsvsyh.js";
|
|
36
36
|
import {
|
|
37
37
|
getHealth
|
|
38
|
-
} from "../index-
|
|
38
|
+
} from "../index-xjn8gam3.js";
|
|
39
39
|
import {
|
|
40
40
|
__commonJS,
|
|
41
41
|
__export,
|
|
42
42
|
__toESM
|
|
43
|
-
} from "../index-
|
|
43
|
+
} from "../index-re3ntm60.js";
|
|
44
44
|
|
|
45
45
|
// node_modules/ajv/dist/compile/codegen/code.js
|
|
46
46
|
var require_code = __commonJS((exports) => {
|
package/dist/server/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
setPageAuth,
|
|
7
7
|
setRetentionPolicy,
|
|
8
8
|
startScheduler
|
|
9
|
-
} from "../index-
|
|
9
|
+
} from "../index-fzmz9aqs.js";
|
|
10
10
|
import {
|
|
11
11
|
countLogs
|
|
12
12
|
} from "../index-6y8pmes4.js";
|
|
@@ -50,8 +50,8 @@ import {
|
|
|
50
50
|
} from "../index-eh9bkbpa.js";
|
|
51
51
|
import {
|
|
52
52
|
getHealth
|
|
53
|
-
} from "../index-
|
|
54
|
-
import"../index-
|
|
53
|
+
} from "../index-xjn8gam3.js";
|
|
54
|
+
import"../index-re3ntm60.js";
|
|
55
55
|
|
|
56
56
|
// node_modules/hono/dist/compose.js
|
|
57
57
|
var compose = (middleware, onError, onNotFound) => {
|
package/package.json
CHANGED
package/src/cli/index.ts
CHANGED
|
@@ -154,29 +154,39 @@ program.command("scan")
|
|
|
154
154
|
// ── logs watch ────────────────────────────────────────────
|
|
155
155
|
program.command("watch")
|
|
156
156
|
.description("Stream new logs in real time with color coding")
|
|
157
|
-
.option("--project <id>")
|
|
158
|
-
.option("--level <levels>", "Comma-separated levels")
|
|
159
|
-
.option("--service <name>")
|
|
157
|
+
.option("--project <name|id>", "Filter by project name or ID")
|
|
158
|
+
.option("--level <levels>", "Comma-separated levels (debug,info,warn,error,fatal)")
|
|
159
|
+
.option("--service <name>", "Filter by service name")
|
|
160
|
+
.option("--interval <ms>", "Poll interval in milliseconds (default: 500)", "500")
|
|
161
|
+
.option("--since <time>", "Start from this time (default: now)")
|
|
160
162
|
.action(async (opts) => {
|
|
161
163
|
const db = getDb()
|
|
162
164
|
const { searchLogs } = await import("../lib/query.ts")
|
|
163
165
|
|
|
166
|
+
// Resolve project name → ID if needed
|
|
167
|
+
let projectId = opts.project
|
|
168
|
+
if (projectId) {
|
|
169
|
+
const proj = db.query("SELECT id FROM projects WHERE id = ? OR name = ?").get(projectId, projectId) as { id: string } | null
|
|
170
|
+
if (proj) projectId = proj.id
|
|
171
|
+
}
|
|
172
|
+
|
|
164
173
|
const COLORS: Record<string, string> = {
|
|
165
174
|
debug: "\x1b[90m", info: "\x1b[36m", warn: "\x1b[33m", error: "\x1b[31m", fatal: "\x1b[35m",
|
|
166
175
|
}
|
|
167
176
|
const RESET = "\x1b[0m"
|
|
168
177
|
const BOLD = "\x1b[1m"
|
|
169
178
|
|
|
170
|
-
let lastTimestamp = new Date().toISOString()
|
|
179
|
+
let lastTimestamp = opts.since ? new Date(opts.since).toISOString() : new Date().toISOString()
|
|
171
180
|
let errorCount = 0
|
|
172
181
|
let warnCount = 0
|
|
182
|
+
const pollIntervalMs = Math.max(100, Number(opts.interval) || 500)
|
|
173
183
|
|
|
174
184
|
process.stdout.write(`\x1b[2J\x1b[H`) // clear screen
|
|
175
|
-
console.log(`${BOLD}@hasna/logs watch${RESET} — Ctrl+C to exit\n`)
|
|
185
|
+
console.log(`${BOLD}@hasna/logs watch${RESET} — Ctrl+C to exit${projectId ? ` [project: ${opts.project}]` : ''}\n`)
|
|
176
186
|
|
|
177
187
|
const poll = () => {
|
|
178
188
|
const rows = searchLogs(db, {
|
|
179
|
-
project_id:
|
|
189
|
+
project_id: projectId,
|
|
180
190
|
level: opts.level ? (opts.level.split(",") as LogLevel[]) : undefined,
|
|
181
191
|
service: opts.service,
|
|
182
192
|
since: lastTimestamp,
|
|
@@ -199,7 +209,7 @@ program.command("watch")
|
|
|
199
209
|
process.stdout.write(`\x1b]2;logs: ${errorCount}E ${warnCount}W\x07`)
|
|
200
210
|
}
|
|
201
211
|
|
|
202
|
-
const interval = setInterval(poll,
|
|
212
|
+
const interval = setInterval(poll, pollIntervalMs)
|
|
203
213
|
process.on("SIGINT", () => { clearInterval(interval); console.log(`\n\nErrors: ${errorCount} Warnings: ${warnCount}`); process.exit(0) })
|
|
204
214
|
})
|
|
205
215
|
|