@holz/ansi-terminal-backend 0.8.0-rc.1 → 0.8.0-rc.2

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@holz/core"),o=t=>`\x1B[${t}`,e=o("0m"),p=o("1m"),$=o("2m"),d=o("31m"),S=o("32m"),v=o("33m"),b=o("34m"),f=o("36m"),A=(t={})=>{const r=t.console??console,l=" ".repeat(5);return n=>{const a=T(new Date),i=`${e}${$}${a}${e}`,m=[{include:!0,command:"%s",content:i},{include:!0,command:"%s",content:y[n.level]},{include:!0,command:"%s",content:n.message.replace(/(\r?\n)/g,`$1${i} ${l} `)},{include:Object.keys(n.context).length>0,command:"%O",content:n.context},{include:n.origin.length>0,command:"%s",content:`${$}${n.origin.join(":")}${e}`}].filter(s=>s.include),u=m.map(s=>s.command).join(" "),g=m.map(s=>s.content);r.error(u,...g)}},T=t=>{const r=t.getHours().toString().padStart(2,"0"),l=t.getMinutes().toString().padStart(2,"0"),n=t.getSeconds().toString().padStart(2,"0"),a=t.getMilliseconds().toString().padStart(3,"0");return`[${r}:${l}:${n}.${a}]`},y={[c.level.trace]:`${f}TRACE${e}`,[c.level.debug]:`${b}DEBUG${e}`,[c.level.info]:`${S}INFO${e} `,[c.level.warn]:`${v}WARN${e} `,[c.level.error]:`${d}ERROR${e}`,[c.level.fatal]:`${p}${d}FATAL${e}`};exports.createAnsiTerminalBackend=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@holz/core"),o=n=>`\x1B[${n}`,t=o("0m"),p=o("1m"),$=o("2m"),d=o("31m"),S=o("32m"),v=o("33m"),b=o("34m"),f=o("97m"),A=(n={})=>{const r=n.console??console,i=" ".repeat(5);return e=>{const a=h(new Date(e.timestamp)),l=`${t}${$}${a}${t}`,m=[{include:!0,command:"%s",content:l},{include:!0,command:"%s",content:T[e.level]},{include:!0,command:"%s",content:e.message.replace(/(\r?\n)/g,`$1${l} ${i} `)},{include:Object.keys(e.context).length>0,command:"%O",content:e.context},{include:e.origin.length>0,command:"%s",content:`${$}${e.origin.join(":")}${t}`}].filter(s=>s.include),u=m.map(s=>s.command).join(" "),g=m.map(s=>s.content);r.error(u,...g)}},h=n=>{const r=n.getHours().toString().padStart(2,"0"),i=n.getMinutes().toString().padStart(2,"0"),e=n.getSeconds().toString().padStart(2,"0"),a=n.getMilliseconds().toString().padStart(3,"0");return`[${r}:${i}:${e}.${a}]`},T={[c.level.trace]:`${f}TRACE${t}`,[c.level.debug]:`${b}DEBUG${t}`,[c.level.info]:`${S}INFO${t} `,[c.level.warn]:`${v}WARN${t} `,[c.level.error]:`${d}ERROR${t}`,[c.level.fatal]:`${p}${d}FATAL${t}`};exports.createAnsiTerminalBackend=A;
@@ -1,49 +1,49 @@
1
1
  import { level as c } from "@holz/core";
2
- const o = (n) => `\x1B[${n}`, t = o("0m"), g = o("1m"), l = o("2m"), d = o("31m"), S = o("32m"), f = o("33m"), b = o("34m"), A = o("36m"), v = (n = {}) => {
3
- const r = n.console ?? console, m = " ".repeat(5);
4
- return (e) => {
5
- const a = x(/* @__PURE__ */ new Date()), i = `${t}${l}${a}${t}`, $ = [
2
+ const o = (e) => `\x1B[${e}`, n = o("0m"), g = o("1m"), l = o("2m"), d = o("31m"), S = o("32m"), b = o("33m"), f = o("34m"), h = o("97m"), v = (e = {}) => {
3
+ const r = e.console ?? console, m = " ".repeat(5);
4
+ return (t) => {
5
+ const i = A(new Date(t.timestamp)), a = `${n}${l}${i}${n}`, $ = [
6
6
  {
7
7
  include: !0,
8
8
  command: "%s",
9
- content: i
9
+ content: a
10
10
  },
11
11
  {
12
12
  include: !0,
13
13
  command: "%s",
14
- content: R[e.level]
14
+ content: x[t.level]
15
15
  },
16
16
  {
17
17
  include: !0,
18
18
  command: "%s",
19
- content: e.message.replace(
19
+ content: t.message.replace(
20
20
  /(\r?\n)/g,
21
- `$1${i} ${m} `
21
+ `$1${a} ${m} `
22
22
  )
23
23
  },
24
24
  {
25
- include: Object.keys(e.context).length > 0,
25
+ include: Object.keys(t.context).length > 0,
26
26
  command: "%O",
27
- content: e.context
27
+ content: t.context
28
28
  },
29
29
  {
30
- include: e.origin.length > 0,
30
+ include: t.origin.length > 0,
31
31
  command: "%s",
32
- content: `${l}${e.origin.join(":")}${t}`
32
+ content: `${l}${t.origin.join(":")}${n}`
33
33
  }
34
34
  ].filter((s) => s.include), u = $.map((s) => s.command).join(" "), p = $.map((s) => s.content);
35
35
  r.error(u, ...p);
36
36
  };
37
- }, x = (n) => {
38
- const r = n.getHours().toString().padStart(2, "0"), m = n.getMinutes().toString().padStart(2, "0"), e = n.getSeconds().toString().padStart(2, "0"), a = n.getMilliseconds().toString().padStart(3, "0");
39
- return `[${r}:${m}:${e}.${a}]`;
40
- }, R = {
41
- [c.trace]: `${A}TRACE${t}`,
42
- [c.debug]: `${b}DEBUG${t}`,
43
- [c.info]: `${S}INFO${t} `,
44
- [c.warn]: `${f}WARN${t} `,
45
- [c.error]: `${d}ERROR${t}`,
46
- [c.fatal]: `${g}${d}FATAL${t}`
37
+ }, A = (e) => {
38
+ const r = e.getHours().toString().padStart(2, "0"), m = e.getMinutes().toString().padStart(2, "0"), t = e.getSeconds().toString().padStart(2, "0"), i = e.getMilliseconds().toString().padStart(3, "0");
39
+ return `[${r}:${m}:${t}.${i}]`;
40
+ }, x = {
41
+ [c.trace]: `${h}TRACE${n}`,
42
+ [c.debug]: `${f}DEBUG${n}`,
43
+ [c.info]: `${S}INFO${n} `,
44
+ [c.warn]: `${b}WARN${n} `,
45
+ [c.error]: `${d}ERROR${n}`,
46
+ [c.fatal]: `${g}${d}FATAL${n}`
47
47
  };
48
48
  export {
49
49
  v as createAnsiTerminalBackend
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holz/ansi-terminal-backend",
3
- "version": "0.8.0-rc.1",
3
+ "version": "0.8.0-rc.2",
4
4
  "description": "An ANSI terminal backend for Holz",
5
5
  "type": "module",
6
6
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "test:types": "tsc"
37
37
  },
38
38
  "peerDependencies": {
39
- "@holz/core": "^0.8.0-rc.1"
39
+ "@holz/core": "^0.8.0-rc.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@holz/core": "^0.8.0-rc.1",
42
+ "@holz/core": "^0.8.0-rc.2",
43
43
  "@types/node": "^22.0.0",
44
44
  "@vitest/coverage-v8": "^3.0.8",
45
45
  "typescript": "^5.8.2",
package/src/ansi-codes.ts CHANGED
@@ -17,3 +17,4 @@ export const blue = ansiCode('34m');
17
17
  export const magenta = ansiCode('35m');
18
18
  export const cyan = ansiCode('36m');
19
19
  export const white = ansiCode('37m');
20
+ export const brightWhite = ansiCode('97m');
@@ -17,7 +17,7 @@ export const createAnsiTerminalBackend = (
17
17
  const labelSizeInWhitespace = ' '.repeat(5); // char length of longest level type
18
18
 
19
19
  return (log: Log) => {
20
- const timestamp = formatAsTimestamp(new Date());
20
+ const timestamp = formatAsTimestamp(new Date(log.timestamp));
21
21
  const timestampPrefix = `${ansi.reset}${ansi.dim}${timestamp}${ansi.reset}`;
22
22
  const segments = [
23
23
  {
@@ -58,7 +58,8 @@ export const createAnsiTerminalBackend = (
58
58
  };
59
59
  };
60
60
 
61
- // ISO-8601 timestamp with milliseconds.
61
+ // This is an interactive TTY, so we can assume someone is watching. They
62
+ // probably know what day it is. Focus on the time.
62
63
  const formatAsTimestamp = (date: Date) => {
63
64
  const hours = date.getHours().toString().padStart(2, '0');
64
65
  const minutes = date.getMinutes().toString().padStart(2, '0');
@@ -70,7 +71,7 @@ const formatAsTimestamp = (date: Date) => {
70
71
 
71
72
  // Trailing whitespace is important for alignment.
72
73
  const logLevelLabel: Record<LogLevel, string> = {
73
- [level.trace]: `${ansi.cyan}TRACE${ansi.reset}`,
74
+ [level.trace]: `${ansi.brightWhite}TRACE${ansi.reset}`,
74
75
  [level.debug]: `${ansi.blue}DEBUG${ansi.reset}`,
75
76
  [level.info]: `${ansi.green}INFO${ansi.reset} `,
76
77
  [level.warn]: `${ansi.yellow}WARN${ansi.reset} `,