@holz/console-backend 0.8.0-rc.2 → 0.8.0-rc.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.
@@ -1 +1 @@
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=$;
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,d=24*u,h=(a,s=a)=>{const t=a.getTime()-s.getTime(),e=Math.abs(t),n=t<0?"":"+";return e>=d?`${n}${Math.round(t/d)}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`},v=(a={})=>{const s=a.console??console;let t;return e=>{const n=new Date(e.timestamp),{error:l,...f}=e.context,m=[{include:!0,format:"%s",values:[e.message]},{include:Object.keys(f).length>0,format:"%o",values:[f]},{include:!0,format:"%c%s",values:["color: gray",h(n,t)]},{include:e.origin.length>0,format:"%c%s",values:["color: rgba(128, 128, 128, 0.6); font-style: italic",e.origin.join(":")]},{include:l,format:"%o",values:[l]}].filter(o=>o.include),g=m.map(o=>o.format).join(" "),$=m.flatMap(o=>o.values);s[b[e.level]](g,...$),t=n}},b={[r.trace]:"trace",[r.debug]:"debug",[r.info]:"info",[r.warn]:"warn",[r.error]:"error",[r.fatal]:"error"};exports.createConsoleBackend=v;
@@ -11,29 +11,29 @@ const r = {
11
11
  debug: 20,
12
12
  /** Extremely detailed progress updates (usually hidden). */
13
13
  trace: 10
14
- }, c = 1e3, i = 60 * c, u = 60 * i, f = 24 * u, $ = (a, s = a) => {
14
+ }, c = 1e3, i = 60 * c, u = 60 * i, d = 24 * u, h = (a, s = a) => {
15
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 = {}) => {
16
+ return t >= d ? `${n}${Math.round(e / d)}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
+ }, p = (a = {}) => {
18
18
  const s = a.console ?? console;
19
19
  let e;
20
20
  return (t) => {
21
- const n = new Date(t.timestamp), l = [
21
+ const n = new Date(t.timestamp), { error: l, ...f } = t.context, m = [
22
22
  {
23
23
  include: !0,
24
24
  format: "%s",
25
25
  values: [t.message]
26
26
  },
27
27
  {
28
- include: Object.keys(t.context).length > 0,
28
+ include: Object.keys(f).length > 0,
29
29
  format: "%o",
30
30
  // Chrome hides object content with `%O`.
31
- values: [t.context]
31
+ values: [f]
32
32
  },
33
33
  {
34
34
  include: !0,
35
35
  format: "%c%s",
36
- values: ["color: gray", $(n, e)]
36
+ values: ["color: gray", h(n, e)]
37
37
  },
38
38
  {
39
39
  include: t.origin.length > 0,
@@ -42,11 +42,16 @@ const r = {
42
42
  "color: rgba(128, 128, 128, 0.6); font-style: italic",
43
43
  t.origin.join(":")
44
44
  ]
45
+ },
46
+ {
47
+ include: l,
48
+ format: "%o",
49
+ values: [l]
45
50
  }
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;
51
+ ].filter((o) => o.include), $ = m.map((o) => o.format).join(" "), g = m.flatMap((o) => o.values);
52
+ s[v[t.level]]($, ...g), e = n;
48
53
  };
49
- }, h = {
54
+ }, v = {
50
55
  [r.trace]: "trace",
51
56
  [r.debug]: "debug",
52
57
  [r.info]: "info",
@@ -55,5 +60,5 @@ const r = {
55
60
  [r.fatal]: "error"
56
61
  };
57
62
  export {
58
- g as createConsoleBackend
63
+ p as createConsoleBackend
59
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holz/console-backend",
3
- "version": "0.8.0-rc.2",
3
+ "version": "0.8.0-rc.3",
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.2"
40
+ "@holz/core": "^0.8.0-rc.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@holz/core": "^0.8.0-rc.2",
43
+ "@holz/core": "^0.8.0-rc.3",
44
44
  "@types/node": "^22.0.0",
45
45
  "@vitest/coverage-v8": "^3.0.8",
46
46
  "typescript": "^5.8.2",
@@ -121,4 +121,17 @@ describe('Console backend', () => {
121
121
 
122
122
  expect(output[pipe].mock.calls[0]).toMatchSnapshot();
123
123
  });
124
+
125
+ it('includes the error object', () => {
126
+ const output = new MockConsole();
127
+ const backend = createConsoleBackend({ console: output });
128
+ const logger = createLogger(backend).namespace('hi');
129
+
130
+ const error = new Error('boom');
131
+ logger.error('an error occurred', { error });
132
+
133
+ expect(output.print).toHaveBeenCalledWith(
134
+ expect.stringContaining('Error: boom'),
135
+ );
136
+ });
124
137
  });
@@ -11,6 +11,7 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
11
11
 
12
12
  return (log: Log) => {
13
13
  const time = new Date(log.timestamp);
14
+ const { error, ...plainContext } = log.context;
14
15
 
15
16
  const segments = [
16
17
  {
@@ -19,9 +20,9 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
19
20
  values: [log.message],
20
21
  },
21
22
  {
22
- include: Object.keys(log.context).length > 0,
23
+ include: Object.keys(plainContext).length > 0,
23
24
  format: '%o', // Chrome hides object content with `%O`.
24
- values: [log.context],
25
+ values: [plainContext],
25
26
  },
26
27
  {
27
28
  include: true,
@@ -36,6 +37,11 @@ export const createConsoleBackend = (options: Options = {}): LogProcessor => {
36
37
  log.origin.join(':'),
37
38
  ],
38
39
  },
40
+ {
41
+ include: error,
42
+ format: '%o',
43
+ values: [error],
44
+ },
39
45
  ].filter((segment) => segment.include);
40
46
 
41
47
  const format = segments.map((segment) => segment.format).join(' ');