@bymax-one/nest-logger 1.4.26 → 1.4.28
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 +53 -2
- package/README.md +2 -1
- package/dist/server/index.cjs +134 -39
- package/dist/server/index.mjs +134 -39
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,55 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.28] - 2026-11-21
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- The options are read once: the snapshot that passes validation is the one the defaults are made from,
|
|
20
|
+
including the `service` metadata, each list (`redactPaths`, `errorOwnFieldNames`, `destinations`,
|
|
21
|
+
`http.excludePaths`, `http.secretPathSegments`, read element by element) and the `serializers` table.
|
|
22
|
+
A getter or a Proxy that answered differently on a second read could pass the validator and then
|
|
23
|
+
change, and the module builder now receives the same copy.
|
|
24
|
+
- The derived keys (`exception.type` and the others) are compared with the same folding as the other
|
|
25
|
+
owned keys, with the separators kept: a variation selector, a line or paragraph separator, a
|
|
26
|
+
combining mark or a lookalike letter no longer lets a spelling of them through; `exception_type`,
|
|
27
|
+
`exceptionType` and `errorType` are still the caller's.
|
|
28
|
+
- Searching the stack of an error whose `name` is not text for its message is bounded by the part of
|
|
29
|
+
the stack the scrub reads, and nothing beyond that part is kept.
|
|
30
|
+
|
|
31
|
+
## [1.4.27] - 2026-11-21
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- An option the host supplies that throws when it is read (a getter, a Proxy trap) now ends `forRoot` and
|
|
36
|
+
`forRootAsync` with `[BymaxLoggerModule] options could not be read`, and the error the host threw is its
|
|
37
|
+
`cause`. Before, the host's own error left the module. The refusals of the options themselves (`[BymaxLoggerModule] options.<path> ...`) are
|
|
38
|
+
unchanged. Each redaction option (`redactPaths`, `redactCensor`, `redactStrategy`,
|
|
39
|
+
`shouldDisableDefaultRedact`) is read by name, so it takes effect whether it is a property, a
|
|
40
|
+
non-enumerable getter, a get-only Proxy or a class getter.
|
|
41
|
+
- The message of an object that is no `Error`, below the top level of a log record, is hidden in the
|
|
42
|
+
header of its `stack` as it is in its `message` field, whatever the case or the look of the two keys (`Message`, `STACK`).
|
|
43
|
+
- A `name` that holds an object, an array or a function is hidden with the message (it may carry
|
|
44
|
+
anything), in the stack header and under `error.type`; a number name is kept.
|
|
45
|
+
- The derived keys (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`, ...) are
|
|
46
|
+
owned as they look in a viewer: a spelling that differs only in case, in white space or zero-width
|
|
47
|
+
characters, or in fullwidth forms is owned too. `errorType`, `exception_type`, `exceptionType` and
|
|
48
|
+
`event.name` are other keys and are kept.
|
|
49
|
+
|
|
50
|
+
### Known limits
|
|
51
|
+
|
|
52
|
+
- An object whose `toJSON` returns a `message` that is not text and a `stack` that carries a secret which
|
|
53
|
+
is not the message text has no text to match: the stack header is written as the object gave it. Put
|
|
54
|
+
such a secret under a name in `redactPaths`, or keep it out of the `stack`.
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- The benchmark of the object message states its margin: the floor is 0.20 and the measurement ranges
|
|
59
|
+
from 0.38 to 0.47 with the load of the host.
|
|
60
|
+
- `pnpm check:property-path` also refuses a variable, a concatenation or a template with a
|
|
61
|
+
substitution as the argument of `toHaveProperty`, and a call with a space before the paren; a key is
|
|
62
|
+
written as an array, `toHaveProperty([key])`.
|
|
63
|
+
|
|
15
64
|
## [1.4.26] - 2026-11-21
|
|
16
65
|
|
|
17
66
|
### Fixed
|
|
@@ -53,7 +102,7 @@ heading here.
|
|
|
53
102
|
### Added
|
|
54
103
|
|
|
55
104
|
- The benchmark gates the cost of an object message: it must keep 0.20 of the throughput of a string
|
|
56
|
-
line on the shipped configuration (measured 0.46 to 0.47 on 1.4.24 and 1.4.25). A change that makes
|
|
105
|
+
line on the shipped configuration (measured 0.46 to 0.47 on a quiet host and 0.38 to 0.42 on a loaded one, on 1.4.24 and 1.4.25). A change that makes
|
|
57
106
|
the object form cost more than 5 times a line fails the job.
|
|
58
107
|
- A check (`pnpm check:property-path`, part of `pnpm lint`) fails on a `toHaveProperty` call that takes a
|
|
59
108
|
string with a dot: Jest reads it as a nested path, so a negative assertion on a key such as
|
|
@@ -3359,7 +3408,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
3359
3408
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
3360
3409
|
`release.yml`, Dependabot, and issue templates
|
|
3361
3410
|
|
|
3362
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3411
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.28...HEAD
|
|
3412
|
+
[1.4.28]: https://github.com/bymaxone/nest-logger/compare/v1.4.27...v1.4.28
|
|
3413
|
+
[1.4.27]: https://github.com/bymaxone/nest-logger/compare/v1.4.26...v1.4.27
|
|
3363
3414
|
[1.4.26]: https://github.com/bymaxone/nest-logger/compare/v1.4.25...v1.4.26
|
|
3364
3415
|
[1.4.25]: https://github.com/bymaxone/nest-logger/compare/v1.4.24...v1.4.25
|
|
3365
3416
|
[1.4.24]: https://github.com/bymaxone/nest-logger/compare/v1.4.23...v1.4.24
|
package/README.md
CHANGED
|
@@ -1066,7 +1066,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1066
1066
|
| `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
|
|
1067
1067
|
| `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
|
|
1068
1068
|
|
|
1069
|
-
**An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the frames are the stack's own text. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
|
|
1069
|
+
**An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the frames are the stack's own text, and this holds for such an object below the top level of the record as well. A `name` that is an object, an array or a function is hidden with the message, as it may carry anything, and a number `name` is kept. The keys the library owns (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`) are matched as they look in a viewer: the same key in another case, with white space, combining marks or zero-width characters inside it, in fullwidth letters, or with a letter of another script drawn like a Latin one is dropped too, while `errorType`, `exception_type`, `exceptionType` and `event.name` are other keys and are kept. An object whose `toJSON` returns a `message` that is not text and a `stack` carrying a secret that is not the message text leaves nothing to match, so name such a secret in `redactPaths`. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
|
|
1070
1070
|
|
|
1071
1071
|
**Helpers**
|
|
1072
1072
|
|
|
@@ -1240,6 +1240,7 @@ Two kinds of failure, and they surface differently. A **thrown `Error`** carries
|
|
|
1240
1240
|
| Message starts with | Thrown from | When | Action |
|
|
1241
1241
|
| -------------------------------------------------------- | ------------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
|
|
1242
1242
|
| `[BymaxLoggerModule] options.` | `forRoot` / `forRootAsync`, at module setup | any option fails validation: a missing `service`, a `level` outside the set, a bad type | Fix the option the message names; it prints the path and what it received |
|
|
1243
|
+
| `[BymaxLoggerModule] options could not be read` | `forRoot` / `forRootAsync`, at module setup | an option the host supplies threw when it was read (a getter or a Proxy trap) | Fix the option; the error the host threw is the `cause` |
|
|
1243
1244
|
| `[BymaxLoggerModule] useNestLogger(app) called but` | `BymaxLoggerModule.useNestLogger` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
|
|
1244
1245
|
| `[BymaxLoggerModule] applyAccessLog(app) called but` | `applyAccessLog` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
|
|
1245
1246
|
| `[BymaxLoggerModule] useRequestContext(app) called but` | `useRequestContext` | the module was never imported into the application | Import `BymaxLoggerModule` before calling it |
|
package/dist/server/index.cjs
CHANGED
|
@@ -81,6 +81,20 @@ function readSet(source, keys) {
|
|
|
81
81
|
}
|
|
82
82
|
return set;
|
|
83
83
|
}
|
|
84
|
+
var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
|
|
85
|
+
var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
|
|
86
|
+
function copyLists(holder, names) {
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
const value = Reflect.get(holder, name);
|
|
89
|
+
if (!Array.isArray(value)) continue;
|
|
90
|
+
const length = Reflect.get(value, "length");
|
|
91
|
+
Reflect.set(
|
|
92
|
+
holder,
|
|
93
|
+
name,
|
|
94
|
+
Array.from({ length }, (_, index) => Reflect.get(value, index))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
84
98
|
function dropUnsetOptions(options) {
|
|
85
99
|
if (!isRecord(options)) return options;
|
|
86
100
|
const set = readSet(options, Object.keys(OPTION_KEYS));
|
|
@@ -89,9 +103,33 @@ function dropUnsetOptions(options) {
|
|
|
89
103
|
if (isRecord(value))
|
|
90
104
|
Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
|
|
91
105
|
}
|
|
106
|
+
const service = Reflect.get(set, "service");
|
|
107
|
+
if (isRecord(service)) Reflect.set(set, "service", { ...service });
|
|
108
|
+
const serializers = Reflect.get(set, "serializers");
|
|
109
|
+
if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
|
|
110
|
+
copyLists(set, LIST_OPTIONS);
|
|
111
|
+
const http = Reflect.get(set, "http");
|
|
112
|
+
if (isRecord(http)) copyLists(http, HTTP_LISTS);
|
|
92
113
|
return set;
|
|
93
114
|
}
|
|
94
115
|
|
|
116
|
+
// src/server/config/options-refusal.util.ts
|
|
117
|
+
var refusals = /* @__PURE__ */ new WeakSet();
|
|
118
|
+
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
119
|
+
function refuse(message) {
|
|
120
|
+
const error = new Error(message);
|
|
121
|
+
refusals.add(error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
function guardOptions(read) {
|
|
125
|
+
try {
|
|
126
|
+
return read();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
129
|
+
throw new Error(UNREADABLE, { cause: error });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
95
133
|
// src/server/constants/lifecycle-timeouts.constants.ts
|
|
96
134
|
var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
|
|
97
135
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
@@ -214,7 +252,7 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
|
|
|
214
252
|
// src/server/config/validate-options.ts
|
|
215
253
|
function reject(path, rule, got, wasGiven = got !== void 0) {
|
|
216
254
|
const received = wasGiven ? `. Received ${describeValue(got)}` : "";
|
|
217
|
-
|
|
255
|
+
refuse(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
|
|
218
256
|
}
|
|
219
257
|
function describeValue(value) {
|
|
220
258
|
switch (typeof value) {
|
|
@@ -312,7 +350,7 @@ function validateLifecycle(options) {
|
|
|
312
350
|
function validateCore(options) {
|
|
313
351
|
const service = options.service;
|
|
314
352
|
if (service === void 0) {
|
|
315
|
-
|
|
353
|
+
refuse("[BymaxLoggerModule] options.service is required");
|
|
316
354
|
}
|
|
317
355
|
if (!isRecord2(service)) reject("service", "must be an object", service);
|
|
318
356
|
for (const field of ["name", "version"]) {
|
|
@@ -394,12 +432,12 @@ function validateErrorFields(options) {
|
|
|
394
432
|
}
|
|
395
433
|
});
|
|
396
434
|
}
|
|
397
|
-
var
|
|
435
|
+
var UNREADABLE2 = /* @__PURE__ */ Symbol("unreadable");
|
|
398
436
|
function readMember(destination, key) {
|
|
399
437
|
try {
|
|
400
438
|
return Reflect.get(destination, key);
|
|
401
439
|
} catch {
|
|
402
|
-
return
|
|
440
|
+
return UNREADABLE2;
|
|
403
441
|
}
|
|
404
442
|
}
|
|
405
443
|
function validateDestination(entry, index) {
|
|
@@ -408,16 +446,16 @@ function validateDestination(entry, index) {
|
|
|
408
446
|
reject(path, "must be an object implementing ILogDestination", entry, true);
|
|
409
447
|
}
|
|
410
448
|
const write = readMember(entry, "write");
|
|
411
|
-
if (write !==
|
|
449
|
+
if (write !== UNREADABLE2 && typeof write !== "function") {
|
|
412
450
|
reject(path, "must have a write(payload) method");
|
|
413
451
|
}
|
|
414
452
|
const name = readMember(entry, "name");
|
|
415
|
-
if (name !==
|
|
453
|
+
if (name !== UNREADABLE2 && !isNonEmptyString(name)) {
|
|
416
454
|
reject(path, "must have a non-empty string name", name);
|
|
417
455
|
}
|
|
418
456
|
for (const hook of ["onInit", "onShutdown", "onRegistryReady"]) {
|
|
419
457
|
const value = readMember(entry, hook);
|
|
420
|
-
if (value !==
|
|
458
|
+
if (value !== UNREADABLE2 && value !== void 0 && typeof value !== "function") {
|
|
421
459
|
reject(`${path}.${hook}`, "must be a function", value);
|
|
422
460
|
}
|
|
423
461
|
}
|
|
@@ -484,6 +522,15 @@ function validateOptions(given) {
|
|
|
484
522
|
validateOtel(options);
|
|
485
523
|
}
|
|
486
524
|
|
|
525
|
+
// src/server/config/resolve-options.ts
|
|
526
|
+
function resolveOptions(given) {
|
|
527
|
+
return guardOptions(() => {
|
|
528
|
+
const snapshot = dropUnsetOptions(given);
|
|
529
|
+
validateOptions(snapshot);
|
|
530
|
+
return applyDefaults(snapshot);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
487
534
|
// src/server/constants/injection-tokens.constants.ts
|
|
488
535
|
var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
|
|
489
536
|
var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
|
|
@@ -604,6 +651,7 @@ function escapeControlCharacters(text) {
|
|
|
604
651
|
|
|
605
652
|
// src/server/utils/fold-key.util.ts
|
|
606
653
|
var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
|
|
654
|
+
var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
|
|
607
655
|
var PLAIN = /^[\x21-\x7e]*$/;
|
|
608
656
|
var LOOKALIKES = new Map(
|
|
609
657
|
Object.entries({
|
|
@@ -635,9 +683,10 @@ var LOOKALIKES = new Map(
|
|
|
635
683
|
z: "\u1D22"
|
|
636
684
|
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
637
685
|
);
|
|
638
|
-
function foldKey(key) {
|
|
639
|
-
|
|
640
|
-
|
|
686
|
+
function foldKey(key, keepSeparators = false) {
|
|
687
|
+
const ignored = keepSeparators ? INVISIBLE : IGNORED;
|
|
688
|
+
if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
|
|
689
|
+
let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
|
|
641
690
|
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
642
691
|
return folded;
|
|
643
692
|
}
|
|
@@ -800,9 +849,20 @@ function readsAsError(value) {
|
|
|
800
849
|
const candidate = value;
|
|
801
850
|
return typeof candidate.message === "string" && (isError(value) || typeof candidate.name === "string");
|
|
802
851
|
}
|
|
803
|
-
function readScrubbedStack(value, name, message, result, walk2) {
|
|
852
|
+
function readScrubbedStack(value, name, message, textName, result, walk2) {
|
|
804
853
|
const stack = readOptional(() => value.stack, result);
|
|
805
|
-
|
|
854
|
+
if (stack === void 0) return void 0;
|
|
855
|
+
const header = headerCensor(name, message, walk2.censorMessage);
|
|
856
|
+
return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
|
|
857
|
+
}
|
|
858
|
+
var FRAME_LINE2 = /\n[ \t]+at /;
|
|
859
|
+
function withNamedHeader(stack, message) {
|
|
860
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
861
|
+
const found = message === "" ? -1 : head.indexOf(message);
|
|
862
|
+
if (found !== -1) return `Error: ${head.slice(found)}`;
|
|
863
|
+
const end = head.search(FRAME_LINE2);
|
|
864
|
+
const frames = end === -1 ? "" : head.slice(end);
|
|
865
|
+
return `Error${message === "" ? "" : `: ${message}`}${frames}`;
|
|
806
866
|
}
|
|
807
867
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
808
868
|
try {
|
|
@@ -810,13 +870,13 @@ function toSanitizedError(value, seen, depth2, walk2) {
|
|
|
810
870
|
return { name: "UnknownError", message: cutText(String(value)) };
|
|
811
871
|
}
|
|
812
872
|
seen.add(value);
|
|
813
|
-
const message = value
|
|
814
|
-
const name = cutText(typeof
|
|
873
|
+
const { message, name: rawName } = value;
|
|
874
|
+
const name = cutText(typeof rawName === "string" ? rawName : "Error");
|
|
815
875
|
const result = {
|
|
816
876
|
name: censorName(name, walk2.censorMessage),
|
|
817
877
|
message: cutText(message)
|
|
818
878
|
};
|
|
819
|
-
const stack = readScrubbedStack(value, name, message, result, walk2);
|
|
879
|
+
const stack = readScrubbedStack(value, name, message, typeof rawName === "string", result, walk2);
|
|
820
880
|
if (stack !== void 0) result.stack = stack;
|
|
821
881
|
const isAtDepthLimit = depth2 >= walk2.maxDepth;
|
|
822
882
|
const cause = readOptional(() => value.cause, result);
|
|
@@ -929,7 +989,7 @@ function headerCensor(name, message, censorMessage) {
|
|
|
929
989
|
function censorStackName(stack, header) {
|
|
930
990
|
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
931
991
|
}
|
|
932
|
-
function scrubStack(stack, header) {
|
|
992
|
+
function scrubStack(stack, header, wasLonger = false) {
|
|
933
993
|
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
934
994
|
const scrubbed = escapeControlCharacters(
|
|
935
995
|
(header === void 0 ? head : censorStackHeader(
|
|
@@ -939,7 +999,7 @@ function scrubStack(stack, header) {
|
|
|
939
999
|
header.censored
|
|
940
1000
|
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
941
1001
|
);
|
|
942
|
-
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
1002
|
+
return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
|
|
943
1003
|
}
|
|
944
1004
|
function isObject(value) {
|
|
945
1005
|
return typeof value === "object" && value !== null;
|
|
@@ -962,7 +1022,7 @@ var RESOURCE_KEYS = [
|
|
|
962
1022
|
"deployment.environment.name"
|
|
963
1023
|
];
|
|
964
1024
|
var OWNED_KEY_SPELLINGS = new Set(
|
|
965
|
-
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
1025
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
|
|
966
1026
|
);
|
|
967
1027
|
var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
968
1028
|
"exception.type",
|
|
@@ -972,7 +1032,7 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
|
972
1032
|
]);
|
|
973
1033
|
var isOwnedKey = (key) => {
|
|
974
1034
|
const lower = key.toLowerCase();
|
|
975
|
-
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(
|
|
1035
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
976
1036
|
};
|
|
977
1037
|
function withoutOwnedKeys(metadata, omit) {
|
|
978
1038
|
if (metadata === void 0) {
|
|
@@ -2786,7 +2846,8 @@ function cutOrWalk(value, level, host, depth2) {
|
|
|
2786
2846
|
return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
|
|
2787
2847
|
}
|
|
2788
2848
|
function writeName(value, level, host, depth2) {
|
|
2789
|
-
|
|
2849
|
+
const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
|
|
2850
|
+
return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
|
|
2790
2851
|
}
|
|
2791
2852
|
function addErrorParts(copy, error, ownKeys, host, depth2) {
|
|
2792
2853
|
const taken = new Set(ownKeys);
|
|
@@ -2835,7 +2896,7 @@ function rulesBelow(rules, key, value, honorToJson) {
|
|
|
2835
2896
|
if (leavesErrorText(rules, key, value, honorToJson)) {
|
|
2836
2897
|
return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
|
|
2837
2898
|
}
|
|
2838
|
-
return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
|
|
2899
|
+
return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
|
|
2839
2900
|
}
|
|
2840
2901
|
function isCensored(rules, key, value) {
|
|
2841
2902
|
const lower = key.toLowerCase();
|
|
@@ -2844,10 +2905,32 @@ function isCensored(rules, key, value) {
|
|
|
2844
2905
|
function messageCensor(rules) {
|
|
2845
2906
|
return (text) => rules.sensitive.has("message") ? rules.censor : text;
|
|
2846
2907
|
}
|
|
2847
|
-
function
|
|
2908
|
+
function headerMessage(rules, source, keys, isError2) {
|
|
2909
|
+
if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
|
|
2910
|
+
return void 0;
|
|
2911
|
+
if (rules.headerKept === true) return void 0;
|
|
2912
|
+
const key = keys.find((candidate) => foldKey(candidate) === "message");
|
|
2913
|
+
if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
|
|
2914
|
+
return void 0;
|
|
2915
|
+
}
|
|
2916
|
+
const text = Reflect.get(source, key);
|
|
2917
|
+
return typeof text === "string" ? { key, text } : void 0;
|
|
2918
|
+
}
|
|
2919
|
+
function readField(source, key, header) {
|
|
2920
|
+
return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
|
|
2921
|
+
}
|
|
2922
|
+
function censorAnyName(rules, name) {
|
|
2923
|
+
if (typeof name === "string") return censorName(name, messageCensor(rules));
|
|
2924
|
+
const holder = typeof name === "object" && name !== null || typeof name === "function";
|
|
2925
|
+
return holder && rules.sensitive.has("message") ? rules.censor : name;
|
|
2926
|
+
}
|
|
2927
|
+
function errorTextField(rules, key, value, isError2, header) {
|
|
2928
|
+
if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
|
|
2929
|
+
return hideMessageInStack(value, header.text, rules.censor);
|
|
2930
|
+
}
|
|
2848
2931
|
if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
|
|
2849
2932
|
const cut = cutIfText(value);
|
|
2850
|
-
return key === "name"
|
|
2933
|
+
return key === "name" ? censorAnyName(rules, cut) : cut;
|
|
2851
2934
|
}
|
|
2852
2935
|
|
|
2853
2936
|
// src/server/utils/redact-error-clone.util.ts
|
|
@@ -2906,6 +2989,14 @@ function resolveToJson(value, viaGet = false) {
|
|
|
2906
2989
|
volatile: accessor || proxied
|
|
2907
2990
|
};
|
|
2908
2991
|
}
|
|
2992
|
+
function rulesInside(rules, names, visits) {
|
|
2993
|
+
return names === void 0 ? void 0 : { ...rules, sensitive: names, visits, insideErrors: void 0 };
|
|
2994
|
+
}
|
|
2995
|
+
var errorOutputs = /* @__PURE__ */ new WeakSet();
|
|
2996
|
+
function markErrorOutput(output) {
|
|
2997
|
+
if (typeof output === "object" && output !== null) errorOutputs.add(output);
|
|
2998
|
+
return output;
|
|
2999
|
+
}
|
|
2909
3000
|
function walkArray(value, rules, depth2, ancestors, inSerialized) {
|
|
2910
3001
|
const length = value.length;
|
|
2911
3002
|
const copy = [];
|
|
@@ -2992,13 +3083,13 @@ function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized)
|
|
|
2992
3083
|
function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized) {
|
|
2993
3084
|
const source = value;
|
|
2994
3085
|
const keys = Object.keys(source);
|
|
2995
|
-
const
|
|
2996
|
-
const asData = isError(value) && (safe || rules.errorsAsData && !inSerialized);
|
|
3086
|
+
const asData = isError(value) && (rules.ownFields.safe || rules.errorsAsData && !inSerialized);
|
|
2997
3087
|
const copy = startCopy(value, asData);
|
|
2998
|
-
const scrubbed = isError(value) && (safe || !inSerialized);
|
|
3088
|
+
const scrubbed = isError(value) && (rules.ownFields.safe || !inSerialized);
|
|
2999
3089
|
const omitted = /* @__PURE__ */ new Set();
|
|
3090
|
+
const header = headerMessage(rules, source, keys, isError(value));
|
|
3000
3091
|
for (const key of keys) {
|
|
3001
|
-
const read =
|
|
3092
|
+
const read = readField(source, key, header);
|
|
3002
3093
|
const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
|
|
3003
3094
|
const hook = honorToJson && key === "toJSON" && typeof current === "function";
|
|
3004
3095
|
if (current === OMIT_OWN_FIELD || hook) {
|
|
@@ -3012,7 +3103,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
3012
3103
|
isCensored(rules, key, current) ? rules.censor : censorHeaderArray(
|
|
3013
3104
|
key,
|
|
3014
3105
|
walk(
|
|
3015
|
-
errorTextField(rules, key, current, scrubbed),
|
|
3106
|
+
errorTextField(rules, key, current, scrubbed, header),
|
|
3016
3107
|
rulesBelow(rules, key, current, honorToJson),
|
|
3017
3108
|
depth2 + 1,
|
|
3018
3109
|
ancestors,
|
|
@@ -3043,7 +3134,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
|
|
|
3043
3134
|
// What a serializer receives names the error `name`, as the error-like shape it reads does;
|
|
3044
3135
|
// everything else keeps the `type` the written entries use.
|
|
3045
3136
|
nameKey: inSerialized ? "name" : "type",
|
|
3046
|
-
censorName: (name) =>
|
|
3137
|
+
censorName: (name) => censorAnyName(rules, name),
|
|
3047
3138
|
walk: (value, depth2) => walk(value, rules, depth2, ancestors, true, inSerialized),
|
|
3048
3139
|
// Under 'safe' the cap does not read a list's `toJSON`: a list over the cap becomes a fresh array
|
|
3049
3140
|
// and is never read for it, and a list within the cap is read once, by the walk.
|
|
@@ -3067,8 +3158,9 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
|
|
|
3067
3158
|
const visits = { count: 0 };
|
|
3068
3159
|
const call = {
|
|
3069
3160
|
...rules,
|
|
3161
|
+
headerKept: typeof value === "object" && value !== null && errorOutputs.has(value),
|
|
3070
3162
|
visits,
|
|
3071
|
-
insideErrors:
|
|
3163
|
+
insideErrors: rulesInside(rules, insideNames, visits)
|
|
3072
3164
|
};
|
|
3073
3165
|
return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
|
|
3074
3166
|
} catch {
|
|
@@ -3439,7 +3531,7 @@ function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
|
|
|
3439
3531
|
() => onTruncate("max_entry_size")
|
|
3440
3532
|
);
|
|
3441
3533
|
return {
|
|
3442
|
-
err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
|
|
3534
|
+
err: bound((error) => markErrorOutput(serializeErrorValue(error, ownFields, censorMessage))),
|
|
3443
3535
|
...Object.fromEntries(
|
|
3444
3536
|
Object.entries(options.serializers).map(
|
|
3445
3537
|
([key, serializer]) => [key, bound(serializer)]
|
|
@@ -4344,8 +4436,8 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4344
4436
|
* BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
|
|
4345
4437
|
*/
|
|
4346
4438
|
static forRoot(options) {
|
|
4347
|
-
|
|
4348
|
-
const resolved =
|
|
4439
|
+
const snapshot = guardOptions(() => dropUnsetOptions(options));
|
|
4440
|
+
const resolved = resolveOptions(snapshot);
|
|
4349
4441
|
const providers = [
|
|
4350
4442
|
{ provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
|
|
4351
4443
|
...buildCommonProviders()
|
|
@@ -4356,7 +4448,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4356
4448
|
providers.push({ provide: core.APP_FILTER, useClass: exports.HttpExceptionFilter });
|
|
4357
4449
|
}
|
|
4358
4450
|
}
|
|
4359
|
-
return augmentLoggerModule(
|
|
4451
|
+
return augmentLoggerModule(
|
|
4452
|
+
guardOptions(() => super.forRoot(snapshot)),
|
|
4453
|
+
providers
|
|
4454
|
+
);
|
|
4360
4455
|
}
|
|
4361
4456
|
/**
|
|
4362
4457
|
* Asynchronous registration. Options are resolved lazily via the consumer's
|
|
@@ -4385,10 +4480,7 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4385
4480
|
const providers = [
|
|
4386
4481
|
{
|
|
4387
4482
|
provide: LOGGER_OPTIONS_TOKEN,
|
|
4388
|
-
useFactory: (raw) =>
|
|
4389
|
-
validateOptions(raw);
|
|
4390
|
-
return applyDefaults(raw);
|
|
4391
|
-
},
|
|
4483
|
+
useFactory: (raw) => resolveOptions(raw),
|
|
4392
4484
|
inject: [BUILDER_OPTIONS_TOKEN]
|
|
4393
4485
|
},
|
|
4394
4486
|
...buildCommonProviders(),
|
|
@@ -4396,7 +4488,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4396
4488
|
// gated at runtime against the async-resolved `http.isEnabled`.
|
|
4397
4489
|
asyncHttpInterceptorProvider()
|
|
4398
4490
|
];
|
|
4399
|
-
return augmentLoggerModule(
|
|
4491
|
+
return augmentLoggerModule(
|
|
4492
|
+
guardOptions(() => super.forRootAsync(options)),
|
|
4493
|
+
providers
|
|
4494
|
+
);
|
|
4400
4495
|
}
|
|
4401
4496
|
/**
|
|
4402
4497
|
* Replace NestJS's internal logger with this library's `PinoLoggerService` and
|
package/dist/server/index.mjs
CHANGED
|
@@ -78,6 +78,20 @@ function readSet(source, keys) {
|
|
|
78
78
|
}
|
|
79
79
|
return set;
|
|
80
80
|
}
|
|
81
|
+
var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
|
|
82
|
+
var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
|
|
83
|
+
function copyLists(holder, names) {
|
|
84
|
+
for (const name of names) {
|
|
85
|
+
const value = Reflect.get(holder, name);
|
|
86
|
+
if (!Array.isArray(value)) continue;
|
|
87
|
+
const length = Reflect.get(value, "length");
|
|
88
|
+
Reflect.set(
|
|
89
|
+
holder,
|
|
90
|
+
name,
|
|
91
|
+
Array.from({ length }, (_, index) => Reflect.get(value, index))
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
81
95
|
function dropUnsetOptions(options) {
|
|
82
96
|
if (!isRecord(options)) return options;
|
|
83
97
|
const set = readSet(options, Object.keys(OPTION_KEYS));
|
|
@@ -86,9 +100,33 @@ function dropUnsetOptions(options) {
|
|
|
86
100
|
if (isRecord(value))
|
|
87
101
|
Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
|
|
88
102
|
}
|
|
103
|
+
const service = Reflect.get(set, "service");
|
|
104
|
+
if (isRecord(service)) Reflect.set(set, "service", { ...service });
|
|
105
|
+
const serializers = Reflect.get(set, "serializers");
|
|
106
|
+
if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
|
|
107
|
+
copyLists(set, LIST_OPTIONS);
|
|
108
|
+
const http = Reflect.get(set, "http");
|
|
109
|
+
if (isRecord(http)) copyLists(http, HTTP_LISTS);
|
|
89
110
|
return set;
|
|
90
111
|
}
|
|
91
112
|
|
|
113
|
+
// src/server/config/options-refusal.util.ts
|
|
114
|
+
var refusals = /* @__PURE__ */ new WeakSet();
|
|
115
|
+
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
116
|
+
function refuse(message) {
|
|
117
|
+
const error = new Error(message);
|
|
118
|
+
refusals.add(error);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
function guardOptions(read) {
|
|
122
|
+
try {
|
|
123
|
+
return read();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
126
|
+
throw new Error(UNREADABLE, { cause: error });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
92
130
|
// src/server/constants/lifecycle-timeouts.constants.ts
|
|
93
131
|
var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
|
|
94
132
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
@@ -211,7 +249,7 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
|
|
|
211
249
|
// src/server/config/validate-options.ts
|
|
212
250
|
function reject(path2, rule, got, wasGiven = got !== void 0) {
|
|
213
251
|
const received = wasGiven ? `. Received ${describeValue(got)}` : "";
|
|
214
|
-
|
|
252
|
+
refuse(`[BymaxLoggerModule] options.${path2} ${rule}${received}`);
|
|
215
253
|
}
|
|
216
254
|
function describeValue(value) {
|
|
217
255
|
switch (typeof value) {
|
|
@@ -309,7 +347,7 @@ function validateLifecycle(options) {
|
|
|
309
347
|
function validateCore(options) {
|
|
310
348
|
const service = options.service;
|
|
311
349
|
if (service === void 0) {
|
|
312
|
-
|
|
350
|
+
refuse("[BymaxLoggerModule] options.service is required");
|
|
313
351
|
}
|
|
314
352
|
if (!isRecord2(service)) reject("service", "must be an object", service);
|
|
315
353
|
for (const field of ["name", "version"]) {
|
|
@@ -391,12 +429,12 @@ function validateErrorFields(options) {
|
|
|
391
429
|
}
|
|
392
430
|
});
|
|
393
431
|
}
|
|
394
|
-
var
|
|
432
|
+
var UNREADABLE2 = /* @__PURE__ */ Symbol("unreadable");
|
|
395
433
|
function readMember(destination, key) {
|
|
396
434
|
try {
|
|
397
435
|
return Reflect.get(destination, key);
|
|
398
436
|
} catch {
|
|
399
|
-
return
|
|
437
|
+
return UNREADABLE2;
|
|
400
438
|
}
|
|
401
439
|
}
|
|
402
440
|
function validateDestination(entry, index) {
|
|
@@ -405,16 +443,16 @@ function validateDestination(entry, index) {
|
|
|
405
443
|
reject(path2, "must be an object implementing ILogDestination", entry, true);
|
|
406
444
|
}
|
|
407
445
|
const write = readMember(entry, "write");
|
|
408
|
-
if (write !==
|
|
446
|
+
if (write !== UNREADABLE2 && typeof write !== "function") {
|
|
409
447
|
reject(path2, "must have a write(payload) method");
|
|
410
448
|
}
|
|
411
449
|
const name = readMember(entry, "name");
|
|
412
|
-
if (name !==
|
|
450
|
+
if (name !== UNREADABLE2 && !isNonEmptyString(name)) {
|
|
413
451
|
reject(path2, "must have a non-empty string name", name);
|
|
414
452
|
}
|
|
415
453
|
for (const hook of ["onInit", "onShutdown", "onRegistryReady"]) {
|
|
416
454
|
const value = readMember(entry, hook);
|
|
417
|
-
if (value !==
|
|
455
|
+
if (value !== UNREADABLE2 && value !== void 0 && typeof value !== "function") {
|
|
418
456
|
reject(`${path2}.${hook}`, "must be a function", value);
|
|
419
457
|
}
|
|
420
458
|
}
|
|
@@ -481,6 +519,15 @@ function validateOptions(given) {
|
|
|
481
519
|
validateOtel(options);
|
|
482
520
|
}
|
|
483
521
|
|
|
522
|
+
// src/server/config/resolve-options.ts
|
|
523
|
+
function resolveOptions(given) {
|
|
524
|
+
return guardOptions(() => {
|
|
525
|
+
const snapshot = dropUnsetOptions(given);
|
|
526
|
+
validateOptions(snapshot);
|
|
527
|
+
return applyDefaults(snapshot);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
484
531
|
// src/server/constants/injection-tokens.constants.ts
|
|
485
532
|
var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
|
|
486
533
|
var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
|
|
@@ -601,6 +648,7 @@ function escapeControlCharacters(text) {
|
|
|
601
648
|
|
|
602
649
|
// src/server/utils/fold-key.util.ts
|
|
603
650
|
var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
|
|
651
|
+
var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
|
|
604
652
|
var PLAIN = /^[\x21-\x7e]*$/;
|
|
605
653
|
var LOOKALIKES = new Map(
|
|
606
654
|
Object.entries({
|
|
@@ -632,9 +680,10 @@ var LOOKALIKES = new Map(
|
|
|
632
680
|
z: "\u1D22"
|
|
633
681
|
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
634
682
|
);
|
|
635
|
-
function foldKey(key) {
|
|
636
|
-
|
|
637
|
-
|
|
683
|
+
function foldKey(key, keepSeparators = false) {
|
|
684
|
+
const ignored = keepSeparators ? INVISIBLE : IGNORED;
|
|
685
|
+
if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
|
|
686
|
+
let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
|
|
638
687
|
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
639
688
|
return folded;
|
|
640
689
|
}
|
|
@@ -797,9 +846,20 @@ function readsAsError(value) {
|
|
|
797
846
|
const candidate = value;
|
|
798
847
|
return typeof candidate.message === "string" && (isError(value) || typeof candidate.name === "string");
|
|
799
848
|
}
|
|
800
|
-
function readScrubbedStack(value, name, message, result, walk2) {
|
|
849
|
+
function readScrubbedStack(value, name, message, textName, result, walk2) {
|
|
801
850
|
const stack = readOptional(() => value.stack, result);
|
|
802
|
-
|
|
851
|
+
if (stack === void 0) return void 0;
|
|
852
|
+
const header = headerCensor(name, message, walk2.censorMessage);
|
|
853
|
+
return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
|
|
854
|
+
}
|
|
855
|
+
var FRAME_LINE2 = /\n[ \t]+at /;
|
|
856
|
+
function withNamedHeader(stack, message) {
|
|
857
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
858
|
+
const found = message === "" ? -1 : head.indexOf(message);
|
|
859
|
+
if (found !== -1) return `Error: ${head.slice(found)}`;
|
|
860
|
+
const end = head.search(FRAME_LINE2);
|
|
861
|
+
const frames = end === -1 ? "" : head.slice(end);
|
|
862
|
+
return `Error${message === "" ? "" : `: ${message}`}${frames}`;
|
|
803
863
|
}
|
|
804
864
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
805
865
|
try {
|
|
@@ -807,13 +867,13 @@ function toSanitizedError(value, seen, depth2, walk2) {
|
|
|
807
867
|
return { name: "UnknownError", message: cutText(String(value)) };
|
|
808
868
|
}
|
|
809
869
|
seen.add(value);
|
|
810
|
-
const message = value
|
|
811
|
-
const name = cutText(typeof
|
|
870
|
+
const { message, name: rawName } = value;
|
|
871
|
+
const name = cutText(typeof rawName === "string" ? rawName : "Error");
|
|
812
872
|
const result = {
|
|
813
873
|
name: censorName(name, walk2.censorMessage),
|
|
814
874
|
message: cutText(message)
|
|
815
875
|
};
|
|
816
|
-
const stack = readScrubbedStack(value, name, message, result, walk2);
|
|
876
|
+
const stack = readScrubbedStack(value, name, message, typeof rawName === "string", result, walk2);
|
|
817
877
|
if (stack !== void 0) result.stack = stack;
|
|
818
878
|
const isAtDepthLimit = depth2 >= walk2.maxDepth;
|
|
819
879
|
const cause = readOptional(() => value.cause, result);
|
|
@@ -926,7 +986,7 @@ function headerCensor(name, message, censorMessage) {
|
|
|
926
986
|
function censorStackName(stack, header) {
|
|
927
987
|
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
928
988
|
}
|
|
929
|
-
function scrubStack(stack, header) {
|
|
989
|
+
function scrubStack(stack, header, wasLonger = false) {
|
|
930
990
|
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
931
991
|
const scrubbed = escapeControlCharacters(
|
|
932
992
|
(header === void 0 ? head : censorStackHeader(
|
|
@@ -936,7 +996,7 @@ function scrubStack(stack, header) {
|
|
|
936
996
|
header.censored
|
|
937
997
|
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
938
998
|
);
|
|
939
|
-
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
999
|
+
return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
|
|
940
1000
|
}
|
|
941
1001
|
function isObject(value) {
|
|
942
1002
|
return typeof value === "object" && value !== null;
|
|
@@ -959,7 +1019,7 @@ var RESOURCE_KEYS = [
|
|
|
959
1019
|
"deployment.environment.name"
|
|
960
1020
|
];
|
|
961
1021
|
var OWNED_KEY_SPELLINGS = new Set(
|
|
962
|
-
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
1022
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
|
|
963
1023
|
);
|
|
964
1024
|
var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
965
1025
|
"exception.type",
|
|
@@ -969,7 +1029,7 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
|
969
1029
|
]);
|
|
970
1030
|
var isOwnedKey = (key) => {
|
|
971
1031
|
const lower = key.toLowerCase();
|
|
972
|
-
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(
|
|
1032
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
973
1033
|
};
|
|
974
1034
|
function withoutOwnedKeys(metadata, omit) {
|
|
975
1035
|
if (metadata === void 0) {
|
|
@@ -2783,7 +2843,8 @@ function cutOrWalk(value, level, host, depth2) {
|
|
|
2783
2843
|
return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
|
|
2784
2844
|
}
|
|
2785
2845
|
function writeName(value, level, host, depth2) {
|
|
2786
|
-
|
|
2846
|
+
const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
|
|
2847
|
+
return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
|
|
2787
2848
|
}
|
|
2788
2849
|
function addErrorParts(copy, error, ownKeys, host, depth2) {
|
|
2789
2850
|
const taken = new Set(ownKeys);
|
|
@@ -2832,7 +2893,7 @@ function rulesBelow(rules, key, value, honorToJson) {
|
|
|
2832
2893
|
if (leavesErrorText(rules, key, value, honorToJson)) {
|
|
2833
2894
|
return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
|
|
2834
2895
|
}
|
|
2835
|
-
return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
|
|
2896
|
+
return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
|
|
2836
2897
|
}
|
|
2837
2898
|
function isCensored(rules, key, value) {
|
|
2838
2899
|
const lower = key.toLowerCase();
|
|
@@ -2841,10 +2902,32 @@ function isCensored(rules, key, value) {
|
|
|
2841
2902
|
function messageCensor(rules) {
|
|
2842
2903
|
return (text) => rules.sensitive.has("message") ? rules.censor : text;
|
|
2843
2904
|
}
|
|
2844
|
-
function
|
|
2905
|
+
function headerMessage(rules, source, keys, isError2) {
|
|
2906
|
+
if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
|
|
2907
|
+
return void 0;
|
|
2908
|
+
if (rules.headerKept === true) return void 0;
|
|
2909
|
+
const key = keys.find((candidate) => foldKey(candidate) === "message");
|
|
2910
|
+
if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
|
|
2911
|
+
return void 0;
|
|
2912
|
+
}
|
|
2913
|
+
const text = Reflect.get(source, key);
|
|
2914
|
+
return typeof text === "string" ? { key, text } : void 0;
|
|
2915
|
+
}
|
|
2916
|
+
function readField(source, key, header) {
|
|
2917
|
+
return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
|
|
2918
|
+
}
|
|
2919
|
+
function censorAnyName(rules, name) {
|
|
2920
|
+
if (typeof name === "string") return censorName(name, messageCensor(rules));
|
|
2921
|
+
const holder = typeof name === "object" && name !== null || typeof name === "function";
|
|
2922
|
+
return holder && rules.sensitive.has("message") ? rules.censor : name;
|
|
2923
|
+
}
|
|
2924
|
+
function errorTextField(rules, key, value, isError2, header) {
|
|
2925
|
+
if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
|
|
2926
|
+
return hideMessageInStack(value, header.text, rules.censor);
|
|
2927
|
+
}
|
|
2845
2928
|
if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
|
|
2846
2929
|
const cut = cutIfText(value);
|
|
2847
|
-
return key === "name"
|
|
2930
|
+
return key === "name" ? censorAnyName(rules, cut) : cut;
|
|
2848
2931
|
}
|
|
2849
2932
|
|
|
2850
2933
|
// src/server/utils/redact-error-clone.util.ts
|
|
@@ -2903,6 +2986,14 @@ function resolveToJson(value, viaGet = false) {
|
|
|
2903
2986
|
volatile: accessor || proxied
|
|
2904
2987
|
};
|
|
2905
2988
|
}
|
|
2989
|
+
function rulesInside(rules, names, visits) {
|
|
2990
|
+
return names === void 0 ? void 0 : { ...rules, sensitive: names, visits, insideErrors: void 0 };
|
|
2991
|
+
}
|
|
2992
|
+
var errorOutputs = /* @__PURE__ */ new WeakSet();
|
|
2993
|
+
function markErrorOutput(output) {
|
|
2994
|
+
if (typeof output === "object" && output !== null) errorOutputs.add(output);
|
|
2995
|
+
return output;
|
|
2996
|
+
}
|
|
2906
2997
|
function walkArray(value, rules, depth2, ancestors, inSerialized) {
|
|
2907
2998
|
const length = value.length;
|
|
2908
2999
|
const copy = [];
|
|
@@ -2989,13 +3080,13 @@ function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized)
|
|
|
2989
3080
|
function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized) {
|
|
2990
3081
|
const source = value;
|
|
2991
3082
|
const keys = Object.keys(source);
|
|
2992
|
-
const
|
|
2993
|
-
const asData = isError(value) && (safe || rules.errorsAsData && !inSerialized);
|
|
3083
|
+
const asData = isError(value) && (rules.ownFields.safe || rules.errorsAsData && !inSerialized);
|
|
2994
3084
|
const copy = startCopy(value, asData);
|
|
2995
|
-
const scrubbed = isError(value) && (safe || !inSerialized);
|
|
3085
|
+
const scrubbed = isError(value) && (rules.ownFields.safe || !inSerialized);
|
|
2996
3086
|
const omitted = /* @__PURE__ */ new Set();
|
|
3087
|
+
const header = headerMessage(rules, source, keys, isError(value));
|
|
2997
3088
|
for (const key of keys) {
|
|
2998
|
-
const read =
|
|
3089
|
+
const read = readField(source, key, header);
|
|
2999
3090
|
const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
|
|
3000
3091
|
const hook = honorToJson && key === "toJSON" && typeof current === "function";
|
|
3001
3092
|
if (current === OMIT_OWN_FIELD || hook) {
|
|
@@ -3009,7 +3100,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
3009
3100
|
isCensored(rules, key, current) ? rules.censor : censorHeaderArray(
|
|
3010
3101
|
key,
|
|
3011
3102
|
walk(
|
|
3012
|
-
errorTextField(rules, key, current, scrubbed),
|
|
3103
|
+
errorTextField(rules, key, current, scrubbed, header),
|
|
3013
3104
|
rulesBelow(rules, key, current, honorToJson),
|
|
3014
3105
|
depth2 + 1,
|
|
3015
3106
|
ancestors,
|
|
@@ -3040,7 +3131,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
|
|
|
3040
3131
|
// What a serializer receives names the error `name`, as the error-like shape it reads does;
|
|
3041
3132
|
// everything else keeps the `type` the written entries use.
|
|
3042
3133
|
nameKey: inSerialized ? "name" : "type",
|
|
3043
|
-
censorName: (name) =>
|
|
3134
|
+
censorName: (name) => censorAnyName(rules, name),
|
|
3044
3135
|
walk: (value, depth2) => walk(value, rules, depth2, ancestors, true, inSerialized),
|
|
3045
3136
|
// Under 'safe' the cap does not read a list's `toJSON`: a list over the cap becomes a fresh array
|
|
3046
3137
|
// and is never read for it, and a list within the cap is read once, by the walk.
|
|
@@ -3064,8 +3155,9 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
|
|
|
3064
3155
|
const visits = { count: 0 };
|
|
3065
3156
|
const call = {
|
|
3066
3157
|
...rules,
|
|
3158
|
+
headerKept: typeof value === "object" && value !== null && errorOutputs.has(value),
|
|
3067
3159
|
visits,
|
|
3068
|
-
insideErrors:
|
|
3160
|
+
insideErrors: rulesInside(rules, insideNames, visits)
|
|
3069
3161
|
};
|
|
3070
3162
|
return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
|
|
3071
3163
|
} catch {
|
|
@@ -3436,7 +3528,7 @@ function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
|
|
|
3436
3528
|
() => onTruncate("max_entry_size")
|
|
3437
3529
|
);
|
|
3438
3530
|
return {
|
|
3439
|
-
err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
|
|
3531
|
+
err: bound((error) => markErrorOutput(serializeErrorValue(error, ownFields, censorMessage))),
|
|
3440
3532
|
...Object.fromEntries(
|
|
3441
3533
|
Object.entries(options.serializers).map(
|
|
3442
3534
|
([key, serializer]) => [key, bound(serializer)]
|
|
@@ -4341,8 +4433,8 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4341
4433
|
* BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
|
|
4342
4434
|
*/
|
|
4343
4435
|
static forRoot(options) {
|
|
4344
|
-
|
|
4345
|
-
const resolved =
|
|
4436
|
+
const snapshot = guardOptions(() => dropUnsetOptions(options));
|
|
4437
|
+
const resolved = resolveOptions(snapshot);
|
|
4346
4438
|
const providers = [
|
|
4347
4439
|
{ provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
|
|
4348
4440
|
...buildCommonProviders()
|
|
@@ -4353,7 +4445,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4353
4445
|
providers.push({ provide: APP_FILTER, useClass: HttpExceptionFilter });
|
|
4354
4446
|
}
|
|
4355
4447
|
}
|
|
4356
|
-
return augmentLoggerModule(
|
|
4448
|
+
return augmentLoggerModule(
|
|
4449
|
+
guardOptions(() => super.forRoot(snapshot)),
|
|
4450
|
+
providers
|
|
4451
|
+
);
|
|
4357
4452
|
}
|
|
4358
4453
|
/**
|
|
4359
4454
|
* Asynchronous registration. Options are resolved lazily via the consumer's
|
|
@@ -4382,10 +4477,7 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4382
4477
|
const providers = [
|
|
4383
4478
|
{
|
|
4384
4479
|
provide: LOGGER_OPTIONS_TOKEN,
|
|
4385
|
-
useFactory: (raw) =>
|
|
4386
|
-
validateOptions(raw);
|
|
4387
|
-
return applyDefaults(raw);
|
|
4388
|
-
},
|
|
4480
|
+
useFactory: (raw) => resolveOptions(raw),
|
|
4389
4481
|
inject: [BUILDER_OPTIONS_TOKEN]
|
|
4390
4482
|
},
|
|
4391
4483
|
...buildCommonProviders(),
|
|
@@ -4393,7 +4485,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4393
4485
|
// gated at runtime against the async-resolved `http.isEnabled`.
|
|
4394
4486
|
asyncHttpInterceptorProvider()
|
|
4395
4487
|
];
|
|
4396
|
-
return augmentLoggerModule(
|
|
4488
|
+
return augmentLoggerModule(
|
|
4489
|
+
guardOptions(() => super.forRootAsync(options)),
|
|
4490
|
+
providers
|
|
4491
|
+
);
|
|
4397
4492
|
}
|
|
4398
4493
|
/**
|
|
4399
4494
|
* Replace NestJS's internal logger with this library's `PinoLoggerService` and
|
package/package.json
CHANGED