@thi.ng/rstream-log 5.0.6 → 5.1.1

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-25T14:07:53Z
3
+ - **Last updated**: 2024-03-01T15:22:50Z
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
@@ -1,16 +1,5 @@
1
1
  <!-- This file is generated - DO NOT EDIT! -->
2
2
  <!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
3
- > [!IMPORTANT]
4
- > ‼️ Announcing the thi.ng user survey 2024 📋
5
- >
6
- > [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
7
- > (open until end of February)
8
- >
9
- > **To achieve a better sample size, I'd highly appreciate if you could
10
- > circulate the link to this survey in your own networks.**
11
- >
12
- > [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
13
-
14
3
  # ![@thi.ng/rstream-log](https://media.thi.ng/umbrella/banners-20230807/thing-rstream-log.svg?8a1c5872)
15
4
 
16
5
  [![npm version](https://img.shields.io/npm/v/@thi.ng/rstream-log.svg)](https://www.npmjs.com/package/@thi.ng/rstream-log)
@@ -22,7 +11,7 @@
22
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
23
12
  > and anti-framework.
24
13
  >
25
- > 🚀 Help me to work full-time on these projects by [sponsoring me on
14
+ > 🚀 Please help me to work full-time on these projects by [sponsoring me on
26
15
  > GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
27
16
 
28
17
  - [About](#about)
@@ -83,7 +72,7 @@ For Node.js REPL:
83
72
  const rstreamLog = await import("@thi.ng/rstream-log");
84
73
  ```
85
74
 
86
- Package sizes (brotli'd, pre-treeshake): ESM: 750 bytes
75
+ Package sizes (brotli'd, pre-treeshake): ESM: 768 bytes
87
76
 
88
77
  ## Dependencies
89
78
 
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`.
@@ -31,6 +45,17 @@ export declare const formatString: (dtFmt?: DateFormat, bodyFmt?: BodyFormat) =>
31
45
  * @param mask -
32
46
  */
33
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
+ */
34
52
  export declare const formatObject: () => Transducer<LogEntry, LogEntryObj>;
35
- 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>;
36
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream-log",
3
- "version": "5.0.6",
3
+ "version": "5.1.1",
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.26",
39
- "@thi.ng/checks": "^3.5.0",
40
- "@thi.ng/logger": "^3.0.3",
41
- "@thi.ng/rstream": "^8.3.8",
42
- "@thi.ng/strings": "^3.7.17",
43
- "@thi.ng/transducers": "^8.9.7"
38
+ "@thi.ng/api": "^8.9.27",
39
+ "@thi.ng/checks": "^3.5.1",
40
+ "@thi.ng/logger": "^3.0.4",
41
+ "@thi.ng/rstream": "^8.3.9",
42
+ "@thi.ng/strings": "^3.7.19",
43
+ "@thi.ng/transducers": "^8.9.8"
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": "6e20f80dd9df1c8055ffa3c1e4d6f7598add0c0b\n"
100
+ "gitHead": "d660ae8fd1bf64d919b4334f19509f1f539d70f6\n"
101
101
  }