@bymax-one/nest-logger 1.4.21 → 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,160 @@ 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
+
90
+ ## [1.4.22] - 2026-11-17
91
+
92
+ ### Breaking
93
+
94
+ - **`maxEntrySizeBytes` is at most 2147483647.** A value such as `2 ** 53` or `1e300` was accepted
95
+ and could never be reached by an entry. `forRoot` now rejects it with
96
+ `options.maxEntrySizeBytes must be at most 2147483647`.
97
+ **Apply:** pass a ceiling of at most 2147483647 bytes; the default and every value up to that are
98
+ unaffected.
99
+
100
+ - **A `maxStringLength` outside 64 to 2147483647 is refused.** 1.4.21 did not read an option of that
101
+ name, so a key `maxStringLength` was ignored whatever it held. It is validated at startup now
102
+ (`options.maxStringLength must be an integer from 64 to 2147483647`), and a value such as `10`,
103
+ `64.5` or `'100'` stops the application from starting. **Apply:** remove the key, or give a whole
104
+ number of characters from 64 up to 2147483647.
105
+
106
+ ### Added
107
+
108
+ - **`maxStringLength` bounds the length of every string of a log record.** A string under a metadata
109
+ key is the caller's own data and was written as given, so one value of a megabyte made an entry of
110
+ a megabyte. With `maxStringLength` set, a string longer than the limit is cut to that many
111
+ characters (a cut never splits a surrogate pair) and ends with `…[truncated]`. It is an integer
112
+ from 64 to 2147483647 and it is off until set. The cut runs after
113
+ every redaction rule and before the event name and the exception fields are written, so it cannot
114
+ cut a string before a rule that needs the whole of it.
115
+ It applies at any depth, and not to a key, a value that is not text, the log message, the
116
+ `logKey`, the bindings of a logger, or anything under a key that has a serializer (`err` and the
117
+ keys of `serializers`). The event name and the `exception.*` and `error.type` fields the library
118
+ writes are added after the cut, so the limit does not apply to them, and the exception fields among them keep the cap of
119
+ 16384 characters they had in 1.4.21. An `Error` placed in the metadata under any
120
+ other key is data of the record when the cut runs, and its message and stack are cut like any
121
+ other string. The names left whole are matched on the root key, so a key of your own named like a
122
+ serializer key is left whole too. A `userId` longer than the
123
+ limit is cut like any other string. A `redactCensor` longer than the limit is refused at startup,
124
+ so a censor is never cut. Setting the option makes the record walk run even when no field name is
125
+ covered (`shouldDisableDefaultRedact: true` and no `redactPaths`), and the walk writes a boxed
126
+ `String` or `Number`, a `Buffer`, a `Uint8Array` and an `Error` in the metadata as the default
127
+ redaction already does: a two-byte `Buffer` is written as `[Binary 2 bytes]` and not as
128
+ `{"type":"Buffer","data":[104,105]}`, while a boxed `Number` is written as `{}` and a boxed
129
+ `String` as a map of its indexes (`{"0":"a","1":"b","2":"c"}` for `new String('abc')`), as the
130
+ default redaction writes them.
131
+
132
+ ### Changed
133
+
134
+ - **The steps of `PrettyDevDestination.onInit` are module functions, not methods.** 1.4.21 split
135
+ `onInit` into the private methods `refuseInProduction`, `buildTransform` and `initFailure`, which
136
+ `onInit` called through `this`. A subclass written without the type check, as JavaScript is, that
137
+ defined a member with one of those names had it called in the place of the step. The steps are now
138
+ functions of the module, so no member of any name replaces them, and the three declarations leave
139
+ the `.d.ts`. Behavior is otherwise unchanged.
140
+
141
+ - **A refused option names the type of the value it received and never quotes it.** The message
142
+ used to end in `Got: "3"` for a string and in `String(value)` for a number, a boolean, a bigint or a
143
+ Symbol, so a token typed into the wrong field, or a Symbol with a description, reached the bootstrap
144
+ log. It now ends in
145
+ `Received a string`, `Received a symbol`, `Received an object` and so on, and prints a value only
146
+ when it is a finite number (`Received the number 63`). The refusals that bypassed the shared path
147
+ and printed `String(value)` (`level`, `redactStrategy`, `resourceFormat`, `errorFormat` and
148
+ `eventNameField`) go through it too. A `service` that is not an object, including `null`, `0`,
149
+ `false`, `''` and `NaN`, is now refused as `options.service must be an object. Received …`:
150
+ 1.4.21 said `options.service is required` for a falsy one and blamed `service.name` or `service.version` for any other,
151
+ and only an undefined `service` keeps `options.service is required`. **Apply:** code that matches
152
+ the text `Got:` of a refusal matches `Received` instead; apart from that and `service`, the
153
+ option's name and the rule are unchanged. Three refusals had no suffix at
154
+ all (a `service.name` or `service.version` that is not a non-empty string, and a
155
+ `maxEntrySizeBytes` of 0 or less) and now end in `Received <type>` too, so an exact match on their
156
+ whole text changes as well; a missing `service.name` or `service.version` still has no suffix.
157
+
158
+ #### Apply to a derived backend
159
+
160
+ `PrettyDevDestination`: nothing is required. A subclass that defines a member named
161
+ `refuseInProduction`, `buildTransform` or `initFailure` keeps it, and `onInit` no longer calls it.
162
+
163
+ `maxStringLength`: a configuration that already passes that key with a value outside 64 to
164
+ 2147483647 must change it, because it is refused now (see the Breaking entry above); otherwise
165
+ nothing is required, since the option is off until set. `ResolvedBymaxLoggerModuleOptions` gains the key `maxStringLength: number | undefined`, so a derived
166
+ backend that builds that object itself adds `maxStringLength: undefined`; one that spreads the
167
+ result of `applyDefaults` already has it.
168
+
15
169
  ## [1.4.21] - 2026-11-17
16
170
 
17
171
  ### Breaking
@@ -2941,7 +3095,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
2941
3095
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
2942
3096
  `release.yml`, Dependabot, and issue templates
2943
3097
 
2944
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...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
3100
+ [1.4.22]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...v1.4.22
2945
3101
  [1.4.21]: https://github.com/bymaxone/nest-logger/compare/v1.4.20...v1.4.21
2946
3102
  [1.4.20]: https://github.com/bymaxone/nest-logger/compare/v1.4.19...v1.4.20
2947
3103
  [1.4.19]: https://github.com/bymaxone/nest-logger/compare/v1.4.18...v1.4.19
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 |
@@ -267,7 +269,8 @@ Full options reference for `BymaxLoggerModule.forRoot(options)`:
267
269
  | `redactStrategy` | `'names' \| 'paths'` | `'names'` | Engine behind the DEFAULT set. `'paths'` is the legacy `fast-redact` expansion (four-level ceiling, much slower) |
268
270
  | `shouldDisableDefaultRedact` | `boolean` | `false` | Skip the default PII coverage entirely. ⚠️ Emits `LOGGER_BOOTSTRAP_WARNING` at startup — document why |
269
271
  | `redactCensor` | `string` | `'[REDACTED]'` | Replacement value written in place of every redacted field |
270
- | `maxEntrySizeBytes` | `number` | `65536` | UTF-8 byte ceiling per serialized field, a whole number (`err` + any custom serializer); over it the value becomes a truncation envelope |
272
+ | `maxEntrySizeBytes` | `number` | `65536` | UTF-8 byte ceiling per serialized field, a whole number from 1 to 2147483647 (`err` + any custom serializer); over it the value becomes a truncation envelope |
273
+ | `maxStringLength` | `number` | unset (a string is written whole) | The most characters a string of a log record is written with: an integer from 64 to 2147483647. A longer string is cut to that length and ends with `…[truncated]`. See [Bounded string length](#bounded-string-length) |
271
274
  | `destinationHookTimeoutMs` | `number` | `10000` | Longest `onInit` or `onRegistryReady` of a destination, in ms (an integer from 1 to 2147483647). An `onInit` that does not settle in time counts as one that threw: the destination is failed, skipped and reported, and stays inactive if the call settles later. A hung `onInit` may leak what it opened |
272
275
  | `errorOwnFields` | `'all' \| 'safe'` | `'all'` | Which own fields of an error are written. `'all'` writes every one; `'safe'` writes an allow-list of operational names plus `errorOwnFieldNames` (see [Error fields](#error-fields)). A binary value is written as its size in both. Recommended: `'safe'` |
273
276
  | `errorOwnFieldNames` | `readonly string[]` | `[]` | Own-field names `'safe'` writes beside its default list, matched exactly; ignored under `'all'` |
@@ -907,6 +910,12 @@ An interpolated value has no name, so no configuration can redact it. **A value
907
910
 
908
911
  Every serializer, the default `err` one and any you supply, is wrapped so a field whose serialized JSON exceeds `maxEntrySizeBytes` (64 KB by default) is replaced by an envelope with `_truncated`, `_logKey: 'LOGGER_ENTRY_TRUNCATED'`, `_originalSize` and a 200-character `_preview`.
909
912
 
913
+ ### Bounded string length
914
+
915
+ `maxEntrySizeBytes` bounds what a serializer returns, and a string under a metadata key is the caller's own data, written as given. `maxStringLength` bounds that string too, and is off until set. A string longer than the limit is cut to that many characters (UTF-16 units, so a cut never splits a surrogate pair) and ends with `…[truncated]`; what is written is the limit plus 12 characters at most, and a string of exactly the limit is written whole.
916
+
917
+ It applies to every string value of the record at any depth, in an object or an array, after redaction: a value a redaction rule censors is the censor and not a cut text. It does not apply to a key, to a value that is not text, to the log message (already capped at 16384 characters), to the `logKey` of the entry (an identifier, and `event.name` is derived from it), to the bindings of a logger (the service identity and the `context` of an `@InjectLogger` logger are written once, whole), to anything under a key that has a serializer (`err` and the keys of `serializers`): this limit does not cut the error you log under `err`, and `maxEntrySizeBytes` caps what a serializer returns when that output serializes to JSON. The event name and the `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` fields written from an error are added after the cut, so the limit does not apply to them, and the exception fields among them keep the cap of 16384 characters they had in 1.4.21, and a key of your own with one of those names is cut like any other string. The names left whole are matched on the root key, so a key of your own named like a key of `serializers` is left whole too. An `Error` placed in the metadata under any other key is data of the record when the cut runs, so its message, its stack and its own fields are cut like any other string. The limit is an integer from 64, because the strings the library writes into a record itself (trace and span ids) are shorter than that. A string the caller supplies, such as a `userId`, a `tenantId`, or a `requestId` taken from an inbound request header, is cut like any other when it is longer than the limit. Setting it makes the record walk run even when no field name is covered (`shouldDisableDefaultRedact: true` and no `redactPaths`), and the walk writes a boxed `String` or `Number`, a `Buffer`, a `Uint8Array` and an `Error` in the metadata as the default redaction already does: a two-byte `Buffer` is written as `[Binary 2 bytes]` and not as `{"type":"Buffer","data":[104,105]}`, while a boxed `Number` is written as `{}` and a boxed `String` as a map of its indexes (`{"0":"a","1":"b","2":"c"}` for `new String('abc')`), as the default redaction writes them. A `redactCensor` longer than the limit is refused at startup, because a censor the cut shortened would no longer be the text you look for in place of a secret.
918
+
910
919
  ### Security Checklist
911
920
 
912
921
  - `shouldDisableDefaultRedact` stays `false`; if it is on, the `LOGGER_BOOTSTRAP_WARNING` must be justified in a security review.
@@ -982,7 +991,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
982
991
  | `warnStructured` | `(logKey, msg, userId?, meta?)` | Structured warn log — takes a **message string** |
983
992
  | `errorStructured` | `(logKey, error, userId?, meta?)` | Structured error log — takes an **`Error`**, serialized to `err` |
984
993
 
985
- `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.
986
995
 
987
996
  **NestJS `LoggerService` bridge** — the variadic contract NestJS calls, so `app.useLogger()` works. These take a message, not a log key.
988
997
 
@@ -995,13 +1004,15 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
995
1004
  | `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
996
1005
  | `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
997
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
+
998
1009
  **Helpers**
999
1010
 
1000
1011
  | Method | Signature | Notes |
1001
1012
  | -------------- | ------------ | ----------------------------------------------------------------- |
1002
1013
  | `child` | `(bindings)` | New `PinoLoggerService` over a Pino child logger |
1003
1014
  | `setContext` | `(context)` | Global label — ⚠️ singleton; prefer `@InjectLogger(MyClass.name)` |
1004
- | `getRawLogger` | `()` | The underlying Pino instance |
1015
+ | `getRawLogger` | `()` | The underlying Pino instance; bypasses the `meta` guards above |
1005
1016
 
1006
1017
  > [!NOTE]
1007
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.