@bymax-one/nest-logger 1.4.26 → 1.4.27

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
@@ -12,6 +12,39 @@ heading here.
12
12
 
13
13
  ## [Unreleased]
14
14
 
15
+ ## [1.4.27] - 2026-11-21
16
+
17
+ ### Fixed
18
+
19
+ - An option the host supplies that throws when it is read (a getter, a Proxy trap) now ends `forRoot` and
20
+ `forRootAsync` with `[BymaxLoggerModule] options could not be read`, and the error the host threw is its
21
+ `cause`. Before, the host's own error left the module. The refusals of the options themselves (`[BymaxLoggerModule] options.<path> ...`) are
22
+ unchanged. Each redaction option (`redactPaths`, `redactCensor`, `redactStrategy`,
23
+ `shouldDisableDefaultRedact`) is read by name, so it takes effect whether it is a property, a
24
+ non-enumerable getter, a get-only Proxy or a class getter.
25
+ - The message of an object that is no `Error`, below the top level of a log record, is hidden in the
26
+ header of its `stack` as it is in its `message` field, whatever the case or the look of the two keys (`Message`, `STACK`).
27
+ - A `name` that holds an object, an array or a function is hidden with the message (it may carry
28
+ anything), in the stack header and under `error.type`; a number name is kept.
29
+ - The derived keys (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`, ...) are
30
+ owned as they look in a viewer: a spelling that differs only in case, in white space or zero-width
31
+ characters, or in fullwidth forms is owned too. `errorType`, `exception_type`, `exceptionType` and
32
+ `event.name` are other keys and are kept.
33
+
34
+ ### Known limits
35
+
36
+ - An object whose `toJSON` returns a `message` that is not text and a `stack` that carries a secret which
37
+ is not the message text has no text to match: the stack header is written as the object gave it. Put
38
+ such a secret under a name in `redactPaths`, or keep it out of the `stack`.
39
+
40
+ ### Changed
41
+
42
+ - The benchmark of the object message states its margin: the floor is 0.20 and the measurement ranges
43
+ from 0.38 to 0.47 with the load of the host.
44
+ - `pnpm check:property-path` also refuses a variable, a concatenation or a template with a
45
+ substitution as the argument of `toHaveProperty`, and a call with a space before the paren; a key is
46
+ written as an array, `toHaveProperty([key])`.
47
+
15
48
  ## [1.4.26] - 2026-11-21
16
49
 
17
50
  ### Fixed
@@ -53,7 +86,7 @@ heading here.
53
86
  ### Added
54
87
 
55
88
  - 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
89
+ 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
90
  the object form cost more than 5 times a line fails the job.
58
91
  - A check (`pnpm check:property-path`, part of `pnpm lint`) fails on a `toHaveProperty` call that takes a
59
92
  string with a dot: Jest reads it as a nested path, so a negative assertion on a key such as
@@ -3359,7 +3392,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
3359
3392
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
3360
3393
  `release.yml`, Dependabot, and issue templates
3361
3394
 
3362
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.26...HEAD
3395
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.27...HEAD
3396
+ [1.4.27]: https://github.com/bymaxone/nest-logger/compare/v1.4.26...v1.4.27
3363
3397
  [1.4.26]: https://github.com/bymaxone/nest-logger/compare/v1.4.25...v1.4.26
3364
3398
  [1.4.25]: https://github.com/bymaxone/nest-logger/compare/v1.4.24...v1.4.25
3365
3399
  [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 or zero-width characters inside it, or in fullwidth letters 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 |
@@ -186,6 +186,23 @@ function applyDefaults(given) {
186
186
  return Object.freeze(merged);
187
187
  }
188
188
 
189
+ // src/server/config/options-refusal.util.ts
190
+ var refusals = /* @__PURE__ */ new WeakSet();
191
+ var UNREADABLE = "[BymaxLoggerModule] options could not be read";
192
+ function refuse(message) {
193
+ const error = new Error(message);
194
+ refusals.add(error);
195
+ throw error;
196
+ }
197
+ function guardOptions(read) {
198
+ try {
199
+ return read();
200
+ } catch (error) {
201
+ if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
202
+ throw new Error(UNREADABLE, { cause: error });
203
+ }
204
+ }
205
+
189
206
  // src/server/constants/log-levels.constants.ts
190
207
  var PINO_LEVEL_NUMBERS = Object.freeze({
191
208
  fatal: 60,
@@ -214,7 +231,7 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
214
231
  // src/server/config/validate-options.ts
215
232
  function reject(path, rule, got, wasGiven = got !== void 0) {
216
233
  const received = wasGiven ? `. Received ${describeValue(got)}` : "";
217
- throw new Error(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
234
+ refuse(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
218
235
  }
219
236
  function describeValue(value) {
220
237
  switch (typeof value) {
@@ -312,7 +329,7 @@ function validateLifecycle(options) {
312
329
  function validateCore(options) {
313
330
  const service = options.service;
314
331
  if (service === void 0) {
315
- throw new Error("[BymaxLoggerModule] options.service is required");
332
+ refuse("[BymaxLoggerModule] options.service is required");
316
333
  }
317
334
  if (!isRecord2(service)) reject("service", "must be an object", service);
318
335
  for (const field of ["name", "version"]) {
@@ -394,12 +411,12 @@ function validateErrorFields(options) {
394
411
  }
395
412
  });
396
413
  }
397
- var UNREADABLE = /* @__PURE__ */ Symbol("unreadable");
414
+ var UNREADABLE2 = /* @__PURE__ */ Symbol("unreadable");
398
415
  function readMember(destination, key) {
399
416
  try {
400
417
  return Reflect.get(destination, key);
401
418
  } catch {
402
- return UNREADABLE;
419
+ return UNREADABLE2;
403
420
  }
404
421
  }
405
422
  function validateDestination(entry, index) {
@@ -408,16 +425,16 @@ function validateDestination(entry, index) {
408
425
  reject(path, "must be an object implementing ILogDestination", entry, true);
409
426
  }
410
427
  const write = readMember(entry, "write");
411
- if (write !== UNREADABLE && typeof write !== "function") {
428
+ if (write !== UNREADABLE2 && typeof write !== "function") {
412
429
  reject(path, "must have a write(payload) method");
413
430
  }
414
431
  const name = readMember(entry, "name");
415
- if (name !== UNREADABLE && !isNonEmptyString(name)) {
432
+ if (name !== UNREADABLE2 && !isNonEmptyString(name)) {
416
433
  reject(path, "must have a non-empty string name", name);
417
434
  }
418
435
  for (const hook of ["onInit", "onShutdown", "onRegistryReady"]) {
419
436
  const value = readMember(entry, hook);
420
- if (value !== UNREADABLE && value !== void 0 && typeof value !== "function") {
437
+ if (value !== UNREADABLE2 && value !== void 0 && typeof value !== "function") {
421
438
  reject(`${path}.${hook}`, "must be a function", value);
422
439
  }
423
440
  }
@@ -800,9 +817,19 @@ function readsAsError(value) {
800
817
  const candidate = value;
801
818
  return typeof candidate.message === "string" && (isError(value) || typeof candidate.name === "string");
802
819
  }
803
- function readScrubbedStack(value, name, message, result, walk2) {
820
+ function readScrubbedStack(value, name, message, textName, result, walk2) {
804
821
  const stack = readOptional(() => value.stack, result);
805
- return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(name, message, walk2.censorMessage));
822
+ if (stack === void 0) return void 0;
823
+ const header = headerCensor(name, message, walk2.censorMessage);
824
+ return scrubStack(textName ? stack : withNamedHeader(stack, message), header);
825
+ }
826
+ var FRAME_LINE2 = /\n[ \t]+at /;
827
+ function withNamedHeader(stack, message) {
828
+ const found = message === "" ? -1 : stack.indexOf(message);
829
+ if (found !== -1) return `Error: ${stack.slice(found)}`;
830
+ const end = stack.search(FRAME_LINE2);
831
+ const frames = end === -1 ? "" : stack.slice(end);
832
+ return `Error${message === "" ? "" : `: ${message}`}${frames}`;
806
833
  }
807
834
  function toSanitizedError(value, seen, depth2, walk2) {
808
835
  try {
@@ -810,13 +837,13 @@ function toSanitizedError(value, seen, depth2, walk2) {
810
837
  return { name: "UnknownError", message: cutText(String(value)) };
811
838
  }
812
839
  seen.add(value);
813
- const message = value.message;
814
- const name = cutText(typeof value.name === "string" ? value.name : "Error");
840
+ const { message, name: rawName } = value;
841
+ const name = cutText(typeof rawName === "string" ? rawName : "Error");
815
842
  const result = {
816
843
  name: censorName(name, walk2.censorMessage),
817
844
  message: cutText(message)
818
845
  };
819
- const stack = readScrubbedStack(value, name, message, result, walk2);
846
+ const stack = readScrubbedStack(value, name, message, typeof rawName === "string", result, walk2);
820
847
  if (stack !== void 0) result.stack = stack;
821
848
  const isAtDepthLimit = depth2 >= walk2.maxDepth;
822
849
  const cause = readOptional(() => value.cause, result);
@@ -970,9 +997,10 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
970
997
  "exception.stacktrace",
971
998
  "error.type"
972
999
  ]);
1000
+ var lookAlike = (key) => key.normalize("NFKC").replace(/[\p{Cf}\p{Zs}]/gu, "").toLowerCase();
973
1001
  var isOwnedKey = (key) => {
974
1002
  const lower = key.toLowerCase();
975
- return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(lower) || lower.startsWith("service.") || lower.startsWith("deployment.");
1003
+ return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(lookAlike(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
976
1004
  };
977
1005
  function withoutOwnedKeys(metadata, omit) {
978
1006
  if (metadata === void 0) {
@@ -2786,7 +2814,8 @@ function cutOrWalk(value, level, host, depth2) {
2786
2814
  return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
2787
2815
  }
2788
2816
  function writeName(value, level, host, depth2) {
2789
- return typeof value === "string" ? host.censorName(cutText(value)) : cutOrWalk(value, level, host, depth2);
2817
+ const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
2818
+ return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
2790
2819
  }
2791
2820
  function addErrorParts(copy, error, ownKeys, host, depth2) {
2792
2821
  const taken = new Set(ownKeys);
@@ -2835,7 +2864,7 @@ function rulesBelow(rules, key, value, honorToJson) {
2835
2864
  if (leavesErrorText(rules, key, value, honorToJson)) {
2836
2865
  return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
2837
2866
  }
2838
- return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
2867
+ return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
2839
2868
  }
2840
2869
  function isCensored(rules, key, value) {
2841
2870
  const lower = key.toLowerCase();
@@ -2844,10 +2873,32 @@ function isCensored(rules, key, value) {
2844
2873
  function messageCensor(rules) {
2845
2874
  return (text) => rules.sensitive.has("message") ? rules.censor : text;
2846
2875
  }
2847
- function errorTextField(rules, key, value, isError2) {
2876
+ function headerMessage(rules, source, keys, isError2) {
2877
+ if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
2878
+ return void 0;
2879
+ if (rules.headerKept === true) return void 0;
2880
+ const key = keys.find((candidate) => foldKey(candidate) === "message");
2881
+ if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
2882
+ return void 0;
2883
+ }
2884
+ const text = Reflect.get(source, key);
2885
+ return typeof text === "string" ? { key, text } : void 0;
2886
+ }
2887
+ function readField(source, key, header) {
2888
+ return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
2889
+ }
2890
+ function censorAnyName(rules, name) {
2891
+ if (typeof name === "string") return censorName(name, messageCensor(rules));
2892
+ const holder = typeof name === "object" && name !== null || typeof name === "function";
2893
+ return holder && rules.sensitive.has("message") ? rules.censor : name;
2894
+ }
2895
+ function errorTextField(rules, key, value, isError2, header) {
2896
+ if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
2897
+ return hideMessageInStack(value, header.text, rules.censor);
2898
+ }
2848
2899
  if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
2849
2900
  const cut = cutIfText(value);
2850
- return key === "name" && typeof cut === "string" ? censorName(cut, messageCensor(rules)) : cut;
2901
+ return key === "name" ? censorAnyName(rules, cut) : cut;
2851
2902
  }
2852
2903
 
2853
2904
  // src/server/utils/redact-error-clone.util.ts
@@ -2906,6 +2957,14 @@ function resolveToJson(value, viaGet = false) {
2906
2957
  volatile: accessor || proxied
2907
2958
  };
2908
2959
  }
2960
+ function rulesInside(rules, names, visits) {
2961
+ return names === void 0 ? void 0 : { ...rules, sensitive: names, visits, insideErrors: void 0 };
2962
+ }
2963
+ var errorOutputs = /* @__PURE__ */ new WeakSet();
2964
+ function markErrorOutput(output) {
2965
+ if (typeof output === "object" && output !== null) errorOutputs.add(output);
2966
+ return output;
2967
+ }
2909
2968
  function walkArray(value, rules, depth2, ancestors, inSerialized) {
2910
2969
  const length = value.length;
2911
2970
  const copy = [];
@@ -2992,13 +3051,13 @@ function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized)
2992
3051
  function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized) {
2993
3052
  const source = value;
2994
3053
  const keys = Object.keys(source);
2995
- const { safe } = rules.ownFields;
2996
- const asData = isError(value) && (safe || rules.errorsAsData && !inSerialized);
3054
+ const asData = isError(value) && (rules.ownFields.safe || rules.errorsAsData && !inSerialized);
2997
3055
  const copy = startCopy(value, asData);
2998
- const scrubbed = isError(value) && (safe || !inSerialized);
3056
+ const scrubbed = isError(value) && (rules.ownFields.safe || !inSerialized);
2999
3057
  const omitted = /* @__PURE__ */ new Set();
3058
+ const header = headerMessage(rules, source, keys, isError(value));
3000
3059
  for (const key of keys) {
3001
- const read = Reflect.get(source, key);
3060
+ const read = readField(source, key, header);
3002
3061
  const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
3003
3062
  const hook = honorToJson && key === "toJSON" && typeof current === "function";
3004
3063
  if (current === OMIT_OWN_FIELD || hook) {
@@ -3012,7 +3071,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
3012
3071
  isCensored(rules, key, current) ? rules.censor : censorHeaderArray(
3013
3072
  key,
3014
3073
  walk(
3015
- errorTextField(rules, key, current, scrubbed),
3074
+ errorTextField(rules, key, current, scrubbed, header),
3016
3075
  rulesBelow(rules, key, current, honorToJson),
3017
3076
  depth2 + 1,
3018
3077
  ancestors,
@@ -3043,7 +3102,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
3043
3102
  // What a serializer receives names the error `name`, as the error-like shape it reads does;
3044
3103
  // everything else keeps the `type` the written entries use.
3045
3104
  nameKey: inSerialized ? "name" : "type",
3046
- censorName: (name) => censorName(name, messageCensor(rules)),
3105
+ censorName: (name) => censorAnyName(rules, name),
3047
3106
  walk: (value, depth2) => walk(value, rules, depth2, ancestors, true, inSerialized),
3048
3107
  // Under 'safe' the cap does not read a list's `toJSON`: a list over the cap becomes a fresh array
3049
3108
  // and is never read for it, and a list within the cap is read once, by the walk.
@@ -3067,8 +3126,9 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3067
3126
  const visits = { count: 0 };
3068
3127
  const call = {
3069
3128
  ...rules,
3129
+ headerKept: typeof value === "object" && value !== null && errorOutputs.has(value),
3070
3130
  visits,
3071
- insideErrors: insideNames === void 0 ? void 0 : { ...rules, sensitive: insideNames, visits, insideErrors: void 0 }
3131
+ insideErrors: rulesInside(rules, insideNames, visits)
3072
3132
  };
3073
3133
  return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
3074
3134
  } catch {
@@ -3439,7 +3499,7 @@ function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
3439
3499
  () => onTruncate("max_entry_size")
3440
3500
  );
3441
3501
  return {
3442
- err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
3502
+ err: bound((error) => markErrorOutput(serializeErrorValue(error, ownFields, censorMessage))),
3443
3503
  ...Object.fromEntries(
3444
3504
  Object.entries(options.serializers).map(
3445
3505
  ([key, serializer]) => [key, bound(serializer)]
@@ -4344,8 +4404,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4344
4404
  * BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
4345
4405
  */
4346
4406
  static forRoot(options) {
4347
- validateOptions(options);
4348
- const resolved = applyDefaults(options);
4407
+ const resolved = guardOptions(() => {
4408
+ validateOptions(options);
4409
+ return applyDefaults(options);
4410
+ });
4349
4411
  const providers = [
4350
4412
  { provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
4351
4413
  ...buildCommonProviders()
@@ -4356,7 +4418,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4356
4418
  providers.push({ provide: core.APP_FILTER, useClass: exports.HttpExceptionFilter });
4357
4419
  }
4358
4420
  }
4359
- return augmentLoggerModule(super.forRoot(options), providers);
4421
+ return augmentLoggerModule(
4422
+ guardOptions(() => super.forRoot(options)),
4423
+ providers
4424
+ );
4360
4425
  }
4361
4426
  /**
4362
4427
  * Asynchronous registration. Options are resolved lazily via the consumer's
@@ -4386,8 +4451,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4386
4451
  {
4387
4452
  provide: LOGGER_OPTIONS_TOKEN,
4388
4453
  useFactory: (raw) => {
4389
- validateOptions(raw);
4390
- return applyDefaults(raw);
4454
+ return guardOptions(() => {
4455
+ validateOptions(raw);
4456
+ return applyDefaults(raw);
4457
+ });
4391
4458
  },
4392
4459
  inject: [BUILDER_OPTIONS_TOKEN]
4393
4460
  },
@@ -4396,7 +4463,10 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
4396
4463
  // gated at runtime against the async-resolved `http.isEnabled`.
4397
4464
  asyncHttpInterceptorProvider()
4398
4465
  ];
4399
- return augmentLoggerModule(super.forRootAsync(options), providers);
4466
+ return augmentLoggerModule(
4467
+ guardOptions(() => super.forRootAsync(options)),
4468
+ providers
4469
+ );
4400
4470
  }
4401
4471
  /**
4402
4472
  * Replace NestJS's internal logger with this library's `PinoLoggerService` and
@@ -183,6 +183,23 @@ function applyDefaults(given) {
183
183
  return Object.freeze(merged);
184
184
  }
185
185
 
186
+ // src/server/config/options-refusal.util.ts
187
+ var refusals = /* @__PURE__ */ new WeakSet();
188
+ var UNREADABLE = "[BymaxLoggerModule] options could not be read";
189
+ function refuse(message) {
190
+ const error = new Error(message);
191
+ refusals.add(error);
192
+ throw error;
193
+ }
194
+ function guardOptions(read) {
195
+ try {
196
+ return read();
197
+ } catch (error) {
198
+ if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
199
+ throw new Error(UNREADABLE, { cause: error });
200
+ }
201
+ }
202
+
186
203
  // src/server/constants/log-levels.constants.ts
187
204
  var PINO_LEVEL_NUMBERS = Object.freeze({
188
205
  fatal: 60,
@@ -211,7 +228,7 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
211
228
  // src/server/config/validate-options.ts
212
229
  function reject(path2, rule, got, wasGiven = got !== void 0) {
213
230
  const received = wasGiven ? `. Received ${describeValue(got)}` : "";
214
- throw new Error(`[BymaxLoggerModule] options.${path2} ${rule}${received}`);
231
+ refuse(`[BymaxLoggerModule] options.${path2} ${rule}${received}`);
215
232
  }
216
233
  function describeValue(value) {
217
234
  switch (typeof value) {
@@ -309,7 +326,7 @@ function validateLifecycle(options) {
309
326
  function validateCore(options) {
310
327
  const service = options.service;
311
328
  if (service === void 0) {
312
- throw new Error("[BymaxLoggerModule] options.service is required");
329
+ refuse("[BymaxLoggerModule] options.service is required");
313
330
  }
314
331
  if (!isRecord2(service)) reject("service", "must be an object", service);
315
332
  for (const field of ["name", "version"]) {
@@ -391,12 +408,12 @@ function validateErrorFields(options) {
391
408
  }
392
409
  });
393
410
  }
394
- var UNREADABLE = /* @__PURE__ */ Symbol("unreadable");
411
+ var UNREADABLE2 = /* @__PURE__ */ Symbol("unreadable");
395
412
  function readMember(destination, key) {
396
413
  try {
397
414
  return Reflect.get(destination, key);
398
415
  } catch {
399
- return UNREADABLE;
416
+ return UNREADABLE2;
400
417
  }
401
418
  }
402
419
  function validateDestination(entry, index) {
@@ -405,16 +422,16 @@ function validateDestination(entry, index) {
405
422
  reject(path2, "must be an object implementing ILogDestination", entry, true);
406
423
  }
407
424
  const write = readMember(entry, "write");
408
- if (write !== UNREADABLE && typeof write !== "function") {
425
+ if (write !== UNREADABLE2 && typeof write !== "function") {
409
426
  reject(path2, "must have a write(payload) method");
410
427
  }
411
428
  const name = readMember(entry, "name");
412
- if (name !== UNREADABLE && !isNonEmptyString(name)) {
429
+ if (name !== UNREADABLE2 && !isNonEmptyString(name)) {
413
430
  reject(path2, "must have a non-empty string name", name);
414
431
  }
415
432
  for (const hook of ["onInit", "onShutdown", "onRegistryReady"]) {
416
433
  const value = readMember(entry, hook);
417
- if (value !== UNREADABLE && value !== void 0 && typeof value !== "function") {
434
+ if (value !== UNREADABLE2 && value !== void 0 && typeof value !== "function") {
418
435
  reject(`${path2}.${hook}`, "must be a function", value);
419
436
  }
420
437
  }
@@ -797,9 +814,19 @@ function readsAsError(value) {
797
814
  const candidate = value;
798
815
  return typeof candidate.message === "string" && (isError(value) || typeof candidate.name === "string");
799
816
  }
800
- function readScrubbedStack(value, name, message, result, walk2) {
817
+ function readScrubbedStack(value, name, message, textName, result, walk2) {
801
818
  const stack = readOptional(() => value.stack, result);
802
- return stack === void 0 ? void 0 : scrubStack(stack, headerCensor(name, message, walk2.censorMessage));
819
+ if (stack === void 0) return void 0;
820
+ const header = headerCensor(name, message, walk2.censorMessage);
821
+ return scrubStack(textName ? stack : withNamedHeader(stack, message), header);
822
+ }
823
+ var FRAME_LINE2 = /\n[ \t]+at /;
824
+ function withNamedHeader(stack, message) {
825
+ const found = message === "" ? -1 : stack.indexOf(message);
826
+ if (found !== -1) return `Error: ${stack.slice(found)}`;
827
+ const end = stack.search(FRAME_LINE2);
828
+ const frames = end === -1 ? "" : stack.slice(end);
829
+ return `Error${message === "" ? "" : `: ${message}`}${frames}`;
803
830
  }
804
831
  function toSanitizedError(value, seen, depth2, walk2) {
805
832
  try {
@@ -807,13 +834,13 @@ function toSanitizedError(value, seen, depth2, walk2) {
807
834
  return { name: "UnknownError", message: cutText(String(value)) };
808
835
  }
809
836
  seen.add(value);
810
- const message = value.message;
811
- const name = cutText(typeof value.name === "string" ? value.name : "Error");
837
+ const { message, name: rawName } = value;
838
+ const name = cutText(typeof rawName === "string" ? rawName : "Error");
812
839
  const result = {
813
840
  name: censorName(name, walk2.censorMessage),
814
841
  message: cutText(message)
815
842
  };
816
- const stack = readScrubbedStack(value, name, message, result, walk2);
843
+ const stack = readScrubbedStack(value, name, message, typeof rawName === "string", result, walk2);
817
844
  if (stack !== void 0) result.stack = stack;
818
845
  const isAtDepthLimit = depth2 >= walk2.maxDepth;
819
846
  const cause = readOptional(() => value.cause, result);
@@ -967,9 +994,10 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
967
994
  "exception.stacktrace",
968
995
  "error.type"
969
996
  ]);
997
+ var lookAlike = (key) => key.normalize("NFKC").replace(/[\p{Cf}\p{Zs}]/gu, "").toLowerCase();
970
998
  var isOwnedKey = (key) => {
971
999
  const lower = key.toLowerCase();
972
- return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(lower) || lower.startsWith("service.") || lower.startsWith("deployment.");
1000
+ return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(lookAlike(key)) || lower.startsWith("service.") || lower.startsWith("deployment.");
973
1001
  };
974
1002
  function withoutOwnedKeys(metadata, omit) {
975
1003
  if (metadata === void 0) {
@@ -2783,7 +2811,8 @@ function cutOrWalk(value, level, host, depth2) {
2783
2811
  return typeof value === "string" ? cutText(value) : walkChainPart(value, level, host, depth2);
2784
2812
  }
2785
2813
  function writeName(value, level, host, depth2) {
2786
- return typeof value === "string" ? host.censorName(cutText(value)) : cutOrWalk(value, level, host, depth2);
2814
+ const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
2815
+ return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
2787
2816
  }
2788
2817
  function addErrorParts(copy, error, ownKeys, host, depth2) {
2789
2818
  const taken = new Set(ownKeys);
@@ -2832,7 +2861,7 @@ function rulesBelow(rules, key, value, honorToJson) {
2832
2861
  if (leavesErrorText(rules, key, value, honorToJson)) {
2833
2862
  return { ...rules, exemptKeys: ERROR_TEXT_KEYS };
2834
2863
  }
2835
- return rules.exemptKeys === void 0 ? rules : { ...rules, exemptKeys: void 0 };
2864
+ return rules.exemptKeys === void 0 && rules.headerKept !== true ? rules : { ...rules, exemptKeys: void 0, headerKept: void 0 };
2836
2865
  }
2837
2866
  function isCensored(rules, key, value) {
2838
2867
  const lower = key.toLowerCase();
@@ -2841,10 +2870,32 @@ function isCensored(rules, key, value) {
2841
2870
  function messageCensor(rules) {
2842
2871
  return (text) => rules.sensitive.has("message") ? rules.censor : text;
2843
2872
  }
2844
- function errorTextField(rules, key, value, isError2) {
2873
+ function headerMessage(rules, source, keys, isError2) {
2874
+ if (isError2 || !rules.sensitive.has("message") || rules.exemptKeys?.has("message") === true)
2875
+ return void 0;
2876
+ if (rules.headerKept === true) return void 0;
2877
+ const key = keys.find((candidate) => foldKey(candidate) === "message");
2878
+ if (key === void 0 || !keys.some((candidate) => foldKey(candidate) === "stack")) {
2879
+ return void 0;
2880
+ }
2881
+ const text = Reflect.get(source, key);
2882
+ return typeof text === "string" ? { key, text } : void 0;
2883
+ }
2884
+ function readField(source, key, header) {
2885
+ return header !== void 0 && key === header.key ? header.text : Reflect.get(source, key);
2886
+ }
2887
+ function censorAnyName(rules, name) {
2888
+ if (typeof name === "string") return censorName(name, messageCensor(rules));
2889
+ const holder = typeof name === "object" && name !== null || typeof name === "function";
2890
+ return holder && rules.sensitive.has("message") ? rules.censor : name;
2891
+ }
2892
+ function errorTextField(rules, key, value, isError2, header) {
2893
+ if (header !== void 0 && foldKey(key) === "stack" && typeof value === "string") {
2894
+ return hideMessageInStack(value, header.text, rules.censor);
2895
+ }
2845
2896
  if (!isError2 || !ERROR_TEXT_FIELDS.has(key)) return value;
2846
2897
  const cut = cutIfText(value);
2847
- return key === "name" && typeof cut === "string" ? censorName(cut, messageCensor(rules)) : cut;
2898
+ return key === "name" ? censorAnyName(rules, cut) : cut;
2848
2899
  }
2849
2900
 
2850
2901
  // src/server/utils/redact-error-clone.util.ts
@@ -2903,6 +2954,14 @@ function resolveToJson(value, viaGet = false) {
2903
2954
  volatile: accessor || proxied
2904
2955
  };
2905
2956
  }
2957
+ function rulesInside(rules, names, visits) {
2958
+ return names === void 0 ? void 0 : { ...rules, sensitive: names, visits, insideErrors: void 0 };
2959
+ }
2960
+ var errorOutputs = /* @__PURE__ */ new WeakSet();
2961
+ function markErrorOutput(output) {
2962
+ if (typeof output === "object" && output !== null) errorOutputs.add(output);
2963
+ return output;
2964
+ }
2906
2965
  function walkArray(value, rules, depth2, ancestors, inSerialized) {
2907
2966
  const length = value.length;
2908
2967
  const copy = [];
@@ -2989,13 +3048,13 @@ function walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized)
2989
3048
  function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerialized) {
2990
3049
  const source = value;
2991
3050
  const keys = Object.keys(source);
2992
- const { safe } = rules.ownFields;
2993
- const asData = isError(value) && (safe || rules.errorsAsData && !inSerialized);
3051
+ const asData = isError(value) && (rules.ownFields.safe || rules.errorsAsData && !inSerialized);
2994
3052
  const copy = startCopy(value, asData);
2995
- const scrubbed = isError(value) && (safe || !inSerialized);
3053
+ const scrubbed = isError(value) && (rules.ownFields.safe || !inSerialized);
2996
3054
  const omitted = /* @__PURE__ */ new Set();
3055
+ const header = headerMessage(rules, source, keys, isError(value));
2997
3056
  for (const key of keys) {
2998
- const read = Reflect.get(source, key);
3057
+ const read = readField(source, key, header);
2999
3058
  const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
3000
3059
  const hook = honorToJson && key === "toJSON" && typeof current === "function";
3001
3060
  if (current === OMIT_OWN_FIELD || hook) {
@@ -3009,7 +3068,7 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
3009
3068
  isCensored(rules, key, current) ? rules.censor : censorHeaderArray(
3010
3069
  key,
3011
3070
  walk(
3012
- errorTextField(rules, key, current, scrubbed),
3071
+ errorTextField(rules, key, current, scrubbed, header),
3013
3072
  rulesBelow(rules, key, current, honorToJson),
3014
3073
  depth2 + 1,
3015
3074
  ancestors,
@@ -3040,7 +3099,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
3040
3099
  // What a serializer receives names the error `name`, as the error-like shape it reads does;
3041
3100
  // everything else keeps the `type` the written entries use.
3042
3101
  nameKey: inSerialized ? "name" : "type",
3043
- censorName: (name) => censorName(name, messageCensor(rules)),
3102
+ censorName: (name) => censorAnyName(rules, name),
3044
3103
  walk: (value, depth2) => walk(value, rules, depth2, ancestors, true, inSerialized),
3045
3104
  // Under 'safe' the cap does not read a list's `toJSON`: a list over the cap becomes a fresh array
3046
3105
  // and is never read for it, and a list within the cap is read once, by the walk.
@@ -3064,8 +3123,9 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
3064
3123
  const visits = { count: 0 };
3065
3124
  const call = {
3066
3125
  ...rules,
3126
+ headerKept: typeof value === "object" && value !== null && errorOutputs.has(value),
3067
3127
  visits,
3068
- insideErrors: insideNames === void 0 ? void 0 : { ...rules, sensitive: insideNames, visits, insideErrors: void 0 }
3128
+ insideErrors: rulesInside(rules, insideNames, visits)
3069
3129
  };
3070
3130
  return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
3071
3131
  } catch {
@@ -3436,7 +3496,7 @@ function buildSerializers(options, redactSerialized, ownFields, onTruncate) {
3436
3496
  () => onTruncate("max_entry_size")
3437
3497
  );
3438
3498
  return {
3439
- err: bound((error) => serializeErrorValue(error, ownFields, censorMessage)),
3499
+ err: bound((error) => markErrorOutput(serializeErrorValue(error, ownFields, censorMessage))),
3440
3500
  ...Object.fromEntries(
3441
3501
  Object.entries(options.serializers).map(
3442
3502
  ([key, serializer]) => [key, bound(serializer)]
@@ -4341,8 +4401,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
4341
4401
  * BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
4342
4402
  */
4343
4403
  static forRoot(options) {
4344
- validateOptions(options);
4345
- const resolved = applyDefaults(options);
4404
+ const resolved = guardOptions(() => {
4405
+ validateOptions(options);
4406
+ return applyDefaults(options);
4407
+ });
4346
4408
  const providers = [
4347
4409
  { provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
4348
4410
  ...buildCommonProviders()
@@ -4353,7 +4415,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
4353
4415
  providers.push({ provide: APP_FILTER, useClass: HttpExceptionFilter });
4354
4416
  }
4355
4417
  }
4356
- return augmentLoggerModule(super.forRoot(options), providers);
4418
+ return augmentLoggerModule(
4419
+ guardOptions(() => super.forRoot(options)),
4420
+ providers
4421
+ );
4357
4422
  }
4358
4423
  /**
4359
4424
  * Asynchronous registration. Options are resolved lazily via the consumer's
@@ -4383,8 +4448,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
4383
4448
  {
4384
4449
  provide: LOGGER_OPTIONS_TOKEN,
4385
4450
  useFactory: (raw) => {
4386
- validateOptions(raw);
4387
- return applyDefaults(raw);
4451
+ return guardOptions(() => {
4452
+ validateOptions(raw);
4453
+ return applyDefaults(raw);
4454
+ });
4388
4455
  },
4389
4456
  inject: [BUILDER_OPTIONS_TOKEN]
4390
4457
  },
@@ -4393,7 +4460,10 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
4393
4460
  // gated at runtime against the async-resolved `http.isEnabled`.
4394
4461
  asyncHttpInterceptorProvider()
4395
4462
  ];
4396
- return augmentLoggerModule(super.forRootAsync(options), providers);
4463
+ return augmentLoggerModule(
4464
+ guardOptions(() => super.forRootAsync(options)),
4465
+ providers
4466
+ );
4397
4467
  }
4398
4468
  /**
4399
4469
  * Replace NestJS's internal logger with this library's `PinoLoggerService` and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-logger",
3
- "version": "1.4.26",
3
+ "version": "1.4.27",
4
4
  "description": "Structured JSON logging for NestJS based on Pino 10, with optional OpenTelemetry correlation.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",