@holz/stream-backend 0.2.0 → 0.4.0
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,2 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});
|
|
2
|
-
`;this.stream.write(l)}stringifyContext(e){return Object.entries(e).map(([n,r])=>`${n}=${JSON.stringify(r)}`).join(" ")}multilineIndent(e,n){return n.replace(/(\r?\n)/g,r=>r+" ".repeat(e))}}const g={[i.Debug]:"DEBUG",[i.Info]:"INFO ",[i.Warn]:"WARN ",[i.Error]:"ERROR"};exports.StreamBackend=a;exports.default=a;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("node:os"),r=require("@holz/core");class i{constructor(e){this.stream=e.stream}processLog(e){const t=new Date().toISOString(),n=g[e.level],s=this.stringifyContext(e.context),c=e.origin.length?`[${e.origin.join(":")}] `:"",o=`${t} ${n} ${c}`,a=this.multilineIndent(o.length,e.message),l=`${o}${a}${s?" "+s:""}${u.EOL}`;this.stream.write(l)}stringifyContext(e){return Object.entries(e).map(([t,n])=>`${t}=${JSON.stringify(n)}`).join(" ")}multilineIndent(e,t){return t.replace(/(\r?\n)/g,n=>n+" ".repeat(e))}}const g={[r.LogLevel.Debug]:"DEBUG",[r.LogLevel.Info]:"INFO ",[r.LogLevel.Warn]:"WARN ",[r.LogLevel.Error]:"ERROR"};exports.StreamBackend=i;exports.default=i;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { EOL as m } from "node:os";
|
|
2
|
+
import { LogLevel as r } from "@holz/core";
|
|
3
|
+
class p {
|
|
4
|
+
constructor(t) {
|
|
5
|
+
this.stream = t.stream;
|
|
5
6
|
}
|
|
6
|
-
processLog(
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
this.stream.write(u);
|
|
7
|
+
processLog(t) {
|
|
8
|
+
const e = new Date().toISOString(), n = g[t.level], s = this.stringifyContext(t.context), o = t.origin.length ? `[${t.origin.join(":")}] ` : "", i = `${e} ${n} ${o}`, c = this.multilineIndent(i.length, t.message), a = `${i}${c}${s ? " " + s : ""}${m}`;
|
|
9
|
+
this.stream.write(a);
|
|
10
10
|
}
|
|
11
11
|
// { id: 123, type: 'article' } -> 'id=123 type="article"'
|
|
12
|
-
stringifyContext(
|
|
13
|
-
return Object.entries(
|
|
12
|
+
stringifyContext(t) {
|
|
13
|
+
return Object.entries(t).map(([e, n]) => `${e}=${JSON.stringify(n)}`).join(" ");
|
|
14
14
|
}
|
|
15
15
|
// Some messages will ruin your output without proper indentation. Stack
|
|
16
16
|
// traces are a good example of this.
|
|
17
17
|
//
|
|
18
18
|
// Supports Unix + DOS line endings.
|
|
19
|
-
multilineIndent(
|
|
20
|
-
return
|
|
19
|
+
multilineIndent(t, e) {
|
|
20
|
+
return e.replace(
|
|
21
21
|
/(\r?\n)/g,
|
|
22
|
-
(
|
|
22
|
+
(n) => n + " ".repeat(t)
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
const g = {
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
27
|
+
[r.Debug]: "DEBUG",
|
|
28
|
+
[r.Info]: "INFO ",
|
|
29
|
+
[r.Warn]: "WARN ",
|
|
30
|
+
[r.Error]: "ERROR"
|
|
31
31
|
};
|
|
32
32
|
export {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
p as StreamBackend,
|
|
34
|
+
p as default
|
|
35
35
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holz/stream-backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Print logs to stdout or a file.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/holz-stream-backend.cjs",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"test:unit": "vitest --color --passWithNoTests",
|
|
39
39
|
"test:types": "tsc"
|
|
40
40
|
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@holz/core": "0.2.0"
|
|
43
|
+
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@holz/core": "0.2.0",
|
|
43
46
|
"@types/node": "^18.14.0",
|
package/src/stream-backend.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Writable } from 'node:stream';
|
|
2
|
+
import { EOL } from 'node:os';
|
|
2
3
|
import { LogLevel } from '@holz/core';
|
|
3
4
|
import type { Log, LogContext, LogProcessor } from '@holz/core';
|
|
4
5
|
|
|
@@ -25,7 +26,7 @@ export default class StreamBackend implements LogProcessor {
|
|
|
25
26
|
|
|
26
27
|
const header = `${currentTime} ${level} ${namespace}`;
|
|
27
28
|
const message = this.multilineIndent(header.length, log.message);
|
|
28
|
-
const output = `${header}${message}${context ? ' ' + context : ''}
|
|
29
|
+
const output = `${header}${message}${context ? ' ' + context : ''}${EOL}`;
|
|
29
30
|
|
|
30
31
|
// NOTE: If the stream applies backpressure, we will lose logs. I believe
|
|
31
32
|
// this is the right tradeoff. We can't prevent the app from generating
|