@thi.ng/rstream-log 5.0.5 → 5.1.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-02-22T11:59:16Z
3
+ - **Last updated**: 2024-02-28T14:23:30Z
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.
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [5.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-log@5.1.0) (2024-02-28)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update formatString() ([1ad60cc](https://github.com/thi-ng/umbrella/commit/1ad60cc))
17
+ - add support for msg post-processing in formatString()
18
+ - add/update docstrings
19
+
12
20
  ### [5.0.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream-log@5.0.1) (2024-02-16)
13
21
 
14
22
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -83,7 +83,7 @@ For Node.js REPL:
83
83
  const rstreamLog = await import("@thi.ng/rstream-log");
84
84
  ```
85
85
 
86
- Package sizes (brotli'd, pre-treeshake): ESM: 715 bytes
86
+ Package sizes (brotli'd, pre-treeshake): ESM: 768 bytes
87
87
 
88
88
  ## Dependencies
89
89
 
package/format.d.ts CHANGED
@@ -2,7 +2,21 @@ import { type LogEntry } from "@thi.ng/logger/api";
2
2
  import type { Transducer } from "@thi.ng/transducers";
3
3
  import type { BodyFormat, DateFormat, LogEntryObj } from "./api.js";
4
4
  export declare const isoDate: (dt: number) => string;
5
- export declare const formatString: (dtFmt?: DateFormat, bodyFmt?: BodyFormat) => Transducer<LogEntry, string>;
5
+ /**
6
+ * Log entry formatter/transducer. Formats a {@link LogEntry} tuple as string
7
+ * using optionally provided formatters.
8
+ *
9
+ * @remarks
10
+ * If `wrap` is given, it will be called with both the already formatted message
11
+ * string and the original log entry. The function can be used to post-process
12
+ * the message (e.g. to wrap it in ANSI color escape sequences, based on logger
13
+ * ID and/or level, also see [thi.ng/text-format](https://thi.ng/text-format))
14
+ *
15
+ * @param dateFmt
16
+ * @param bodyFmt
17
+ * @param wrap
18
+ */
19
+ export declare const formatString: (dateFmt?: DateFormat, bodyFmt?: BodyFormat, wrap?: ((msg: string, entry: LogEntry) => string) | undefined) => Transducer<LogEntry, string>;
6
20
  /**
7
21
  * Takes an array of regex patterns and optional `mask` string. Returns
8
22
  * transducer which replaces all found pattern occurrences with `mask`.
@@ -12,6 +26,10 @@ export declare const formatString: (dtFmt?: DateFormat, bodyFmt?: BodyFormat) =>
12
26
  *
13
27
  * @example
14
28
  * ```ts
29
+ * import { Logger, formatString, maskSecrets, writeConsole } from "@thi.ng/rstream-log";
30
+ *
31
+ * const logger = new Logger();
32
+ *
15
33
  * logger.transform(
16
34
  * formatString(),
17
35
  * maskSecrets([/(?<=[A-Z0-9_]\=)\w+/g])
@@ -27,6 +45,17 @@ export declare const formatString: (dtFmt?: DateFormat, bodyFmt?: BodyFormat) =>
27
45
  * @param mask -
28
46
  */
29
47
  export declare const maskSecrets: (patterns: RegExp[], mask?: string) => Transducer<string, string>;
48
+ /**
49
+ * Log entry transducer which converts a {@link LogEntry} tuple to a
50
+ * {@link LogEntryObj}.
51
+ */
30
52
  export declare const formatObject: () => Transducer<LogEntry, LogEntryObj>;
31
- export declare const formatJSON: (dtfmt?: DateFormat) => Transducer<LogEntry, string>;
53
+ /**
54
+ * Log entry formatter/transducer. Format a {@link LogEntry} tuple into a
55
+ * serialized JSON string (object keys: `id`, `level`, `time`, `body`), with the
56
+ * entry's timestamp formatted using given `dateFmt` (default: {@link isoDate}).
57
+ *
58
+ * @param dateFmt
59
+ */
60
+ export declare const formatJSON: (dateFmt?: DateFormat) => Transducer<LogEntry, string>;
32
61
  //# sourceMappingURL=format.d.ts.map
package/format.js CHANGED
@@ -2,24 +2,27 @@ 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
4
  const isoDate = (dt) => new Date(dt).toISOString();
5
- const formatString = (dtFmt, bodyFmt) => {
6
- dtFmt = dtFmt || isoDate;
5
+ const formatString = (dateFmt, bodyFmt, wrap) => {
6
+ dateFmt = dateFmt || isoDate;
7
7
  bodyFmt = bodyFmt || ((x) => x.map(stringify()).join(" "));
8
- return map(
9
- ([level, id, time, ...body]) => `[${LogLevel[level]}] ${id}: ${dtFmt(time)} ${bodyFmt(body)}`
10
- );
8
+ return map((entry) => {
9
+ const [level, id, time, ...body] = entry;
10
+ const date = dateFmt(time);
11
+ const res = `[${LogLevel[level]}] ${id}: ${date ? date + " " : ""}${bodyFmt(body)}`;
12
+ return wrap ? wrap(res, entry) : res;
13
+ });
11
14
  };
12
15
  const maskSecrets = (patterns, mask = "****") => map(
13
16
  (msg) => patterns.reduce((acc, pat) => acc.replace(pat, mask), msg)
14
17
  );
15
18
  const formatObject = () => map(([level, id, time, ...body]) => ({ level, id, time, body }));
16
- const formatJSON = (dtfmt) => {
17
- dtfmt = dtfmt || isoDate;
19
+ const formatJSON = (dateFmt) => {
20
+ dateFmt = dateFmt || isoDate;
18
21
  return map(
19
22
  ([level, id, time, ...body]) => JSON.stringify({
20
23
  id,
21
24
  level: LogLevel[level],
22
- time: dtfmt(time),
25
+ time: dateFmt(time),
23
26
  body
24
27
  })
25
28
  );
package/logger.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { ALogger } from "@thi.ng/logger/alogger";
2
2
  import { LogLevel, type ILogger, type LogEntry, type LogLevelName } from "@thi.ng/logger/api";
3
- import { Stream, type ISubscriber } from "@thi.ng/rstream";
3
+ import { type ISubscriber } from "@thi.ng/rstream/api";
4
+ import { Stream } from "@thi.ng/rstream/stream";
4
5
  export declare class Logger extends ALogger implements ISubscriber<LogEntry> {
5
6
  stream: Stream<LogEntry>;
6
- constructor(id: string, level?: LogLevel | LogLevelName, parent?: ILogger);
7
+ constructor(id?: string, level?: LogLevel | LogLevelName, parent?: ILogger);
7
8
  next(x: LogEntry): void;
8
9
  done(): void;
9
10
  error(e: Error): boolean;
package/logger.js CHANGED
@@ -2,11 +2,13 @@ import { ALogger } from "@thi.ng/logger/alogger";
2
2
  import {
3
3
  LogLevel
4
4
  } from "@thi.ng/logger/api";
5
- import { CloseMode, Stream } from "@thi.ng/rstream";
5
+ import { CloseMode } from "@thi.ng/rstream/api";
6
+ import { Stream } from "@thi.ng/rstream/stream";
7
+ import { __nextID } from "@thi.ng/rstream/idgen";
6
8
  class Logger extends ALogger {
7
9
  stream;
8
10
  constructor(id, level, parent) {
9
- super(id, level, parent);
11
+ super(id || `logger-${__nextID()}`, level, parent);
10
12
  this.stream = new Stream({
11
13
  id: this.id,
12
14
  closeOut: CloseMode.NEVER
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream-log",
3
- "version": "5.0.5",
3
+ "version": "5.1.0",
4
4
  "description": "Structured, multilevel & hierarchical loggers based on @thi.ng/rstream",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,12 +35,12 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.9.25",
38
+ "@thi.ng/api": "^8.9.26",
39
39
  "@thi.ng/checks": "^3.5.0",
40
- "@thi.ng/logger": "^3.0.2",
41
- "@thi.ng/rstream": "^8.3.7",
42
- "@thi.ng/strings": "^3.7.16",
43
- "@thi.ng/transducers": "^8.9.6"
40
+ "@thi.ng/logger": "^3.0.3",
41
+ "@thi.ng/rstream": "^8.3.8",
42
+ "@thi.ng/strings": "^3.7.18",
43
+ "@thi.ng/transducers": "^8.9.7"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@microsoft/api-extractor": "^7.40.1",
@@ -97,5 +97,5 @@
97
97
  ],
98
98
  "year": 2017
99
99
  },
100
- "gitHead": "16f2b92b5410bd35dcde6c2971c8e62783ebc472\n"
100
+ "gitHead": "190d68e7f7524631b333cfdbf32c6a23be27c166\n"
101
101
  }