@thi.ng/rstream-log 4.1.86 → 4.1.88

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-18T13:41:20Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -68,7 +68,7 @@ For Node.js REPL:
68
68
  const rstreamLog = await import("@thi.ng/rstream-log");
69
69
  ```
70
70
 
71
- Package sizes (brotli'd, pre-treeshake): ESM: 856 bytes
71
+ Package sizes (brotli'd, pre-treeshake): ESM: 857 bytes
72
72
 
73
73
  ## Dependencies
74
74
 
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/console.js CHANGED
@@ -1 +1,4 @@
1
- export { trace as writeConsole } from "@thi.ng/rstream/trace";
1
+ import { trace } from "@thi.ng/rstream/trace";
2
+ export {
3
+ trace as writeConsole
4
+ };
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
- export const onlyLevel = (level) => filter((l) => l[0] === level);
4
- export const minLevel = (level) => filter((l) => l[0] >= level);
5
- export const maxLevel = (level) => filter((l) => l[0] <= level);
6
- export const matchID = (id) => filter(isString(id) ? (l) => l[1] === id : (l) => id.test(l[1]));
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
- export const isoDate = (dt) => new Date(dt).toISOString();
5
- export const formatString = (dtFmt, bodyFmt) => {
6
- dtFmt = dtFmt || isoDate;
7
- bodyFmt = bodyFmt || ((x) => x.map(stringify()).join(" "));
8
- return map(([level, id, time, ...body]) => `[${LogLevel[level]}] ${id}: ${dtFmt(time)} ${bodyFmt(body)}`);
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
- * Takes an array of regex patterns and optional `mask` string. Returns
12
- * transducer which replaces all found pattern occurrences with `mask`.
13
- * Intended to be used in combination / after {@link formatString} to avoid
14
- * leaking of sensitive information via logged messages.
15
- *
16
- *
17
- * @example
18
- * ```ts
19
- * logger.transform(
20
- * formatString(),
21
- * maskSecrets([/(?<=[A-Z0-9_]\=)\w+/g])
22
- * ).subscribe(
23
- * writeConsole()
24
- * );
25
- *
26
- * logger.info("logged in USER=toxi, using TOKEN=123456");
27
- * // [INFO] logger-0: logged in USER=****, using TOKEN=****
28
- * ```
29
- *
30
- * @param patterns -
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
- export 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 &&
55
- super.next([level, this.id, Date.now(), ...args]);
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.86",
3
+ "version": "4.1.88",
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 clean && tsc --declaration",
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,16 +35,17 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/errors": "^2.4.5",
39
- "@thi.ng/logger": "^2.0.1",
40
- "@thi.ng/rstream": "^8.2.13",
41
- "@thi.ng/strings": "^3.7.2",
42
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/api": "^8.9.13",
39
+ "@thi.ng/checks": "^3.4.13",
40
+ "@thi.ng/errors": "^2.4.7",
41
+ "@thi.ng/logger": "^2.1.0",
42
+ "@thi.ng/rstream": "^8.2.15",
43
+ "@thi.ng/strings": "^3.7.4",
44
+ "@thi.ng/transducers": "^8.8.16"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@microsoft/api-extractor": "^7.38.3",
48
+ "esbuild": "^0.19.8",
46
49
  "rimraf": "^5.0.5",
47
50
  "tools": "^0.0.1",
48
51
  "typedoc": "^0.25.4",
@@ -63,7 +66,7 @@
63
66
  "access": "public"
64
67
  },
65
68
  "engines": {
66
- "node": ">=12.7"
69
+ "node": ">=18"
67
70
  },
68
71
  "files": [
69
72
  "./*.js",
@@ -96,5 +99,5 @@
96
99
  ],
97
100
  "year": 2017
98
101
  },
99
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
102
+ "gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
100
103
  }