@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 CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
  import {
4
4
  runJob
5
- } from "../index-wbsq8qjd.js";
5
+ } from "../index-fzmz9aqs.js";
6
6
  import {
7
7
  createPage,
8
8
  createProject,
@@ -24,7 +24,7 @@ import {
24
24
  __commonJS,
25
25
  __require,
26
26
  __toESM
27
- } from "../index-g8dczzvv.js";
27
+ } from "../index-re3ntm60.js";
28
28
 
29
29
  // node_modules/commander/lib/error.js
30
30
  var require_error = __commonJS((exports) => {
@@ -2235,7 +2235,7 @@ program2.command("scan").description("Run an immediate scan for a job").option("
2235
2235
  process.exit(1);
2236
2236
  }
2237
2237
  const db = getDb();
2238
- const job = (await import("../jobs-02z4fzsn.js")).getJob(db, opts.job);
2238
+ const job = (await import("../jobs-ypmmc2ma.js")).getJob(db, opts.job);
2239
2239
  if (!job) {
2240
2240
  console.error("Job not found");
2241
2241
  process.exit(1);
@@ -2244,9 +2244,15 @@ program2.command("scan").description("Run an immediate scan for a job").option("
2244
2244
  await runJob(db, job.id, job.project_id, job.page_id ?? undefined);
2245
2245
  console.log("Scan complete.");
2246
2246
  });
2247
- program2.command("watch").description("Stream new logs in real time with color coding").option("--project <id>").option("--level <levels>", "Comma-separated levels").option("--service <name>").action(async (opts) => {
2247
+ program2.command("watch").description("Stream new logs in real time with color coding").option("--project <name|id>", "Filter by project name or ID").option("--level <levels>", "Comma-separated levels (debug,info,warn,error,fatal)").option("--service <name>", "Filter by service name").option("--interval <ms>", "Poll interval in milliseconds (default: 500)", "500").option("--since <time>", "Start from this time (default: now)").action(async (opts) => {
2248
2248
  const db = getDb();
2249
- const { searchLogs: searchLogs2 } = await import("../query-tcg3bm9s.js");
2249
+ const { searchLogs: searchLogs2 } = await import("../query-shjjj67k.js");
2250
+ let projectId = opts.project;
2251
+ if (projectId) {
2252
+ const proj = db.query("SELECT id FROM projects WHERE id = ? OR name = ?").get(projectId, projectId);
2253
+ if (proj)
2254
+ projectId = proj.id;
2255
+ }
2250
2256
  const COLORS = {
2251
2257
  debug: "\x1B[90m",
2252
2258
  info: "\x1B[36m",
@@ -2256,15 +2262,16 @@ program2.command("watch").description("Stream new logs in real time with color c
2256
2262
  };
2257
2263
  const RESET = "\x1B[0m";
2258
2264
  const BOLD = "\x1B[1m";
2259
- let lastTimestamp = new Date().toISOString();
2265
+ let lastTimestamp = opts.since ? new Date(opts.since).toISOString() : new Date().toISOString();
2260
2266
  let errorCount = 0;
2261
2267
  let warnCount = 0;
2268
+ const pollIntervalMs = Math.max(100, Number(opts.interval) || 500);
2262
2269
  process.stdout.write(`\x1B[2J\x1B[H`);
2263
- console.log(`${BOLD}@hasna/logs watch${RESET} \u2014 Ctrl+C to exit
2270
+ console.log(`${BOLD}@hasna/logs watch${RESET} \u2014 Ctrl+C to exit${projectId ? ` [project: ${opts.project}]` : ""}
2264
2271
  `);
2265
2272
  const poll = () => {
2266
2273
  const rows = searchLogs2(db, {
2267
- project_id: opts.project,
2274
+ project_id: projectId,
2268
2275
  level: opts.level ? opts.level.split(",") : undefined,
2269
2276
  service: opts.service,
2270
2277
  since: lastTimestamp,
@@ -2286,7 +2293,7 @@ program2.command("watch").description("Stream new logs in real time with color c
2286
2293
  }
2287
2294
  process.stdout.write(`\x1B]2;logs: ${errorCount}E ${warnCount}W\x07`);
2288
2295
  };
2289
- const interval = setInterval(poll, 500);
2296
+ const interval = setInterval(poll, pollIntervalMs);
2290
2297
  process.on("SIGINT", () => {
2291
2298
  clearInterval(interval);
2292
2299
  console.log(`
@@ -2296,7 +2303,7 @@ Errors: ${errorCount} Warnings: ${warnCount}`);
2296
2303
  });
2297
2304
  });
2298
2305
  program2.command("export").description("Export logs to JSON or CSV").option("--project <id>").option("--since <time>", "Relative time or ISO").option("--level <level>").option("--service <name>").option("--format <fmt>", "json or csv", "json").option("--output <file>", "Output file (default: stdout)").option("--limit <n>", "Max rows", "100000").action(async (opts) => {
2299
- const { exportToCsv, exportToJson } = await import("../export-yjaar93b.js");
2306
+ const { exportToCsv, exportToJson } = await import("../export-c3eqjste.js");
2300
2307
  const { createWriteStream } = await import("fs");
2301
2308
  const db = getDb();
2302
2309
  const options = {
@@ -2322,7 +2329,7 @@ Exported ${count} log(s)
2322
2329
  }
2323
2330
  });
2324
2331
  program2.command("health").description("Show server health and DB stats").action(async () => {
2325
- const { getHealth } = await import("../health-egdb00st.js");
2332
+ const { getHealth } = await import("../health-9792c1rc.js");
2326
2333
  const h = getHealth(getDb());
2327
2334
  console.log(JSON.stringify(h, null, 2));
2328
2335
  });
@@ -0,0 +1,10 @@
1
+ // @bun
2
+ import {
3
+ exportToCsv,
4
+ exportToJson
5
+ } from "./index-eh9bkbpa.js";
6
+ import"./index-re3ntm60.js";
7
+ export {
8
+ exportToJson,
9
+ exportToCsv
10
+ };
@@ -0,0 +1,8 @@
1
+ // @bun
2
+ import {
3
+ getHealth
4
+ } from "./index-xjn8gam3.js";
5
+ import"./index-re3ntm60.js";
6
+ export {
7
+ getHealth
8
+ };