@bymax-one/nest-logger 1.4.23 → 1.4.25
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 +220 -1
- package/README.md +158 -58
- package/dist/observability/index.cjs +112 -0
- package/dist/observability/index.d.cts +55 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.mjs +110 -0
- package/dist/server/index.cjs +416 -149
- package/dist/server/index.d.cts +82 -4
- package/dist/server/index.d.ts +82 -4
- package/dist/server/index.mjs +416 -150
- package/dist/shared/index.cjs +1 -0
- package/dist/shared/index.d.cts +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.mjs +1 -0
- package/package.json +24 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,223 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.25] - 2026-11-20
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **The name of an error is censored when it is text.** `err.type`, the stack header, `exception.type`
|
|
20
|
+
and `error.type` wrote the `name` of an error as it was, so a value placed in `e.name` was written
|
|
21
|
+
next to a `message` the options hid. A name that reads as a name (identifier-shaped, at most 64
|
|
22
|
+
characters: `TypeError`, `pg.DatabaseError`, `E_TIMEOUT`) is kept, so the types an alert groups by do
|
|
23
|
+
not change; any other passes the censor of the `message` of an entry. A secret written as a short
|
|
24
|
+
identifier in the name is not found by its shape: that is the limit, and a value belongs in a field
|
|
25
|
+
whose name `redactPaths` covers. The line a failed destination writes follows the same rule.
|
|
26
|
+
- **The message of an error-shaped object is hidden in its stack under `redactStrategy: 'names'`.**
|
|
27
|
+
`logger.error({ name, message, stack })` wrote `message` censored and kept it in the first line of
|
|
28
|
+
`err.stack`. The walk of the record now leaves the `message` of that object to the serializer of
|
|
29
|
+
`err`, which censors it in the stack header, while a `stack` that `redactPaths` names is still
|
|
30
|
+
hidden whole, in every field derived from it. A host that serializes `err` itself still receives
|
|
31
|
+
the censored message.
|
|
32
|
+
- **`exception.stacktrace` is hidden as `err.stack` is.** With `errorFormat: 'semconv'` or `'both'`, a
|
|
33
|
+
`stack` that `redactPaths` names hid `err.stack` and left the full stack in `exception.stacktrace`.
|
|
34
|
+
It is now the censor there too. The field is written for what `err` is written for, a value whose
|
|
35
|
+
`name` and `message` are text: an object with no `name`, or with no `message`, gets no
|
|
36
|
+
`exception.stacktrace`, as it gets no `err.stack`, and the secret in its first line no longer
|
|
37
|
+
reaches the field.
|
|
38
|
+
- **More spellings of a key the logger writes are dropped.** The comparison reads through white
|
|
39
|
+
space, characters that print as nothing (zero-width, soft hyphen, byte order mark), the
|
|
40
|
+
compatibility forms Unicode defines (`RequestId`, `ſpan_id`, `TRACEİD`) and a short list of Cyrillic
|
|
41
|
+
and Greek letters drawn like a Latin one (`rеquestId`), and `service_name`, `service-version`,
|
|
42
|
+
`service.instance_id` and `deployment_environment_name` are the dotted resource keys. A key such
|
|
43
|
+
as `service_tier` or `services` is still yours. A letter of
|
|
44
|
+
another script that looks like a Latin one and is not on the list is kept: the list is not every
|
|
45
|
+
lookalike Unicode has.
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- **The README states what an object message costs.** It said about 1.8 times a string line. Measured
|
|
50
|
+
on the shipped build, three runs of 200,000 calls: a string line 1.2 µs, a structured call with
|
|
51
|
+
`meta` 3.9 µs, an object message 3.3 to 3.8 µs, which is 2.8 to 3.1 times the string line and the
|
|
52
|
+
same work as `meta`. The code did not get faster or slower for this: the sentence did. Where the
|
|
53
|
+
cost goes: an object message is walked as a structured call is (the owned keys are compared with
|
|
54
|
+
the payload, the fields are redacted and the text of the entry is finished), so it costs what the
|
|
55
|
+
same call with `meta` costs. It is not cut because the extra work over
|
|
56
|
+
a string line is the work that hides a value and drops a forged key.
|
|
57
|
+
|
|
58
|
+
### Documentation
|
|
59
|
+
|
|
60
|
+
- The README states the contract of `timestamp` (the value is converted with `String()` and written as
|
|
61
|
+
the JSON string `time`; a function that throws makes the log call throw), says that `OTEL_SERVICE_NAME`
|
|
62
|
+
and the name and version of `OTEL_RESOURCE_ATTRIBUTES` never apply to the required `service.name` and
|
|
63
|
+
`service.version`, describes what `LoggableRequest` and `LoggableResponse` carry and where the `userId`
|
|
64
|
+
of an HTTP entry comes from, adds a table of the application helpers (`useNestLogger`,
|
|
65
|
+
`useRequestContext`, `applyAccessLog`, `applyRequestIdMiddleware`) with when to call each and what
|
|
66
|
+
fails or stays silent, says what the log key regex accepts and that the library does not check a key
|
|
67
|
+
at run time, and states what the health indicator needs and where its `down` stops.
|
|
68
|
+
|
|
69
|
+
### Documented limits
|
|
70
|
+
|
|
71
|
+
- `logger.error('text ' + secret, error.stack)` (the NestJS `(message, stack)` form) writes both
|
|
72
|
+
strings as given: a string is never read for a value, and a stack string is not an `Error`.
|
|
73
|
+
- Under `redactStrategy: 'paths'`, an `Error` held under a key of your own (`{ error: new Error(x) }`)
|
|
74
|
+
is data of the record and is matched by the paths you wrote; its `message` and `stack` are hidden
|
|
75
|
+
only when a path names them.
|
|
76
|
+
- An error name longer than 16,384 characters is cut to that length before it is read, and the stack
|
|
77
|
+
header keeps the first 16,384 characters of it as written, while `err.name` and `err.type` are
|
|
78
|
+
censored. Keep a value out of a name of that length by putting it in a field that `redactPaths` covers.
|
|
79
|
+
|
|
80
|
+
## [1.4.24] - 2026-11-18
|
|
81
|
+
|
|
82
|
+
### Breaking
|
|
83
|
+
|
|
84
|
+
- **A key that only spells a key the logger writes is dropped, like the key itself.** 1.4.23 dropped
|
|
85
|
+
the owned keys and let the logger's value win over a payload key of the same name, but a payload key
|
|
86
|
+
that spelled one differently was written beside it: `trace_id`, `trace.id` or `TraceId` next to
|
|
87
|
+
`traceId`, `request_id` or `request.id` next to `requestId`, `Level` or `log_key` next to `level`
|
|
88
|
+
or `logKey`. A backend that normalises field names reads those as the same field, so a line could
|
|
89
|
+
still be attributed to another request or trace. The case and the separators `_`, `.` and `-` are
|
|
90
|
+
now folded when names are compared, and a spelling of an owned key is dropped from `meta` and from
|
|
91
|
+
an object message, and a spelling of a key the request context or the active span writes on that
|
|
92
|
+
call is dropped from the payload of `meta`, of an object message and of the raw Pino logger. A key
|
|
93
|
+
that is not a spelling of one (`trace_ids`, `levels`, `my_trace`) is kept, and outside a request or
|
|
94
|
+
a span, where the logger writes no such key, a `request_id` is the payload's own field. **Apply:**
|
|
95
|
+
nothing is required; search the `meta` of your calls and your object messages for a field whose
|
|
96
|
+
name, with the case and the `_`, `.` and `-` removed, is `level`, `time`, `msg`, `service`,
|
|
97
|
+
`deployment`, `logkey`, `userid` or `context`, or that starts with `service.` or `deployment.` in
|
|
98
|
+
any case (`Level`, `time_`, `log_key`, `Context`, `user_id`, `user.id`, `Service.x`): it is no
|
|
99
|
+
longer written on any call. Inside a request or a span the same holds, in `meta`, in an object
|
|
100
|
+
message and in the payload of the raw Pino logger, for the spellings of the keys the logger writes
|
|
101
|
+
there (`request_id`, `tenant_id`). Rename those fields (`severity`, `elapsedMs`,
|
|
102
|
+
`legacyRequestId`, `legacyUserId`).
|
|
103
|
+
|
|
104
|
+
- **The lines the library writes about its destinations are library text, with the error of the host
|
|
105
|
+
in `err`, and that error's message is censored.** The lines of `LOGGER_DESTINATION_WRITE_FAILED`
|
|
106
|
+
and `LOGGER_DESTINATION_INIT_FAILED` (a failed `onInit`, a failed `onRegistryReady`) put the name
|
|
107
|
+
of the destination in their `msg`, for example
|
|
108
|
+
`Log destination "audit" failed to write; the entry was dropped`. `msg` is now library text with
|
|
109
|
+
no name in it (for a write, `A log destination failed to write; the entry was dropped`) and the
|
|
110
|
+
name is in `destination` alone. A failed `onShutdown` was
|
|
111
|
+
written as a text line,
|
|
112
|
+
`[DestinationRegistry] Shutdown failed for "audit": <the stack of the error>`, which put the whole
|
|
113
|
+
stack of a host error on stderr outside any censor. It is now a JSON line like the others, under a
|
|
114
|
+
new reserved key, `LOGGER_DESTINATION_SHUTDOWN_FAILED`, with `destination`, `err` and a constant
|
|
115
|
+
`msg`, and its stack is not written. The message of the error in `err` of these lines, of
|
|
116
|
+
`HTTP_UNEXPECTED_ERROR_DROPPED` and of `LOGGER_OTEL_API_BROKEN` was bounded and escaped only; it
|
|
117
|
+
now also passes the censor of the message of an entry (`redactPaths` and `redactCensor`, under the
|
|
118
|
+
name `message`, whatever the strategy), so a credential in an address a driver could not reach is
|
|
119
|
+
no longer written. A censor that cannot answer leaves the line with an empty message. The other
|
|
120
|
+
text lines on stderr (the entries dropped for a full queue, the totals at shutdown, the spent
|
|
121
|
+
shutdown budget) carry counters and the escaped name of a destination, and are unchanged.
|
|
122
|
+
**Apply:** an alert or a search that matches the old text must match the `logKey` and the
|
|
123
|
+
`destination` field instead: `LOGGER_DESTINATION_WRITE_FAILED` and `LOGGER_DESTINATION_INIT_FAILED`
|
|
124
|
+
as before, and `LOGGER_DESTINATION_SHUTDOWN_FAILED` for a failed shutdown, which a match on
|
|
125
|
+
`Shutdown failed for` no longer finds, and a log shipper that read that line as text now receives
|
|
126
|
+
a JSON entry with `level: "error"`. The stack of the error is no longer written there: if you need
|
|
127
|
+
it, log it in your own `onShutdown`. If you list the reserved keys (a dashboard filter, an
|
|
128
|
+
allow-list), add the new one. A `message` in `redactPaths` now also hides the message of the error
|
|
129
|
+
in these lines.
|
|
130
|
+
|
|
131
|
+
### Added
|
|
132
|
+
|
|
133
|
+
- **The logger counts what it cuts and what its destinations refuse.** `LOGGER_OBSERVABILITY_TOKEN`
|
|
134
|
+
provides an `ILoggerObservability`: `truncatedTotal(reason)` (the fields cut or replaced for a size
|
|
135
|
+
bound, with `reason` of `'max_entry_size'` or `'max_string_length'`), `destinationErrorTotal()` (the
|
|
136
|
+
writes the destinations refused) and `deliveryState()` (how many destinations finished their
|
|
137
|
+
`onInit`, how many of them failed it, how many refused a write or had an entry dropped, and whether
|
|
138
|
+
one is healthy). The types `ILoggerObservability`,
|
|
139
|
+
`DeliveryState` and `TruncationReason` are exported with it. Nothing changes for a host that does
|
|
140
|
+
not read them.
|
|
141
|
+
|
|
142
|
+
- **A new `@bymax-one/nest-logger/observability` subpath publishes the counters as Prometheus
|
|
143
|
+
metrics and the delivery state as a readiness check.** `BymaxLoggerObservabilityModule` provides
|
|
144
|
+
`LoggerMetricsContributor`, which registers `bymax_logger_entries_truncated_total{reason}` (with
|
|
145
|
+
`reason` of `max_entry_size` or `max_string_length`) and `bymax_logger_destination_errors_total` on
|
|
146
|
+
the registry `@bymax-one/nest-core` serves, and `LoggerHealthIndicator`, named `logger`, which is
|
|
147
|
+
`up` while at least one destination is healthy. `@bymax-one/nest-core` (`^1.6.10`) and `prom-client`
|
|
148
|
+
(`^15`) are optional peer dependencies, imported only by this subpath; the main entry needs neither. **Apply:**
|
|
149
|
+
nothing is required; to publish the metrics, install the two peers and import
|
|
150
|
+
`BymaxLoggerObservabilityModule` next to `BymaxLoggerModule`.
|
|
151
|
+
|
|
152
|
+
#### Apply to a derived backend
|
|
153
|
+
|
|
154
|
+
Nothing is required. A derived backend that builds the Pino instance itself through
|
|
155
|
+
`buildPinoInstance` passes its `DestinationHealth`, which now counts; one that provides its own
|
|
156
|
+
`LOGGER_OBSERVABILITY_TOKEN` must return the three methods of `ILoggerObservability`.
|
|
157
|
+
|
|
158
|
+
`PinoLoggerService` gains one private member, `errorText`, and one public method,
|
|
159
|
+
`censorMessageText(text)`, in its declaration. A subclass that defines a member of either name no
|
|
160
|
+
longer compiles against it: rename yours. Nothing else about its
|
|
161
|
+
constructor or its public methods changes. A service you build by hand over a Pino instance you built
|
|
162
|
+
yourself censors the text of an `Error` with its own redactor, as it does the text of an object
|
|
163
|
+
message; over a Pino instance from `buildPinoInstance` it uses the function the factory leaves on
|
|
164
|
+
that instance, which also covers `redactStrategy: 'paths'`. The merge of the request and trace keys
|
|
165
|
+
that `buildPinoInstance` installs, and the owned-key guard of the service, now compare names with
|
|
166
|
+
their case and the separators `_`, `.` and `-` folded, and the `err` serializer and the derived
|
|
167
|
+
`exception.*` fields it builds censor the message where it opens a stack; nothing is required beyond
|
|
168
|
+
what the Breaking entry above says.
|
|
169
|
+
|
|
170
|
+
### Fixed
|
|
171
|
+
|
|
172
|
+
- **The text of an entry that comes from an `Error` is censored like `err.message`.** The text of
|
|
173
|
+
`error(err)`, `errorStructured(key, err)` and `warn(err)` (and `log`, `fatal`, `debug`, `verbose`
|
|
174
|
+
with an `Error`) is the error's `message`, and it was written as it was while the field
|
|
175
|
+
`err.message` was censored, so `redactPaths: ['message']` left the secret in `msg`. It is now
|
|
176
|
+
censored under the name `message`, also with `redactStrategy: 'paths'`. It is still capped at
|
|
177
|
+
16 KiB like every log message and not cut at `maxStringLength`, which does not apply to the log
|
|
178
|
+
message. The same text is censored where it opens the stack: in `err.stack`, in the stack of each
|
|
179
|
+
`cause` and of each of the `errors` of an `AggregateError`, and in `exception.message` and
|
|
180
|
+
`exception.stacktrace` with `errorFormat: 'semconv'` or `'both'`. It is replaced where the engine
|
|
181
|
+
writes it, right after the first `: ` of the first line (or at the start, for an error with no
|
|
182
|
+
name), by an exact comparison there, never by a search and never by a pattern built from your
|
|
183
|
+
text, so an error whose name repeats or contains its message is censored in the message and not
|
|
184
|
+
in the name, and so is a message that wraps another error with its frames. It holds for an `Error`,
|
|
185
|
+
a subclass and an `Error` of another realm, and for a message with a control character, which the
|
|
186
|
+
stack escapes. A stack whose header is not in the default form loses its frames when its message
|
|
187
|
+
is censored: it becomes its name, if any, and the censored message, as what it holds may be the
|
|
188
|
+
secret too. A stack of a message that nothing censored is not touched. **What this covers,
|
|
189
|
+
precisely:** redaction works on field names, so it covers a field and the text copied from a named
|
|
190
|
+
field (the `message` or `event` of an object message, and the `message` of an `Error` where it
|
|
191
|
+
appears as the text of the entry, in its stack and in the derived `exception.*` fields); it never
|
|
192
|
+
reads the content of a string, so a text a caller passes as a string, such as
|
|
193
|
+
``logger.warn(`card ${number}`)``, is written as it is, and a secret that an error carries in
|
|
194
|
+
another field (a `code`, an own property) is covered only by the name of that field. 1.4.23 said a
|
|
195
|
+
secret in `event` or `message` does not reach `msg`; that holds for the text of an object message
|
|
196
|
+
and, from this release, for the message of an `Error`, and for no other source of the text. **Apply:** nothing is required; a log search that relied on finding a
|
|
197
|
+
censored value in the `msg` of an `Error` no longer finds it.
|
|
198
|
+
- **The derived exception fields are bounded by `maxEntrySizeBytes`.** With `errorFormat: 'semconv'`
|
|
199
|
+
or `'both'`, `exception.type`, `exception.message`, `exception.stacktrace` and `error.type` were
|
|
200
|
+
cut only by the fixed 16 KiB text cap, so with `maxEntrySizeBytes` set below the 64 KiB default
|
|
201
|
+
each could be larger than the ceiling that bounds a serializer's output. Each
|
|
202
|
+
is now cut to `maxEntrySizeBytes` UTF-8 bytes, ending in `…[truncated]` (omitted under a 14-byte ceiling), at a character boundary.
|
|
203
|
+
**Apply:** nothing is required; a query that reads the full message or stack of a very long error
|
|
204
|
+
through these fields gets the cut text when the ceiling is lower than the error, so raise
|
|
205
|
+
`maxEntrySizeBytes` if you need more of it.
|
|
206
|
+
- **A serializer output that `JSON.stringify` cannot measure is bounded.** A value with a reference
|
|
207
|
+
back to an ancestor, or a `BigInt`, passed the size ceiling unmeasured, so a huge one reached the
|
|
208
|
+
line. It is now measured as it is written (a cycle as `"[Circular]"`, a `BigInt` by its digits) and
|
|
209
|
+
truncated when over the ceiling; a repeated reference without a cycle is counted every time it is
|
|
210
|
+
written. **Apply:** nothing is required; an alert on `LOGGER_ENTRY_TRUNCATED` now also fires for
|
|
211
|
+
these values.
|
|
212
|
+
- **A serializer that is itself `undefined` is refused with its type.** `serializers: { a: undefined }`
|
|
213
|
+
said `options.serializers must map every serializer key to a function` and no more; it now ends in
|
|
214
|
+
`Received undefined`, as the other refused members do. **Apply:** code that matches the text of
|
|
215
|
+
that refusal exactly matches the new one.
|
|
216
|
+
|
|
217
|
+
### Documentation
|
|
218
|
+
|
|
219
|
+
- **The README says what a call costs.** A string line, a structured call and an object message
|
|
220
|
+
are timed in its Performance section, with the cost of comparing the names of a payload with the
|
|
221
|
+
keys the logger writes.
|
|
222
|
+
- **The README names every export of a public subpath.** Some exports of the root entry and one of
|
|
223
|
+
`/shared` (the option and context types, the metadata key of the deprecated `@LogContext` and the
|
|
224
|
+
`ReservedLogKey` union) were never named in it; an "Option and context types" table describes
|
|
225
|
+
each, and a spec reads the barrels through the TypeScript compiler and fails when an export is
|
|
226
|
+
missing, so a new one cannot ship unnamed.
|
|
227
|
+
- **The size measurement is said to count a shared sub-object once per reference.** A sub-object that
|
|
228
|
+
several parents share is measured, and written by Pino, once for each reference, so a graph in
|
|
229
|
+
which large sub-objects are shared widely costs time and size in proportion; keep such graphs out
|
|
230
|
+
of the log.
|
|
231
|
+
|
|
15
232
|
## [1.4.23] - 2026-11-17
|
|
16
233
|
|
|
17
234
|
### Breaking
|
|
@@ -3095,7 +3312,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
3095
3312
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
3096
3313
|
`release.yml`, Dependabot, and issue templates
|
|
3097
3314
|
|
|
3098
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3315
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.25...HEAD
|
|
3316
|
+
[1.4.25]: https://github.com/bymaxone/nest-logger/compare/v1.4.24...v1.4.25
|
|
3317
|
+
[1.4.24]: https://github.com/bymaxone/nest-logger/compare/v1.4.23...v1.4.24
|
|
3099
3318
|
[1.4.23]: https://github.com/bymaxone/nest-logger/compare/v1.4.22...v1.4.23
|
|
3100
3319
|
[1.4.22]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...v1.4.22
|
|
3101
3320
|
[1.4.21]: https://github.com/bymaxone/nest-logger/compare/v1.4.20...v1.4.21
|