@bymax-one/nest-logger 1.4.22 → 1.4.23

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,81 @@ heading here.
12
12
 
13
13
  ## [Unreleased]
14
14
 
15
+ ## [1.4.23] - 2026-11-17
16
+
17
+ ### Breaking
18
+
19
+ - **A payload cannot replace the correlation keys the logger writes from the request context and
20
+ the active span.** A `requestId`, a `tenantId` or another key of the request
21
+ context inside a request, or the trace fields under an active span (`traceId`, `spanId`, `traceFlags`, or the names you set in `otel`,
22
+ or `trace_id`, `span_id` and `trace_flags` with `fieldFormat: 'snake_case'`) carried by an
23
+ object message, by the metadata of a structured call or by the raw Pino logger replaced the
24
+ value the logger had written, so a line could be attributed to another request, tenant or trace.
25
+ The logger's value now wins, except `userId`, which a structured call names as an argument and which keeps winning over the one of the request context; a key the logger does not write, including a `requestId` outside any
26
+ request, is kept as the payload has it, and a key the logger leaves `undefined` does not erase the payload's own value. The merge also drops the payload's own `__proto__` key and its symbol keys, which `Object.assign` used to copy. **Apply:** nothing is required; code that set one of
27
+ these keys on purpose inside a request to override the context no longer gets that, so set it in
28
+ the request context instead (`LogContextService.run`).
29
+ - **A key the logger writes itself can no longer be replaced from `meta` or from an object
30
+ message.** `level`, `time`, `msg`, `service`, `deployment`, `service.*` and `deployment.*`, in the metadata of `info`, `warnStructured` and
31
+ `errorStructured`, were written as a second key of the same name, and a reader that keeps the
32
+ last of a repeated key saw the caller's `level`, `service` or environment. They are dropped from
33
+ the metadata and from an object message, as `logKey`, `userId` and `context` already were.
34
+ **Apply:** nothing is required; a field you named `level`, `time`, `msg`, `service` or
35
+ `deployment` in `meta` is no longer written, so rename it (`severity`, `elapsedMs`, `detail`,
36
+ `owner`, `rollout`).
37
+
38
+ ### Fixed
39
+
40
+ - **A plain object passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal`
41
+ is written as the fields of the entry.** `new Logger('Queue').warn({ event: 'QUEUE_DRAINED',
42
+ jobs: 7 })` through `app.useLogger(app.get(PinoLoggerService))` wrote `msg: "[object Object]"`
43
+ and every key was lost. The
44
+ keys are now fields of the entry, through the same redaction and `maxStringLength` pipeline as
45
+ any other field (a `password` is censored, a long string is cut), the entry text is the
46
+ object's `message` string, else its `event` string, else empty, and the keys the logger
47
+ owns are dropped from the object as they are from `meta`. The text is censored under the names of
48
+ the field it came from, also with `redactStrategy: 'paths'`, so a secret in `event` or `message`
49
+ does not reach `msg`, and it is cut at `maxStringLength` like the 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, keep their own error-only path,
50
+ and a value that is not plain (a class instance, an array) is still written as its string form.
51
+ **Apply:** code that logged an object and got `[object Object]` now gets its fields; a
52
+ dashboard or an alert that matched `[object Object]` in `msg` matches the `event` or `message`
53
+ text instead.
54
+ - **An option that holds `undefined` or `null` is read as not set, in the options and in every
55
+ group.** An `undefined` in a group replaced its default in the spread that merges the two, so `shouldCaptureExceptions: undefined` stayed
56
+ `undefined` and not the default `true`, and a `null` anywhere was refused as a value of the wrong
57
+ kind. Each known key is read by property access, so an `http` or `otel` group written as
58
+ a class instance whose values are getters on its prototype is honored; the spread that merged it skipped them and
59
+ the default won. `false`, `0` and `''` are values you set and are judged as before, and `service`
60
+ is still required: a `null` or an `undefined` service says `options.service is required`, where
61
+ 1.4.22 said `must be an object. Received null` for `null`. **Apply:** nothing is required; code
62
+ that relied on a `null` option being refused, or on an explicit `undefined` in a group replacing
63
+ its default, no longer gets that.
64
+ - **A refusal does not print the key of a serializer, and names the type of an `undefined` list
65
+ member.** The refusal of a serializer that is not a function now says
66
+ `options.serializers must map every serializer key to a function`, followed by the type
67
+ received (a member that is itself `undefined` keeps no type), where it printed the key the caller chose, and a member of `redactPaths`,
68
+ `errorOwnFieldNames`, `destinations`, `http.excludePaths` or `http.secretPathSegments`
69
+ that is `undefined` is refused as `Received undefined`, where it had no
70
+ type. **Apply:** code that matches the text of the serializer refusal matches the new one.
71
+ - **The censor rule holds when the logger is built from resolved options.** A `redactCensor` longer
72
+ than `maxStringLength` was refused only by `validateOptions`, so a derived backend that built
73
+ `ResolvedBymaxLoggerModuleOptions` itself and called the factory that builds the logger skipped it,
74
+ and its censor would be cut. The factory refuses it with the same message. **Apply:** a derived
75
+ backend that builds the resolved options keeps its censor within the limit.
76
+
77
+ #### Apply to a derived backend
78
+
79
+ `PinoLoggerService` gains two private members, `nestStyleMessage` and `censorText`, in its
80
+ declaration. A subclass that defines a member of either name no longer compiles against it: rename
81
+ yours. Nothing else about its constructor or its public methods changes.
82
+
83
+ A service you build by hand over a Pino instance from `buildPinoInstance` censors and cuts the text
84
+ of an object message with the function the factory leaves on that instance; over a Pino instance you
85
+ built yourself, it falls back to its own redactor and applies no `maxStringLength`. That function is a property of the instance under a symbol key, so `getRawLogger()` returns an instance that carries it. Code that calls
86
+ `buildPinoInstance` gets the merge in which the keys the logger writes from the request context and
87
+ the span win over a payload, and the owned-key guard applies to the metadata and to an object message
88
+ of every method of the service; nothing is required beyond what the Breaking entries above say.
89
+
15
90
  ## [1.4.22] - 2026-11-17
16
91
 
17
92
  ### Breaking
@@ -3020,7 +3095,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
3020
3095
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
3021
3096
  `release.yml`, Dependabot, and issue templates
3022
3097
 
3023
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.22...HEAD
3098
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.23...HEAD
3099
+ [1.4.23]: https://github.com/bymaxone/nest-logger/compare/v1.4.22...v1.4.23
3024
3100
  [1.4.22]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...v1.4.22
3025
3101
  [1.4.21]: https://github.com/bymaxone/nest-logger/compare/v1.4.20...v1.4.21
3026
3102
  [1.4.20]: https://github.com/bymaxone/nest-logger/compare/v1.4.19...v1.4.20
package/README.md CHANGED
@@ -250,6 +250,8 @@ Wire the access log in `main.ts` with `applyAccessLog(app)` (see [HTTP Logging](
250
250
 
251
251
  Full options reference for `BymaxLoggerModule.forRoot(options)`:
252
252
 
253
+ A key that holds `undefined` or `null` is read as not set, in the options and in each group, so its default applies; `false`, `0` and `''` are values you set and are judged as such, and `service` is required.
254
+
253
255
  ### Top-level options
254
256
 
255
257
  | Option | Type | Default | Description |
@@ -989,7 +991,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
989
991
  | `warnStructured` | `(logKey, msg, userId?, meta?)` | Structured warn log — takes a **message string** |
990
992
  | `errorStructured` | `(logKey, error, userId?, meta?)` | Structured error log — takes an **`Error`**, serialized to `err` |
991
993
 
992
- `meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them) and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field.
994
+ `meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them), `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` are written by the logger itself and are dropped from `meta`, and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field. A key the logger writes from the request context or from the active span (`requestId`, `tenantId`, the trace fields) keeps the logger's value when the payload carries the same key, for `meta`, an object message and the raw Pino logger alike, except `userId`, which a call names as an argument and which wins over the one of the request context; a key the logger does not write, such as a `requestId` outside a request, keeps the payload's own value. The raw Pino logger from `getRawLogger()` bypasses the owned-key guards of `meta` and of an object message, so a payload can still repeat `level`, `service` or `userId` there; the request and trace keys still win, and redaction still applies.
993
995
 
994
996
  **NestJS `LoggerService` bridge** — the variadic contract NestJS calls, so `app.useLogger()` works. These take a message, not a log key.
995
997
 
@@ -1002,13 +1004,15 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
1002
1004
  | `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
1003
1005
  | `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
1004
1006
 
1007
+ **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, and a value that is not plain (a class instance, an array) is still written as its string form.
1008
+
1005
1009
  **Helpers**
1006
1010
 
1007
1011
  | Method | Signature | Notes |
1008
1012
  | -------------- | ------------ | ----------------------------------------------------------------- |
1009
1013
  | `child` | `(bindings)` | New `PinoLoggerService` over a Pino child logger |
1010
1014
  | `setContext` | `(context)` | Global label — ⚠️ singleton; prefer `@InjectLogger(MyClass.name)` |
1011
- | `getRawLogger` | `()` | The underlying Pino instance |
1015
+ | `getRawLogger` | `()` | The underlying Pino instance; bypasses the `meta` guards above |
1012
1016
 
1013
1017
  > [!NOTE]
1014
1018
  > There is no `fatalStructured` / `debugStructured`. Structured `fatal` and `debug` helpers are out of scope until a consumer needs them; use `getRawLogger()` in the meantime.
@@ -25,6 +25,73 @@ var __decorateClass = (decorators, target, key, kind) => {
25
25
  };
26
26
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
27
27
 
28
+ // src/server/config/drop-unset-options.ts
29
+ var OPTION_KEYS = {
30
+ service: true,
31
+ level: true,
32
+ isGlobal: true,
33
+ shouldUseAsNestLogger: true,
34
+ redactPaths: true,
35
+ redactStrategy: true,
36
+ resourceFormat: true,
37
+ eventNameField: true,
38
+ errorFormat: true,
39
+ redactCensor: true,
40
+ shouldDisableDefaultRedact: true,
41
+ destinations: true,
42
+ http: true,
43
+ otel: true,
44
+ maxEntrySizeBytes: true,
45
+ maxStringLength: true,
46
+ destinationHookTimeoutMs: true,
47
+ shutdown: true,
48
+ destinationQueue: true,
49
+ errorOwnFields: true,
50
+ errorOwnFieldNames: true,
51
+ serializers: true,
52
+ timestamp: true
53
+ };
54
+ var GROUP_KEYS = {
55
+ http: {
56
+ isEnabled: true,
57
+ shouldCaptureExceptions: true,
58
+ shouldGenerateRequestId: true,
59
+ excludePaths: true,
60
+ secretPathSegments: true,
61
+ tenantIdHeader: true,
62
+ tenantIdResolver: true
63
+ },
64
+ otel: {
65
+ shouldAutoInjectTraceContext: true,
66
+ fieldFormat: true,
67
+ traceIdField: true,
68
+ spanIdField: true,
69
+ traceFlagsField: true
70
+ },
71
+ shutdown: { timeoutMs: true, drainTimeoutMs: true },
72
+ destinationQueue: { maxBytes: true }
73
+ };
74
+ var GROUP_NAMES = Object.keys(GROUP_KEYS);
75
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
76
+ function readSet(source, keys) {
77
+ const set = {};
78
+ for (const key of keys) {
79
+ const value = Reflect.get(source, key);
80
+ if (value !== void 0 && value !== null) Reflect.set(set, key, value);
81
+ }
82
+ return set;
83
+ }
84
+ function dropUnsetOptions(options) {
85
+ if (!isRecord(options)) return options;
86
+ const set = readSet(options, Object.keys(OPTION_KEYS));
87
+ for (const group of GROUP_NAMES) {
88
+ const value = Reflect.get(set, group);
89
+ if (isRecord(value))
90
+ Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
91
+ }
92
+ return set;
93
+ }
94
+
28
95
  // src/server/constants/lifecycle-timeouts.constants.ts
29
96
  var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
30
97
  var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
@@ -72,7 +139,8 @@ function applyOtelFieldFormat(merged, user) {
72
139
  }
73
140
  return merged;
74
141
  }
75
- function applyDefaults(options) {
142
+ function applyDefaults(given) {
143
+ const options = dropUnsetOptions(given);
76
144
  const isProduction = process.env["NODE_ENV"] === "production";
77
145
  const http = { ...DEFAULT_HTTP, ...options.http ?? {} };
78
146
  const otel = applyOtelFieldFormat(
@@ -144,8 +212,8 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
144
212
  ]);
145
213
 
146
214
  // src/server/config/validate-options.ts
147
- function reject(path, rule, got) {
148
- const received = got === void 0 ? "" : `. Received ${describeValue(got)}`;
215
+ function reject(path, rule, got, wasGiven = got !== void 0) {
216
+ const received = wasGiven ? `. Received ${describeValue(got)}` : "";
149
217
  throw new Error(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
150
218
  }
151
219
  function describeValue(value) {
@@ -162,12 +230,14 @@ function describeValue(value) {
162
230
  return "a symbol";
163
231
  case "function":
164
232
  return "a function";
233
+ case "undefined":
234
+ return "undefined";
165
235
  default:
166
236
  if (value === null) return "null";
167
237
  return Array.isArray(value) ? "an array" : "an object";
168
238
  }
169
239
  }
170
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
240
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
171
241
  var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
172
242
  function checkBoolean(path, value) {
173
243
  if (value !== void 0 && typeof value !== "boolean") {
@@ -181,7 +251,7 @@ function checkNonEmptyString(path, value) {
181
251
  }
182
252
  function checkGroup(path, value) {
183
253
  if (value === void 0) return void 0;
184
- if (!isRecord(value)) reject(path, "must be an object", value);
254
+ if (!isRecord2(value)) reject(path, "must be an object", value);
185
255
  return value;
186
256
  }
187
257
  var MAX_TIMER_MS = 2147483647;
@@ -213,7 +283,9 @@ function validateStringLimit(options) {
213
283
  limit
214
284
  );
215
285
  }
216
- const censor = options.redactCensor;
286
+ refuseCensorBeyondLimit(options.redactCensor, limit);
287
+ }
288
+ function refuseCensorBeyondLimit(censor, limit) {
217
289
  if (typeof censor === "string" && censor.length > limit) {
218
290
  reject(
219
291
  "redactCensor",
@@ -242,7 +314,7 @@ function validateCore(options) {
242
314
  if (service === void 0) {
243
315
  throw new Error("[BymaxLoggerModule] options.service is required");
244
316
  }
245
- if (!isRecord(service)) reject("service", "must be an object", service);
317
+ if (!isRecord2(service)) reject("service", "must be an object", service);
246
318
  for (const field of ["name", "version"]) {
247
319
  const given = service[field];
248
320
  if (typeof given !== "string" || given.trim() === "") {
@@ -294,16 +366,16 @@ function validateCustomization(options) {
294
366
  if (!Array.isArray(paths)) reject("redactPaths", "must be an array of strings", paths);
295
367
  paths.forEach((entry, index) => {
296
368
  if (!isNonEmptyString(entry)) {
297
- reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry);
369
+ reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry, true);
298
370
  }
299
371
  });
300
372
  }
301
373
  const serializers = options.serializers;
302
374
  if (serializers !== void 0) {
303
- if (!isRecord(serializers)) reject("serializers", "must be an object", serializers);
304
- for (const [key, serializer] of Object.entries(serializers)) {
375
+ if (!isRecord2(serializers)) reject("serializers", "must be an object", serializers);
376
+ for (const serializer of Object.values(serializers)) {
305
377
  if (typeof serializer !== "function") {
306
- reject(`serializers.${key}`, "must be a function", serializer);
378
+ reject("serializers", "must map every serializer key to a function", serializer);
307
379
  }
308
380
  }
309
381
  }
@@ -318,7 +390,7 @@ function validateErrorFields(options) {
318
390
  if (!Array.isArray(names)) reject("errorOwnFieldNames", "must be an array of strings", names);
319
391
  names.forEach((entry, index) => {
320
392
  if (!isNonEmptyString(entry)) {
321
- reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry);
393
+ reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry, true);
322
394
  }
323
395
  });
324
396
  }
@@ -332,8 +404,8 @@ function readMember(destination, key) {
332
404
  }
333
405
  function validateDestination(entry, index) {
334
406
  const path = `destinations[${String(index)}]`;
335
- if (!isRecord(entry)) {
336
- reject(path, "must be an object implementing ILogDestination", entry);
407
+ if (!isRecord2(entry)) {
408
+ reject(path, "must be an object implementing ILogDestination", entry, true);
337
409
  }
338
410
  const write = readMember(entry, "write");
339
411
  if (write !== UNREADABLE && typeof write !== "function") {
@@ -365,7 +437,7 @@ function checkRegExpList(path, value) {
365
437
  }
366
438
  value.forEach((pattern, index) => {
367
439
  if (!util.types.isRegExp(pattern)) {
368
- reject(`${path}[${String(index)}]`, "must be a RegExp", pattern);
440
+ reject(`${path}[${String(index)}]`, "must be a RegExp", pattern, true);
369
441
  }
370
442
  });
371
443
  }
@@ -398,7 +470,8 @@ function validateOtel(options) {
398
470
  checkNonEmptyString("otel.spanIdField", otel["spanIdField"]);
399
471
  checkNonEmptyString("otel.traceFlagsField", otel["traceFlagsField"]);
400
472
  }
401
- function validateOptions(options) {
473
+ function validateOptions(given) {
474
+ const options = dropUnsetOptions(given);
402
475
  validateCore(options);
403
476
  validateClosedSets(options);
404
477
  validateCustomization(options);
@@ -475,6 +548,20 @@ function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
475
548
  return whole + TEXT_TRUNCATED;
476
549
  }
477
550
 
551
+ // src/server/utils/entry-text-finisher.util.ts
552
+ var ENTRY_TEXT_FINISHER = /* @__PURE__ */ Symbol("bymax.entryTextFinisher");
553
+ function createEntryTextFinisher(redact, limit) {
554
+ return (key, text) => {
555
+ try {
556
+ const censored = Reflect.get(redact({ [key]: text }, true), key);
557
+ if (typeof censored !== "string") return "";
558
+ return limit === void 0 ? censored : cutText(censored, false, limit);
559
+ } catch {
560
+ return "";
561
+ }
562
+ };
563
+ }
564
+
478
565
  // src/server/utils/escape-log-text.util.ts
479
566
  var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
480
567
  var UNSAFE_IN_SINGLE_LINE = /[\u0000-\u0008\u000A-\u001F\u007F-\u009F\u2028\u2029]/g;
@@ -494,6 +581,16 @@ function toBoundedMessage(text) {
494
581
  function escapeControlCharacters(text) {
495
582
  return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
496
583
  }
584
+
585
+ // src/server/utils/is-plain-record.util.ts
586
+ function isPlainRecord(node) {
587
+ try {
588
+ const prototype = Object.getPrototypeOf(node);
589
+ return prototype === Object.prototype || prototype === null;
590
+ } catch {
591
+ return false;
592
+ }
593
+ }
497
594
  function isError(value) {
498
595
  try {
499
596
  return util.types.isNativeError(value) || value instanceof Error;
@@ -690,14 +787,22 @@ function createWidthMarker(omitted) {
690
787
 
691
788
  // src/server/services/pino-logger.service.ts
692
789
  var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
693
- function withoutOwnedKeys(metadata) {
790
+ var ENTRY_STRUCTURE_KEYS = /* @__PURE__ */ new Set([
791
+ "level",
792
+ "time",
793
+ "msg",
794
+ "service",
795
+ "deployment"
796
+ ]);
797
+ var isEntryStructureKey = (key) => ENTRY_STRUCTURE_KEYS.has(key) || key.startsWith("service.") || key.startsWith("deployment.");
798
+ function withoutOwnedKeys(metadata, omit) {
694
799
  if (metadata === void 0) {
695
800
  return {};
696
801
  }
697
802
  try {
698
803
  const safe = {};
699
804
  for (const key of Object.keys(metadata)) {
700
- if (!OWNED_PAYLOAD_KEYS.includes(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
805
+ if (key !== omit && !OWNED_PAYLOAD_KEYS.includes(key) && !isEntryStructureKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
701
806
  Reflect.set(safe, key, Reflect.get(metadata, key));
702
807
  }
703
808
  }
@@ -716,6 +821,23 @@ function safeErrorMessage(error) {
716
821
  return "Unreadable error message";
717
822
  }
718
823
  }
824
+ function objectMessageText(fields) {
825
+ for (const key of ["message", "event"]) {
826
+ try {
827
+ const value = Reflect.get(fields, key);
828
+ if (typeof value === "string") return { key, text: value };
829
+ } catch {
830
+ }
831
+ }
832
+ return void 0;
833
+ }
834
+ function readObjectMessage(message) {
835
+ const fields = isPlainRecord(message) && !isErrorLike(message) ? message : void 0;
836
+ const text = fields === void 0 ? void 0 : objectMessageText(fields);
837
+ const omit = text?.key === "message" ? "message" : void 0;
838
+ const payload = withoutOwnedKeys(fields, omit);
839
+ return { fields, text, payload };
840
+ }
719
841
  function safeLogMessage(message) {
720
842
  try {
721
843
  return toBoundedMessage(typeof message === "string" ? message : String(message));
@@ -790,11 +912,11 @@ exports.PinoLoggerService = class PinoLoggerService {
790
912
  }
791
913
  const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
792
914
  const context = typeof optionalParams[1] === "string" ? optionalParams[1] : this.context;
793
- const payload = {};
915
+ const { fields, text, payload } = readObjectMessage(message);
794
916
  assignIfDefined(payload, "context", context);
795
917
  assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
796
918
  assignIfDefined(payload, "err", findErrorParam(optionalParams));
797
- this.pino.error(payload, safeLogMessage(message));
919
+ this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
798
920
  }
799
921
  /**
800
922
  * NestJS `warn` (warn level).
@@ -946,12 +1068,30 @@ exports.PinoLoggerService = class PinoLoggerService {
946
1068
  }
947
1069
  }
948
1070
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1071
+ nestStyleMessage(leading, fields, text, message) {
1072
+ if (leading !== void 0) return safeErrorMessage(leading);
1073
+ if (fields !== void 0) return toBoundedMessage(this.censorText(text));
1074
+ return safeLogMessage(message);
1075
+ }
1076
+ /**
1077
+ * The entry text of an object message, censored under the names of the field it came from and cut
1078
+ * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
+ * value the pipeline censors or cuts in the field itself.
1080
+ *
1081
+ * @param text - The text and the member it came from.
1082
+ * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
+ */
1084
+ censorText(text) {
1085
+ if (text === void 0) return "";
1086
+ const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
1087
+ return finish(text.key, text.text);
1088
+ }
949
1089
  emitNestStyle(level, message, optionalParams) {
950
- const payload = {};
1090
+ const { fields, text, payload } = readObjectMessage(message);
951
1091
  assignIfDefined(payload, "context", this.resolveContext(optionalParams));
952
1092
  const leading = isErrorLike(message) ? message : void 0;
953
1093
  assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
954
- const msg = leading === void 0 ? safeLogMessage(message) : safeErrorMessage(leading);
1094
+ const msg = this.nestStyleMessage(leading, fields, text, message);
955
1095
  switch (level) {
956
1096
  case "info":
957
1097
  this.pino.info(payload, msg);
@@ -2176,11 +2316,6 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
2176
2316
  }
2177
2317
 
2178
2318
  // src/server/utils/cut-strings.util.ts
2179
- function isPlainRecord(node) {
2180
- if (node === null || typeof node !== "object") return false;
2181
- const prototype = Object.getPrototypeOf(node);
2182
- return prototype === Object.prototype || prototype === null;
2183
- }
2184
2319
  function cutNode(node, limit) {
2185
2320
  if (typeof node === "string") return cutText(node, false, limit);
2186
2321
  if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
@@ -2336,6 +2471,30 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
2336
2471
  return stream;
2337
2472
  }
2338
2473
 
2474
+ // src/server/utils/merge-mixin-safely.util.ts
2475
+ var PROTOTYPE_KEY = "__proto__";
2476
+ var EXPLICIT_USER_KEY = "userId";
2477
+ function mergeMixinSafely(mergeObject, mixinObject) {
2478
+ try {
2479
+ const merged = {};
2480
+ for (const key of Object.keys(mergeObject)) {
2481
+ if (key !== PROTOTYPE_KEY) Reflect.set(merged, key, Reflect.get(mergeObject, key));
2482
+ }
2483
+ for (const [key, value] of Object.entries(mixinObject)) {
2484
+ if (value === void 0) continue;
2485
+ if (key === EXPLICIT_USER_KEY && Reflect.get(merged, key) !== void 0) continue;
2486
+ Reflect.set(merged, key, value);
2487
+ }
2488
+ return merged;
2489
+ } catch {
2490
+ return {
2491
+ ...mixinObject,
2492
+ _redactionFailed: true,
2493
+ _logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
2494
+ };
2495
+ }
2496
+ }
2497
+
2339
2498
  // src/server/utils/censor-raw-headers.util.ts
2340
2499
  function censorRawHeaders(raw, sensitive, censor) {
2341
2500
  return raw.map((entry, index) => {
@@ -2987,16 +3146,10 @@ function buildSerializers(options, redactSerialized, ownFields) {
2987
3146
  )
2988
3147
  };
2989
3148
  }
2990
- function mergeMixinSafely(mergeObject, mixinObject) {
2991
- try {
2992
- return Object.assign({}, mixinObject, mergeObject);
2993
- } catch {
2994
- return {
2995
- ...mixinObject,
2996
- _redactionFailed: true,
2997
- _logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
2998
- };
2999
- }
3149
+ function withEntryTextFinisher(logger, options) {
3150
+ const redact = buildNameRedactor(options);
3151
+ Reflect.set(logger, ENTRY_TEXT_FINISHER, createEntryTextFinisher(redact, options.maxStringLength));
3152
+ return logger;
3000
3153
  }
3001
3154
  function buildStreams(options, destinations, health) {
3002
3155
  return destinations.map((destination) => {
@@ -3050,6 +3203,9 @@ function buildFormatters(options, redactRecord, redactBindings) {
3050
3203
  };
3051
3204
  }
3052
3205
  function buildPinoInstance(options, logContext, destinations, health) {
3206
+ if (options.maxStringLength !== void 0) {
3207
+ refuseCensorBeyondLimit(options.redactCensor, options.maxStringLength);
3208
+ }
3053
3209
  const redactRecord = resolveRecordRedactor(options);
3054
3210
  const redactSerialized = buildNameRedactor(options);
3055
3211
  const ownFields = ownFieldPolicyOf(options);
@@ -3075,7 +3231,8 @@ function buildPinoInstance(options, logContext, destinations, health) {
3075
3231
  mixin: createTraceContextMixin(logContext, options.otel),
3076
3232
  mixinMergeStrategy: mergeMixinSafely
3077
3233
  };
3078
- return pino__default.default(pinoOptions, pino__default.default.multistream(buildStreams(options, destinations, health)));
3234
+ const streams = pino__default.default.multistream(buildStreams(options, destinations, health));
3235
+ return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options);
3079
3236
  }
3080
3237
  var DROP_REPORT_INTERVAL_MS = 1e4;
3081
3238
  function countInWindow(records, destination, now) {
@@ -4404,23 +4561,23 @@ var MAX_CODE_LENGTH = 128;
4404
4561
  function isCount(value) {
4405
4562
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
4406
4563
  }
4407
- function isRecord2(value) {
4564
+ function isRecord3(value) {
4408
4565
  return typeof value === "object" && value !== null;
4409
4566
  }
4410
4567
  function exceptionFields(error) {
4411
4568
  try {
4412
- if (!isRecord2(error) || typeof error["getResponse"] !== "function") return {};
4569
+ if (!isRecord3(error) || typeof error["getResponse"] !== "function") return {};
4413
4570
  const response = error["getResponse"]();
4414
- if (!isRecord2(response)) return {};
4571
+ if (!isRecord3(response)) return {};
4415
4572
  const nested = response["error"];
4416
- const carrier = isRecord2(nested) && typeof nested["code"] === "string" ? nested : response;
4573
+ const carrier = isRecord3(nested) && typeof nested["code"] === "string" ? nested : response;
4417
4574
  const fields = {};
4418
4575
  const code = carrier["code"];
4419
4576
  if (typeof code === "string") {
4420
4577
  fields["errorCode"] = code.slice(0, MAX_CODE_LENGTH);
4421
4578
  }
4422
4579
  const details = carrier["details"];
4423
- if (isRecord2(details)) {
4580
+ if (isRecord3(details)) {
4424
4581
  fields["errorDetails"] = details;
4425
4582
  }
4426
4583
  return fields;
@@ -1072,6 +1072,16 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
1072
1072
  /** Emit a structured payload at info or warn level. */
1073
1073
  private emitStructured;
1074
1074
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1075
+ private nestStyleMessage;
1076
+ /**
1077
+ * The entry text of an object message, censored under the names of the field it came from and cut
1078
+ * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
+ * value the pipeline censors or cuts in the field itself.
1080
+ *
1081
+ * @param text - The text and the member it came from.
1082
+ * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
+ */
1084
+ private censorText;
1075
1085
  private emitNestStyle;
1076
1086
  }
1077
1087
 
@@ -1072,6 +1072,16 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
1072
1072
  /** Emit a structured payload at info or warn level. */
1073
1073
  private emitStructured;
1074
1074
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1075
+ private nestStyleMessage;
1076
+ /**
1077
+ * The entry text of an object message, censored under the names of the field it came from and cut
1078
+ * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
+ * value the pipeline censors or cuts in the field itself.
1080
+ *
1081
+ * @param text - The text and the member it came from.
1082
+ * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
+ */
1084
+ private censorText;
1075
1085
  private emitNestStyle;
1076
1086
  }
1077
1087
 
@@ -22,6 +22,73 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
22
22
  var getFilename = () => fileURLToPath(import.meta.url);
23
23
  var __filename$1 = /* @__PURE__ */ getFilename();
24
24
 
25
+ // src/server/config/drop-unset-options.ts
26
+ var OPTION_KEYS = {
27
+ service: true,
28
+ level: true,
29
+ isGlobal: true,
30
+ shouldUseAsNestLogger: true,
31
+ redactPaths: true,
32
+ redactStrategy: true,
33
+ resourceFormat: true,
34
+ eventNameField: true,
35
+ errorFormat: true,
36
+ redactCensor: true,
37
+ shouldDisableDefaultRedact: true,
38
+ destinations: true,
39
+ http: true,
40
+ otel: true,
41
+ maxEntrySizeBytes: true,
42
+ maxStringLength: true,
43
+ destinationHookTimeoutMs: true,
44
+ shutdown: true,
45
+ destinationQueue: true,
46
+ errorOwnFields: true,
47
+ errorOwnFieldNames: true,
48
+ serializers: true,
49
+ timestamp: true
50
+ };
51
+ var GROUP_KEYS = {
52
+ http: {
53
+ isEnabled: true,
54
+ shouldCaptureExceptions: true,
55
+ shouldGenerateRequestId: true,
56
+ excludePaths: true,
57
+ secretPathSegments: true,
58
+ tenantIdHeader: true,
59
+ tenantIdResolver: true
60
+ },
61
+ otel: {
62
+ shouldAutoInjectTraceContext: true,
63
+ fieldFormat: true,
64
+ traceIdField: true,
65
+ spanIdField: true,
66
+ traceFlagsField: true
67
+ },
68
+ shutdown: { timeoutMs: true, drainTimeoutMs: true },
69
+ destinationQueue: { maxBytes: true }
70
+ };
71
+ var GROUP_NAMES = Object.keys(GROUP_KEYS);
72
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
73
+ function readSet(source, keys) {
74
+ const set = {};
75
+ for (const key of keys) {
76
+ const value = Reflect.get(source, key);
77
+ if (value !== void 0 && value !== null) Reflect.set(set, key, value);
78
+ }
79
+ return set;
80
+ }
81
+ function dropUnsetOptions(options) {
82
+ if (!isRecord(options)) return options;
83
+ const set = readSet(options, Object.keys(OPTION_KEYS));
84
+ for (const group of GROUP_NAMES) {
85
+ const value = Reflect.get(set, group);
86
+ if (isRecord(value))
87
+ Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
88
+ }
89
+ return set;
90
+ }
91
+
25
92
  // src/server/constants/lifecycle-timeouts.constants.ts
26
93
  var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
27
94
  var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
@@ -69,7 +136,8 @@ function applyOtelFieldFormat(merged, user) {
69
136
  }
70
137
  return merged;
71
138
  }
72
- function applyDefaults(options) {
139
+ function applyDefaults(given) {
140
+ const options = dropUnsetOptions(given);
73
141
  const isProduction = process.env["NODE_ENV"] === "production";
74
142
  const http = { ...DEFAULT_HTTP, ...options.http ?? {} };
75
143
  const otel = applyOtelFieldFormat(
@@ -141,8 +209,8 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
141
209
  ]);
142
210
 
143
211
  // src/server/config/validate-options.ts
144
- function reject(path2, rule, got) {
145
- const received = got === void 0 ? "" : `. Received ${describeValue(got)}`;
212
+ function reject(path2, rule, got, wasGiven = got !== void 0) {
213
+ const received = wasGiven ? `. Received ${describeValue(got)}` : "";
146
214
  throw new Error(`[BymaxLoggerModule] options.${path2} ${rule}${received}`);
147
215
  }
148
216
  function describeValue(value) {
@@ -159,12 +227,14 @@ function describeValue(value) {
159
227
  return "a symbol";
160
228
  case "function":
161
229
  return "a function";
230
+ case "undefined":
231
+ return "undefined";
162
232
  default:
163
233
  if (value === null) return "null";
164
234
  return Array.isArray(value) ? "an array" : "an object";
165
235
  }
166
236
  }
167
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
237
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
168
238
  var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
169
239
  function checkBoolean(path2, value) {
170
240
  if (value !== void 0 && typeof value !== "boolean") {
@@ -178,7 +248,7 @@ function checkNonEmptyString(path2, value) {
178
248
  }
179
249
  function checkGroup(path2, value) {
180
250
  if (value === void 0) return void 0;
181
- if (!isRecord(value)) reject(path2, "must be an object", value);
251
+ if (!isRecord2(value)) reject(path2, "must be an object", value);
182
252
  return value;
183
253
  }
184
254
  var MAX_TIMER_MS = 2147483647;
@@ -210,7 +280,9 @@ function validateStringLimit(options) {
210
280
  limit
211
281
  );
212
282
  }
213
- const censor = options.redactCensor;
283
+ refuseCensorBeyondLimit(options.redactCensor, limit);
284
+ }
285
+ function refuseCensorBeyondLimit(censor, limit) {
214
286
  if (typeof censor === "string" && censor.length > limit) {
215
287
  reject(
216
288
  "redactCensor",
@@ -239,7 +311,7 @@ function validateCore(options) {
239
311
  if (service === void 0) {
240
312
  throw new Error("[BymaxLoggerModule] options.service is required");
241
313
  }
242
- if (!isRecord(service)) reject("service", "must be an object", service);
314
+ if (!isRecord2(service)) reject("service", "must be an object", service);
243
315
  for (const field of ["name", "version"]) {
244
316
  const given = service[field];
245
317
  if (typeof given !== "string" || given.trim() === "") {
@@ -291,16 +363,16 @@ function validateCustomization(options) {
291
363
  if (!Array.isArray(paths)) reject("redactPaths", "must be an array of strings", paths);
292
364
  paths.forEach((entry, index) => {
293
365
  if (!isNonEmptyString(entry)) {
294
- reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry);
366
+ reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry, true);
295
367
  }
296
368
  });
297
369
  }
298
370
  const serializers = options.serializers;
299
371
  if (serializers !== void 0) {
300
- if (!isRecord(serializers)) reject("serializers", "must be an object", serializers);
301
- for (const [key, serializer] of Object.entries(serializers)) {
372
+ if (!isRecord2(serializers)) reject("serializers", "must be an object", serializers);
373
+ for (const serializer of Object.values(serializers)) {
302
374
  if (typeof serializer !== "function") {
303
- reject(`serializers.${key}`, "must be a function", serializer);
375
+ reject("serializers", "must map every serializer key to a function", serializer);
304
376
  }
305
377
  }
306
378
  }
@@ -315,7 +387,7 @@ function validateErrorFields(options) {
315
387
  if (!Array.isArray(names)) reject("errorOwnFieldNames", "must be an array of strings", names);
316
388
  names.forEach((entry, index) => {
317
389
  if (!isNonEmptyString(entry)) {
318
- reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry);
390
+ reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry, true);
319
391
  }
320
392
  });
321
393
  }
@@ -329,8 +401,8 @@ function readMember(destination, key) {
329
401
  }
330
402
  function validateDestination(entry, index) {
331
403
  const path2 = `destinations[${String(index)}]`;
332
- if (!isRecord(entry)) {
333
- reject(path2, "must be an object implementing ILogDestination", entry);
404
+ if (!isRecord2(entry)) {
405
+ reject(path2, "must be an object implementing ILogDestination", entry, true);
334
406
  }
335
407
  const write = readMember(entry, "write");
336
408
  if (write !== UNREADABLE && typeof write !== "function") {
@@ -362,7 +434,7 @@ function checkRegExpList(path2, value) {
362
434
  }
363
435
  value.forEach((pattern, index) => {
364
436
  if (!types.isRegExp(pattern)) {
365
- reject(`${path2}[${String(index)}]`, "must be a RegExp", pattern);
437
+ reject(`${path2}[${String(index)}]`, "must be a RegExp", pattern, true);
366
438
  }
367
439
  });
368
440
  }
@@ -395,7 +467,8 @@ function validateOtel(options) {
395
467
  checkNonEmptyString("otel.spanIdField", otel["spanIdField"]);
396
468
  checkNonEmptyString("otel.traceFlagsField", otel["traceFlagsField"]);
397
469
  }
398
- function validateOptions(options) {
470
+ function validateOptions(given) {
471
+ const options = dropUnsetOptions(given);
399
472
  validateCore(options);
400
473
  validateClosedSets(options);
401
474
  validateCustomization(options);
@@ -472,6 +545,20 @@ function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
472
545
  return whole + TEXT_TRUNCATED;
473
546
  }
474
547
 
548
+ // src/server/utils/entry-text-finisher.util.ts
549
+ var ENTRY_TEXT_FINISHER = /* @__PURE__ */ Symbol("bymax.entryTextFinisher");
550
+ function createEntryTextFinisher(redact, limit) {
551
+ return (key, text) => {
552
+ try {
553
+ const censored = Reflect.get(redact({ [key]: text }, true), key);
554
+ if (typeof censored !== "string") return "";
555
+ return limit === void 0 ? censored : cutText(censored, false, limit);
556
+ } catch {
557
+ return "";
558
+ }
559
+ };
560
+ }
561
+
475
562
  // src/server/utils/escape-log-text.util.ts
476
563
  var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
477
564
  var UNSAFE_IN_SINGLE_LINE = /[\u0000-\u0008\u000A-\u001F\u007F-\u009F\u2028\u2029]/g;
@@ -491,6 +578,16 @@ function toBoundedMessage(text) {
491
578
  function escapeControlCharacters(text) {
492
579
  return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
493
580
  }
581
+
582
+ // src/server/utils/is-plain-record.util.ts
583
+ function isPlainRecord(node) {
584
+ try {
585
+ const prototype = Object.getPrototypeOf(node);
586
+ return prototype === Object.prototype || prototype === null;
587
+ } catch {
588
+ return false;
589
+ }
590
+ }
494
591
  function isError(value) {
495
592
  try {
496
593
  return types.isNativeError(value) || value instanceof Error;
@@ -687,14 +784,22 @@ function createWidthMarker(omitted) {
687
784
 
688
785
  // src/server/services/pino-logger.service.ts
689
786
  var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
690
- function withoutOwnedKeys(metadata) {
787
+ var ENTRY_STRUCTURE_KEYS = /* @__PURE__ */ new Set([
788
+ "level",
789
+ "time",
790
+ "msg",
791
+ "service",
792
+ "deployment"
793
+ ]);
794
+ var isEntryStructureKey = (key) => ENTRY_STRUCTURE_KEYS.has(key) || key.startsWith("service.") || key.startsWith("deployment.");
795
+ function withoutOwnedKeys(metadata, omit) {
691
796
  if (metadata === void 0) {
692
797
  return {};
693
798
  }
694
799
  try {
695
800
  const safe = {};
696
801
  for (const key of Object.keys(metadata)) {
697
- if (!OWNED_PAYLOAD_KEYS.includes(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
802
+ if (key !== omit && !OWNED_PAYLOAD_KEYS.includes(key) && !isEntryStructureKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
698
803
  Reflect.set(safe, key, Reflect.get(metadata, key));
699
804
  }
700
805
  }
@@ -713,6 +818,23 @@ function safeErrorMessage(error) {
713
818
  return "Unreadable error message";
714
819
  }
715
820
  }
821
+ function objectMessageText(fields) {
822
+ for (const key of ["message", "event"]) {
823
+ try {
824
+ const value = Reflect.get(fields, key);
825
+ if (typeof value === "string") return { key, text: value };
826
+ } catch {
827
+ }
828
+ }
829
+ return void 0;
830
+ }
831
+ function readObjectMessage(message) {
832
+ const fields = isPlainRecord(message) && !isErrorLike(message) ? message : void 0;
833
+ const text = fields === void 0 ? void 0 : objectMessageText(fields);
834
+ const omit = text?.key === "message" ? "message" : void 0;
835
+ const payload = withoutOwnedKeys(fields, omit);
836
+ return { fields, text, payload };
837
+ }
716
838
  function safeLogMessage(message) {
717
839
  try {
718
840
  return toBoundedMessage(typeof message === "string" ? message : String(message));
@@ -787,11 +909,11 @@ var PinoLoggerService = class {
787
909
  }
788
910
  const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
789
911
  const context = typeof optionalParams[1] === "string" ? optionalParams[1] : this.context;
790
- const payload = {};
912
+ const { fields, text, payload } = readObjectMessage(message);
791
913
  assignIfDefined(payload, "context", context);
792
914
  assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
793
915
  assignIfDefined(payload, "err", findErrorParam(optionalParams));
794
- this.pino.error(payload, safeLogMessage(message));
916
+ this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
795
917
  }
796
918
  /**
797
919
  * NestJS `warn` (warn level).
@@ -943,12 +1065,30 @@ var PinoLoggerService = class {
943
1065
  }
944
1066
  }
945
1067
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1068
+ nestStyleMessage(leading, fields, text, message) {
1069
+ if (leading !== void 0) return safeErrorMessage(leading);
1070
+ if (fields !== void 0) return toBoundedMessage(this.censorText(text));
1071
+ return safeLogMessage(message);
1072
+ }
1073
+ /**
1074
+ * The entry text of an object message, censored under the names of the field it came from and cut
1075
+ * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1076
+ * value the pipeline censors or cuts in the field itself.
1077
+ *
1078
+ * @param text - The text and the member it came from.
1079
+ * @returns The censored text, or an empty one when the redactor cannot be applied.
1080
+ */
1081
+ censorText(text) {
1082
+ if (text === void 0) return "";
1083
+ const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
1084
+ return finish(text.key, text.text);
1085
+ }
946
1086
  emitNestStyle(level, message, optionalParams) {
947
- const payload = {};
1087
+ const { fields, text, payload } = readObjectMessage(message);
948
1088
  assignIfDefined(payload, "context", this.resolveContext(optionalParams));
949
1089
  const leading = isErrorLike(message) ? message : void 0;
950
1090
  assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
951
- const msg = leading === void 0 ? safeLogMessage(message) : safeErrorMessage(leading);
1091
+ const msg = this.nestStyleMessage(leading, fields, text, message);
952
1092
  switch (level) {
953
1093
  case "info":
954
1094
  this.pino.info(payload, msg);
@@ -2173,11 +2313,6 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
2173
2313
  }
2174
2314
 
2175
2315
  // src/server/utils/cut-strings.util.ts
2176
- function isPlainRecord(node) {
2177
- if (node === null || typeof node !== "object") return false;
2178
- const prototype = Object.getPrototypeOf(node);
2179
- return prototype === Object.prototype || prototype === null;
2180
- }
2181
2316
  function cutNode(node, limit) {
2182
2317
  if (typeof node === "string") return cutText(node, false, limit);
2183
2318
  if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
@@ -2333,6 +2468,30 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
2333
2468
  return stream;
2334
2469
  }
2335
2470
 
2471
+ // src/server/utils/merge-mixin-safely.util.ts
2472
+ var PROTOTYPE_KEY = "__proto__";
2473
+ var EXPLICIT_USER_KEY = "userId";
2474
+ function mergeMixinSafely(mergeObject, mixinObject) {
2475
+ try {
2476
+ const merged = {};
2477
+ for (const key of Object.keys(mergeObject)) {
2478
+ if (key !== PROTOTYPE_KEY) Reflect.set(merged, key, Reflect.get(mergeObject, key));
2479
+ }
2480
+ for (const [key, value] of Object.entries(mixinObject)) {
2481
+ if (value === void 0) continue;
2482
+ if (key === EXPLICIT_USER_KEY && Reflect.get(merged, key) !== void 0) continue;
2483
+ Reflect.set(merged, key, value);
2484
+ }
2485
+ return merged;
2486
+ } catch {
2487
+ return {
2488
+ ...mixinObject,
2489
+ _redactionFailed: true,
2490
+ _logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
2491
+ };
2492
+ }
2493
+ }
2494
+
2336
2495
  // src/server/utils/censor-raw-headers.util.ts
2337
2496
  function censorRawHeaders(raw, sensitive, censor) {
2338
2497
  return raw.map((entry, index) => {
@@ -2984,16 +3143,10 @@ function buildSerializers(options, redactSerialized, ownFields) {
2984
3143
  )
2985
3144
  };
2986
3145
  }
2987
- function mergeMixinSafely(mergeObject, mixinObject) {
2988
- try {
2989
- return Object.assign({}, mixinObject, mergeObject);
2990
- } catch {
2991
- return {
2992
- ...mixinObject,
2993
- _redactionFailed: true,
2994
- _logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
2995
- };
2996
- }
3146
+ function withEntryTextFinisher(logger, options) {
3147
+ const redact = buildNameRedactor(options);
3148
+ Reflect.set(logger, ENTRY_TEXT_FINISHER, createEntryTextFinisher(redact, options.maxStringLength));
3149
+ return logger;
2997
3150
  }
2998
3151
  function buildStreams(options, destinations, health) {
2999
3152
  return destinations.map((destination) => {
@@ -3047,6 +3200,9 @@ function buildFormatters(options, redactRecord, redactBindings) {
3047
3200
  };
3048
3201
  }
3049
3202
  function buildPinoInstance(options, logContext, destinations, health) {
3203
+ if (options.maxStringLength !== void 0) {
3204
+ refuseCensorBeyondLimit(options.redactCensor, options.maxStringLength);
3205
+ }
3050
3206
  const redactRecord = resolveRecordRedactor(options);
3051
3207
  const redactSerialized = buildNameRedactor(options);
3052
3208
  const ownFields = ownFieldPolicyOf(options);
@@ -3072,7 +3228,8 @@ function buildPinoInstance(options, logContext, destinations, health) {
3072
3228
  mixin: createTraceContextMixin(logContext, options.otel),
3073
3229
  mixinMergeStrategy: mergeMixinSafely
3074
3230
  };
3075
- return pino(pinoOptions, pino.multistream(buildStreams(options, destinations, health)));
3231
+ const streams = pino.multistream(buildStreams(options, destinations, health));
3232
+ return withEntryTextFinisher(pino(pinoOptions, streams), options);
3076
3233
  }
3077
3234
  var DROP_REPORT_INTERVAL_MS = 1e4;
3078
3235
  function countInWindow(records, destination, now) {
@@ -4401,23 +4558,23 @@ var MAX_CODE_LENGTH = 128;
4401
4558
  function isCount(value) {
4402
4559
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
4403
4560
  }
4404
- function isRecord2(value) {
4561
+ function isRecord3(value) {
4405
4562
  return typeof value === "object" && value !== null;
4406
4563
  }
4407
4564
  function exceptionFields(error) {
4408
4565
  try {
4409
- if (!isRecord2(error) || typeof error["getResponse"] !== "function") return {};
4566
+ if (!isRecord3(error) || typeof error["getResponse"] !== "function") return {};
4410
4567
  const response = error["getResponse"]();
4411
- if (!isRecord2(response)) return {};
4568
+ if (!isRecord3(response)) return {};
4412
4569
  const nested = response["error"];
4413
- const carrier = isRecord2(nested) && typeof nested["code"] === "string" ? nested : response;
4570
+ const carrier = isRecord3(nested) && typeof nested["code"] === "string" ? nested : response;
4414
4571
  const fields = {};
4415
4572
  const code = carrier["code"];
4416
4573
  if (typeof code === "string") {
4417
4574
  fields["errorCode"] = code.slice(0, MAX_CODE_LENGTH);
4418
4575
  }
4419
4576
  const details = carrier["details"];
4420
- if (isRecord2(details)) {
4577
+ if (isRecord3(details)) {
4421
4578
  fields["errorDetails"] = details;
4422
4579
  }
4423
4580
  return fields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-logger",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
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",