@thi.ng/rstream-log 4.1.85 → 4.1.87
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.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/console.js +4 -1
- package/filter.js +10 -4
- package/format.js +28 -38
- package/logger.js +53 -51
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/console.js
CHANGED
package/filter.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { isString } from "@thi.ng/checks/is-string";
|
|
2
2
|
import { filter } from "@thi.ng/transducers/filter";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const onlyLevel = (level) => filter((l) => l[0] === level);
|
|
4
|
+
const minLevel = (level) => filter((l) => l[0] >= level);
|
|
5
|
+
const maxLevel = (level) => filter((l) => l[0] <= level);
|
|
6
|
+
const matchID = (id) => filter(isString(id) ? (l) => l[1] === id : (l) => id.test(l[1]));
|
|
7
|
+
export {
|
|
8
|
+
matchID,
|
|
9
|
+
maxLevel,
|
|
10
|
+
minLevel,
|
|
11
|
+
onlyLevel
|
|
12
|
+
};
|
package/format.js
CHANGED
|
@@ -1,43 +1,33 @@
|
|
|
1
1
|
import { LogLevel } from "@thi.ng/logger/api";
|
|
2
2
|
import { stringify } from "@thi.ng/strings/stringify";
|
|
3
3
|
import { map } from "@thi.ng/transducers/map";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const isoDate = (dt) => new Date(dt).toISOString();
|
|
5
|
+
const formatString = (dtFmt, bodyFmt) => {
|
|
6
|
+
dtFmt = dtFmt || isoDate;
|
|
7
|
+
bodyFmt = bodyFmt || ((x) => x.map(stringify()).join(" "));
|
|
8
|
+
return map(
|
|
9
|
+
([level, id, time, ...body]) => `[${LogLevel[level]}] ${id}: ${dtFmt(time)} ${bodyFmt(body)}`
|
|
10
|
+
);
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @param mask -
|
|
32
|
-
*/
|
|
33
|
-
export const maskSecrets = (patterns, mask = "****") => map((msg) => patterns.reduce((acc, pat) => acc.replace(pat, mask), msg));
|
|
34
|
-
export const formatObject = () => map(([level, id, time, ...body]) => ({ level, id, time, body }));
|
|
35
|
-
export const formatJSON = (dtfmt) => {
|
|
36
|
-
dtfmt = dtfmt || isoDate;
|
|
37
|
-
return map(([level, id, time, ...body]) => JSON.stringify({
|
|
38
|
-
id,
|
|
39
|
-
level: LogLevel[level],
|
|
40
|
-
time: dtfmt(time),
|
|
41
|
-
body,
|
|
42
|
-
}));
|
|
12
|
+
const maskSecrets = (patterns, mask = "****") => map(
|
|
13
|
+
(msg) => patterns.reduce((acc, pat) => acc.replace(pat, mask), msg)
|
|
14
|
+
);
|
|
15
|
+
const formatObject = () => map(([level, id, time, ...body]) => ({ level, id, time, body }));
|
|
16
|
+
const formatJSON = (dtfmt) => {
|
|
17
|
+
dtfmt = dtfmt || isoDate;
|
|
18
|
+
return map(
|
|
19
|
+
([level, id, time, ...body]) => JSON.stringify({
|
|
20
|
+
id,
|
|
21
|
+
level: LogLevel[level],
|
|
22
|
+
time: dtfmt(time),
|
|
23
|
+
body
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
formatJSON,
|
|
29
|
+
formatObject,
|
|
30
|
+
formatString,
|
|
31
|
+
isoDate,
|
|
32
|
+
maskSecrets
|
|
43
33
|
};
|
package/logger.js
CHANGED
|
@@ -3,55 +3,57 @@ import { LogLevel } from "@thi.ng/logger/api";
|
|
|
3
3
|
import { CloseMode } from "@thi.ng/rstream/api";
|
|
4
4
|
import { __nextID } from "@thi.ng/rstream/idgen";
|
|
5
5
|
import { StreamMerge } from "@thi.ng/rstream/merge";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
6
|
+
class Logger extends StreamMerge {
|
|
7
|
+
level;
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
let id;
|
|
10
|
+
let level = LogLevel.FINE;
|
|
11
|
+
let src;
|
|
12
|
+
switch (args.length) {
|
|
13
|
+
case 0:
|
|
14
|
+
break;
|
|
15
|
+
case 1:
|
|
16
|
+
id = args[0];
|
|
17
|
+
break;
|
|
18
|
+
case 2:
|
|
19
|
+
[id, level] = args;
|
|
20
|
+
break;
|
|
21
|
+
case 3:
|
|
22
|
+
[id, src, level] = args;
|
|
23
|
+
src = [...src];
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
illegalArity(args.length);
|
|
27
|
+
}
|
|
28
|
+
id = id || `logger-${__nextID()}`;
|
|
29
|
+
super({ src, id, closeIn: CloseMode.NEVER, closeOut: CloseMode.NEVER });
|
|
30
|
+
this.level = level;
|
|
31
|
+
}
|
|
32
|
+
enabled(level) {
|
|
33
|
+
return this.level <= level;
|
|
34
|
+
}
|
|
35
|
+
next(x) {
|
|
36
|
+
x[0] >= this.level && super.next(x);
|
|
37
|
+
}
|
|
38
|
+
fine(...args) {
|
|
39
|
+
this.log(LogLevel.FINE, args);
|
|
40
|
+
}
|
|
41
|
+
debug(...args) {
|
|
42
|
+
this.log(LogLevel.DEBUG, args);
|
|
43
|
+
}
|
|
44
|
+
info(...args) {
|
|
45
|
+
this.log(LogLevel.INFO, args);
|
|
46
|
+
}
|
|
47
|
+
warn(...args) {
|
|
48
|
+
this.log(LogLevel.WARN, args);
|
|
49
|
+
}
|
|
50
|
+
severe(...args) {
|
|
51
|
+
this.log(LogLevel.SEVERE, args);
|
|
52
|
+
}
|
|
53
|
+
log(level, args) {
|
|
54
|
+
this.level <= level && super.next([level, this.id, Date.now(), ...args]);
|
|
55
|
+
}
|
|
57
56
|
}
|
|
57
|
+
export {
|
|
58
|
+
Logger
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream-log",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.87",
|
|
4
4
|
"description": "Structured, multilevel & hierarchical loggers based on @thi.ng/rstream",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc output xform",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,17 +35,17 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/errors": "^2.4.
|
|
39
|
-
"@thi.ng/logger": "^2.0.
|
|
40
|
-
"@thi.ng/rstream": "^8.2.
|
|
41
|
-
"@thi.ng/strings": "^3.7.
|
|
42
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/errors": "^2.4.6",
|
|
41
|
+
"@thi.ng/logger": "^2.0.2",
|
|
42
|
+
"@thi.ng/rstream": "^8.2.14",
|
|
43
|
+
"@thi.ng/strings": "^3.7.3",
|
|
44
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@microsoft/api-extractor": "^7.38.3",
|
|
46
|
-
"
|
|
48
|
+
"esbuild": "^0.19.8",
|
|
47
49
|
"rimraf": "^5.0.5",
|
|
48
50
|
"tools": "^0.0.1",
|
|
49
51
|
"typedoc": "^0.25.4",
|
|
@@ -97,5 +99,5 @@
|
|
|
97
99
|
],
|
|
98
100
|
"year": 2017
|
|
99
101
|
},
|
|
100
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
101
103
|
}
|