@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=
|
|
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 = (
|
|
3
|
-
const r =
|
|
4
|
-
return (
|
|
5
|
-
const
|
|
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:
|
|
9
|
+
content: a
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
include: !0,
|
|
13
13
|
command: "%s",
|
|
14
|
-
content:
|
|
14
|
+
content: x[t.level]
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
include: !0,
|
|
18
18
|
command: "%s",
|
|
19
|
-
content:
|
|
19
|
+
content: t.message.replace(
|
|
20
20
|
/(\r?\n)/g,
|
|
21
|
-
`$1${
|
|
21
|
+
`$1${a} ${m} `
|
|
22
22
|
)
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
include: Object.keys(
|
|
25
|
+
include: Object.keys(t.context).length > 0,
|
|
26
26
|
command: "%O",
|
|
27
|
-
content:
|
|
27
|
+
content: t.context
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
include:
|
|
30
|
+
include: t.origin.length > 0,
|
|
31
31
|
command: "%s",
|
|
32
|
-
content: `${l}${
|
|
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
|
-
},
|
|
38
|
-
const r =
|
|
39
|
-
return `[${r}:${m}:${
|
|
40
|
-
},
|
|
41
|
-
[c.trace]: `${
|
|
42
|
-
[c.debug]: `${
|
|
43
|
-
[c.info]: `${S}INFO${
|
|
44
|
-
[c.warn]: `${
|
|
45
|
-
[c.error]: `${d}ERROR${
|
|
46
|
-
[c.fatal]: `${g}${d}FATAL${
|
|
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.
|
|
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.
|
|
39
|
+
"@holz/core": "^0.8.0-rc.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@holz/core": "^0.8.0-rc.
|
|
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,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
|
-
//
|
|
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.
|
|
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} `,
|