@hasna/logs 0.3.4 → 0.3.6

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-fzmz9aqs.js";
5
+ } from "../index-4hj4sakk.js";
6
6
  import {
7
7
  createPage,
8
8
  createProject,
@@ -12,7 +12,7 @@ import {
12
12
  listProjects,
13
13
  resolveProjectId,
14
14
  summarizeLogs
15
- } from "../index-5tvnhvgr.js";
15
+ } from "../index-86j0hn03.js";
16
16
  import {
17
17
  createJob,
18
18
  listJobs
@@ -2137,21 +2137,54 @@ 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;
2143
2174
  return resolveProjectId(getDb(), nameOrId) ?? nameOrId;
2144
2175
  }
2145
2176
  var program2 = new Command().name("logs").description("@hasna/logs \u2014 log aggregation and monitoring").version("0.0.1");
2146
- program2.command("list").description("Search and list logs").option("--project <name|id>", "Filter by project name or ID").option("--page <id>", "Filter by page ID").option("--level <levels>", "Comma-separated levels (error,warn,info,debug,fatal)").option("--service <name>", "Filter by service").option("--since <iso>", "Since timestamp or relative (1h, 24h, 7d)").option("--text <query>", "Full-text search").option("--limit <n>", "Max results", "100").option("--format <fmt>", "Output format: table|json|compact", "table").action((opts) => {
2177
+ program2.command("list").description("Search and list logs").option("--project <name|id>", "Filter by project name or ID").option("--page <id>", "Filter by page ID").option("--level <levels>", "Comma-separated levels (error,warn,info,debug,fatal)").option("--service <name>", "Filter by service").option("--since <iso>", "Since timestamp or relative (1h, 24h, 7d)").option("--until <iso>", "Until timestamp or relative (e.g. logs list --since 2h --until 1h)").option("--text <query>", "Full-text search").option("--limit <n>", "Max results", "100").option("--format <fmt>", "Output format: table|json|compact", "table").action((opts) => {
2147
2178
  const db = getDb();
2148
2179
  const since = parseRelativeTime(opts.since);
2180
+ const until = parseRelativeTime(opts.until);
2149
2181
  const rows = searchLogs(db, {
2150
2182
  project_id: resolveProject(opts.project),
2151
2183
  page_id: opts.page,
2152
2184
  level: opts.level ? opts.level.split(",") : undefined,
2153
2185
  service: opts.service,
2154
2186
  since,
2187
+ until,
2155
2188
  text: opts.text,
2156
2189
  limit: Number(opts.limit)
2157
2190
  });
@@ -2166,7 +2199,7 @@ program2.command("list").description("Search and list logs").option("--project <
2166
2199
  }
2167
2200
  for (const r of rows) {
2168
2201
  const meta = r.metadata ? ` ${r.metadata}` : "";
2169
- console.log(`${r.timestamp} ${pad(r.level.toUpperCase(), 5)} ${pad(r.service ?? "-", 12)} ${r.message}${meta}`);
2202
+ console.log(`${colorRow(r.timestamp, r.level, r.service ?? "-", r.message)}${meta}`);
2170
2203
  }
2171
2204
  console.log(`
2172
2205
  ${rows.length} log(s)`);
@@ -2174,16 +2207,16 @@ ${rows.length} log(s)`);
2174
2207
  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
2208
  const rows = tailLogs(getDb(), resolveProject(opts.project), Number(opts.n));
2176
2209
  for (const r of rows)
2177
- console.log(`${r.timestamp} ${pad(r.level.toUpperCase(), 5)} ${r.message}`);
2210
+ console.log(colorRow(r.timestamp, r.level, r.service ?? "-", r.message));
2178
2211
  });
2179
- 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
- const summary = summarizeLogs(getDb(), resolveProject(opts.project), parseRelativeTime(opts.since));
2212
+ 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").option("--until <time>", "Upper bound time").action((opts) => {
2213
+ const summary = summarizeLogs(getDb(), resolveProject(opts.project), parseRelativeTime(opts.since), parseRelativeTime(opts.until));
2181
2214
  if (!summary.length) {
2182
2215
  console.log("No errors/warnings in this window.");
2183
2216
  return;
2184
2217
  }
2185
2218
  for (const s of summary)
2186
- console.log(`${pad(s.level.toUpperCase(), 5)} ${pad(s.service ?? "-", 15)} count=${s.count} latest=${s.latest}`);
2219
+ console.log(`${colorLevel(s.level)} ${C.cyan}${pad(s.service ?? "-", 15)}${C.reset} count=${s.count} latest=${s.latest}`);
2187
2220
  });
2188
2221
  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
2222
  const row = ingestLog(getDb(), { level: opts.level, message, service: opts.service, project_id: resolveProject(opts.project), trace_id: opts.trace });