@holz/console-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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={fatal:60,error:50,warn:40,info:30,debug:20,trace:10},c=1e3,i=60*c,u=60*i,f=24*u,g=(a,s=a)=>{const t=a.getTime()-s.getTime(),e=Math.abs(t),n=t<0?"":"+";return e>=f?`${n}${Math.round(t/f)}d`:e>=u?`${n}${Math.round(t/u)}h`:e>=i?`${n}${Math.round(t/i)}m`:e>=c?`${n}${Math.round(t/c)}s`:`${n}${t}ms`},$=(a={})=>{const s=a.console??console;let t;return e=>{const n=new Date(e.timestamp),l=[{include:!0,format:"%s",values:[e.message]},{include:Object.keys(e.context).length>0,format:"%o",values:[e.context]},{include:!0,format:"%c%s",values:["color: gray",g(n,t)]},{include:e.origin.length>0,format:"%c%s",values:["color: rgba(128, 128, 128, 0.6); font-style: italic",e.origin.join(":")]}].filter(o=>o.include),m=l.map(o=>o.format).join(" "),d=l.flatMap(o=>o.values);s[h[e.level]](m,...d),t=n}},h={[r.trace]:"trace",[r.debug]:"debug",[r.info]:"info",[r.warn]:"warn",[r.error]:"error",[r.fatal]:"error"};exports.createConsoleBackend=$;
|
|
@@ -11,14 +11,14 @@ const r = {
|
|
|
11
11
|
debug: 20,
|
|
12
12
|
/** Extremely detailed progress updates (usually hidden). */
|
|
13
13
|
trace: 10
|
|
14
|
-
}, c = 1e3,
|
|
15
|
-
const e =
|
|
16
|
-
return t >= f ? `${n}${Math.round(e / f)}d` : t >=
|
|
17
|
-
},
|
|
18
|
-
const
|
|
14
|
+
}, c = 1e3, i = 60 * c, u = 60 * i, f = 24 * u, $ = (a, s = a) => {
|
|
15
|
+
const e = a.getTime() - s.getTime(), t = Math.abs(e), n = e < 0 ? "" : "+";
|
|
16
|
+
return t >= f ? `${n}${Math.round(e / f)}d` : t >= u ? `${n}${Math.round(e / u)}h` : t >= i ? `${n}${Math.round(e / i)}m` : t >= c ? `${n}${Math.round(e / c)}s` : `${n}${e}ms`;
|
|
17
|
+
}, g = (a = {}) => {
|
|
18
|
+
const s = a.console ?? console;
|
|
19
19
|
let e;
|
|
20
20
|
return (t) => {
|
|
21
|
-
const n =
|
|
21
|
+
const n = new Date(t.timestamp), l = [
|
|
22
22
|
{
|
|
23
23
|
include: !0,
|
|
24
24
|
format: "%s",
|
|
@@ -43,10 +43,10 @@ const r = {
|
|
|
43
43
|
t.origin.join(":")
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
|
-
].filter((o) => o.include),
|
|
47
|
-
|
|
46
|
+
].filter((o) => o.include), m = l.map((o) => o.format).join(" "), d = l.flatMap((o) => o.values);
|
|
47
|
+
s[h[t.level]](m, ...d), e = n;
|
|
48
48
|
};
|
|
49
|
-
},
|
|
49
|
+
}, h = {
|
|
50
50
|
[r.trace]: "trace",
|
|
51
51
|
[r.debug]: "debug",
|
|
52
52
|
[r.info]: "info",
|
|
@@ -55,5 +55,5 @@ const r = {
|
|
|
55
55
|
[r.fatal]: "error"
|
|
56
56
|
};
|
|
57
57
|
export {
|
|
58
|
-
|
|
58
|
+
g as createConsoleBackend
|
|
59
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holz/console-backend",
|
|
3
|
-
"version": "0.8.0-rc.
|
|
3
|
+
"version": "0.8.0-rc.2",
|
|
4
4
|
"description": "A console backend for Holz",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"test:types": "tsc"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@holz/core": "^0.8.0-rc.
|
|
40
|
+
"@holz/core": "^0.8.0-rc.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@holz/core": "^0.8.0-rc.
|
|
43
|
+
"@holz/core": "^0.8.0-rc.2",
|
|
44
44
|
"@types/node": "^22.0.0",
|
|
45
45
|
"@vitest/coverage-v8": "^3.0.8",
|
|
46
46
|
"typescript": "^5.8.2",
|
package/src/console-backend.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
|
|
|
10
10
|
let lastTimestamp: Date;
|
|
11
11
|
|
|
12
12
|
return (log: Log) => {
|
|
13
|
-
const
|
|
13
|
+
const time = new Date(log.timestamp);
|
|
14
14
|
|
|
15
15
|
const segments = [
|
|
16
16
|
{
|
|
@@ -26,7 +26,7 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
|
|
|
26
26
|
{
|
|
27
27
|
include: true,
|
|
28
28
|
format: '%c%s',
|
|
29
|
-
values: ['color: gray', timeDelta(
|
|
29
|
+
values: ['color: gray', timeDelta(time, lastTimestamp)],
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
include: log.origin.length > 0,
|
|
@@ -45,7 +45,7 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
|
|
|
45
45
|
output[sink[log.level]](format, ...values);
|
|
46
46
|
|
|
47
47
|
// Track the time spent between logs.
|
|
48
|
-
lastTimestamp =
|
|
48
|
+
lastTimestamp = time;
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|