@bymax-one/nest-logger 1.4.20 → 1.4.22
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 +108 -1
- package/README.md +9 -2
- package/dist/server/index.cjs +207 -129
- package/dist/server/index.d.cts +25 -2
- package/dist/server/index.d.ts +25 -2
- package/dist/server/index.mjs +207 -129
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,111 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.22] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Breaking
|
|
18
|
+
|
|
19
|
+
- **`maxEntrySizeBytes` is at most 2147483647.** A value such as `2 ** 53` or `1e300` was accepted
|
|
20
|
+
and could never be reached by an entry. `forRoot` now rejects it with
|
|
21
|
+
`options.maxEntrySizeBytes must be at most 2147483647`.
|
|
22
|
+
**Apply:** pass a ceiling of at most 2147483647 bytes; the default and every value up to that are
|
|
23
|
+
unaffected.
|
|
24
|
+
|
|
25
|
+
- **A `maxStringLength` outside 64 to 2147483647 is refused.** 1.4.21 did not read an option of that
|
|
26
|
+
name, so a key `maxStringLength` was ignored whatever it held. It is validated at startup now
|
|
27
|
+
(`options.maxStringLength must be an integer from 64 to 2147483647`), and a value such as `10`,
|
|
28
|
+
`64.5` or `'100'` stops the application from starting. **Apply:** remove the key, or give a whole
|
|
29
|
+
number of characters from 64 up to 2147483647.
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **`maxStringLength` bounds the length of every string of a log record.** A string under a metadata
|
|
34
|
+
key is the caller's own data and was written as given, so one value of a megabyte made an entry of
|
|
35
|
+
a megabyte. With `maxStringLength` set, a string longer than the limit is cut to that many
|
|
36
|
+
characters (a cut never splits a surrogate pair) and ends with `…[truncated]`. It is an integer
|
|
37
|
+
from 64 to 2147483647 and it is off until set. The cut runs after
|
|
38
|
+
every redaction rule and before the event name and the exception fields are written, so it cannot
|
|
39
|
+
cut a string before a rule that needs the whole of it.
|
|
40
|
+
It applies at any depth, and not to a key, a value that is not text, the log message, the
|
|
41
|
+
`logKey`, the bindings of a logger, or anything under a key that has a serializer (`err` and the
|
|
42
|
+
keys of `serializers`). The event name and the `exception.*` and `error.type` fields the library
|
|
43
|
+
writes are added after the cut, so the limit does not apply to them, and the exception fields among them keep the cap of
|
|
44
|
+
16384 characters they had in 1.4.21. An `Error` placed in the metadata under any
|
|
45
|
+
other key is data of the record when the cut runs, and its message and stack are cut like any
|
|
46
|
+
other string. The names left whole are matched on the root key, so a key of your own named like a
|
|
47
|
+
serializer key is left whole too. A `userId` longer than the
|
|
48
|
+
limit is cut like any other string. A `redactCensor` longer than the limit is refused at startup,
|
|
49
|
+
so a censor is never cut. Setting the option makes the record walk run even when no field name is
|
|
50
|
+
covered (`shouldDisableDefaultRedact: true` and no `redactPaths`), and the walk writes a boxed
|
|
51
|
+
`String` or `Number`, a `Buffer`, a `Uint8Array` and an `Error` in the metadata as the default
|
|
52
|
+
redaction already does: a two-byte `Buffer` is written as `[Binary 2 bytes]` and not as
|
|
53
|
+
`{"type":"Buffer","data":[104,105]}`, while a boxed `Number` is written as `{}` and a boxed
|
|
54
|
+
`String` as a map of its indexes (`{"0":"a","1":"b","2":"c"}` for `new String('abc')`), as the
|
|
55
|
+
default redaction writes them.
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- **The steps of `PrettyDevDestination.onInit` are module functions, not methods.** 1.4.21 split
|
|
60
|
+
`onInit` into the private methods `refuseInProduction`, `buildTransform` and `initFailure`, which
|
|
61
|
+
`onInit` called through `this`. A subclass written without the type check, as JavaScript is, that
|
|
62
|
+
defined a member with one of those names had it called in the place of the step. The steps are now
|
|
63
|
+
functions of the module, so no member of any name replaces them, and the three declarations leave
|
|
64
|
+
the `.d.ts`. Behavior is otherwise unchanged.
|
|
65
|
+
|
|
66
|
+
- **A refused option names the type of the value it received and never quotes it.** The message
|
|
67
|
+
used to end in `Got: "3"` for a string and in `String(value)` for a number, a boolean, a bigint or a
|
|
68
|
+
Symbol, so a token typed into the wrong field, or a Symbol with a description, reached the bootstrap
|
|
69
|
+
log. It now ends in
|
|
70
|
+
`Received a string`, `Received a symbol`, `Received an object` and so on, and prints a value only
|
|
71
|
+
when it is a finite number (`Received the number 63`). The refusals that bypassed the shared path
|
|
72
|
+
and printed `String(value)` (`level`, `redactStrategy`, `resourceFormat`, `errorFormat` and
|
|
73
|
+
`eventNameField`) go through it too. A `service` that is not an object, including `null`, `0`,
|
|
74
|
+
`false`, `''` and `NaN`, is now refused as `options.service must be an object. Received …`:
|
|
75
|
+
1.4.21 said `options.service is required` for a falsy one and blamed `service.name` or `service.version` for any other,
|
|
76
|
+
and only an undefined `service` keeps `options.service is required`. **Apply:** code that matches
|
|
77
|
+
the text `Got:` of a refusal matches `Received` instead; apart from that and `service`, the
|
|
78
|
+
option's name and the rule are unchanged. Three refusals had no suffix at
|
|
79
|
+
all (a `service.name` or `service.version` that is not a non-empty string, and a
|
|
80
|
+
`maxEntrySizeBytes` of 0 or less) and now end in `Received <type>` too, so an exact match on their
|
|
81
|
+
whole text changes as well; a missing `service.name` or `service.version` still has no suffix.
|
|
82
|
+
|
|
83
|
+
#### Apply to a derived backend
|
|
84
|
+
|
|
85
|
+
`PrettyDevDestination`: nothing is required. A subclass that defines a member named
|
|
86
|
+
`refuseInProduction`, `buildTransform` or `initFailure` keeps it, and `onInit` no longer calls it.
|
|
87
|
+
|
|
88
|
+
`maxStringLength`: a configuration that already passes that key with a value outside 64 to
|
|
89
|
+
2147483647 must change it, because it is refused now (see the Breaking entry above); otherwise
|
|
90
|
+
nothing is required, since the option is off until set. `ResolvedBymaxLoggerModuleOptions` gains the key `maxStringLength: number | undefined`, so a derived
|
|
91
|
+
backend that builds that object itself adds `maxStringLength: undefined`; one that spreads the
|
|
92
|
+
result of `applyDefaults` already has it.
|
|
93
|
+
|
|
94
|
+
## [1.4.21] - 2026-11-17
|
|
95
|
+
|
|
96
|
+
### Breaking
|
|
97
|
+
|
|
98
|
+
- **`@LogPerformance(thresholdMs)` refuses a threshold that is not a finite number of zero or
|
|
99
|
+
more.** `NaN` and `Infinity` made the comparison `duration > thresholdMs` never true, so slow-call
|
|
100
|
+
logging was silently off, and a negative value logged every call as slow. The decorator now throws
|
|
101
|
+
a `TypeError` where it is applied, at class definition. **Apply:** if a call passes a computed
|
|
102
|
+
threshold, check that it is a finite number of zero or more; a literal such as `500` or no
|
|
103
|
+
argument is unaffected.
|
|
104
|
+
- **`maxEntrySizeBytes` must be an integer.** A fraction such as `1.5` was accepted and compared as
|
|
105
|
+
a byte ceiling. `forRoot` now rejects it with `options.maxEntrySizeBytes must be an integer`, as it
|
|
106
|
+
does for every other size and timer option. **Apply:** pass a whole number of bytes.
|
|
107
|
+
|
|
108
|
+
### Changed
|
|
109
|
+
|
|
110
|
+
- **`PrettyDevDestination.onInit` is split into private methods.** `refuseInProduction`,
|
|
111
|
+
`buildTransform` and `initFailure` now appear in the class declaration as `private` members.
|
|
112
|
+
Behavior is unchanged.
|
|
113
|
+
|
|
114
|
+
#### Apply to a derived backend
|
|
115
|
+
|
|
116
|
+
Nothing is required of most consumers. A subclass of `PrettyDevDestination` that declares a member named
|
|
117
|
+
`refuseInProduction`, `buildTransform` or `initFailure` no longer compiles against the new
|
|
118
|
+
declaration; rename it.
|
|
119
|
+
|
|
15
120
|
## [1.4.20] - 2026-11-17
|
|
16
121
|
|
|
17
122
|
### Fixed
|
|
@@ -2915,7 +3020,9 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
2915
3020
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
2916
3021
|
`release.yml`, Dependabot, and issue templates
|
|
2917
3022
|
|
|
2918
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3023
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.22...HEAD
|
|
3024
|
+
[1.4.22]: https://github.com/bymaxone/nest-logger/compare/v1.4.21...v1.4.22
|
|
3025
|
+
[1.4.21]: https://github.com/bymaxone/nest-logger/compare/v1.4.20...v1.4.21
|
|
2919
3026
|
[1.4.20]: https://github.com/bymaxone/nest-logger/compare/v1.4.19...v1.4.20
|
|
2920
3027
|
[1.4.19]: https://github.com/bymaxone/nest-logger/compare/v1.4.18...v1.4.19
|
|
2921
3028
|
[1.4.18]: https://github.com/bymaxone/nest-logger/compare/v1.4.17...v1.4.18
|
package/README.md
CHANGED
|
@@ -267,7 +267,8 @@ Full options reference for `BymaxLoggerModule.forRoot(options)`:
|
|
|
267
267
|
| `redactStrategy` | `'names' \| 'paths'` | `'names'` | Engine behind the DEFAULT set. `'paths'` is the legacy `fast-redact` expansion (four-level ceiling, much slower) |
|
|
268
268
|
| `shouldDisableDefaultRedact` | `boolean` | `false` | Skip the default PII coverage entirely. ⚠️ Emits `LOGGER_BOOTSTRAP_WARNING` at startup — document why |
|
|
269
269
|
| `redactCensor` | `string` | `'[REDACTED]'` | Replacement value written in place of every redacted field |
|
|
270
|
-
| `maxEntrySizeBytes` | `number` | `65536` | UTF-8 byte ceiling per serialized field (`err` + any custom serializer); over it the value becomes a truncation envelope
|
|
270
|
+
| `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 |
|
|
271
|
+
| `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
272
|
| `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
273
|
| `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
274
|
| `errorOwnFieldNames` | `readonly string[]` | `[]` | Own-field names `'safe'` writes beside its default list, matched exactly; ignored under `'all'` |
|
|
@@ -907,6 +908,12 @@ An interpolated value has no name, so no configuration can redact it. **A value
|
|
|
907
908
|
|
|
908
909
|
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
910
|
|
|
911
|
+
### Bounded string length
|
|
912
|
+
|
|
913
|
+
`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.
|
|
914
|
+
|
|
915
|
+
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.
|
|
916
|
+
|
|
910
917
|
### Security Checklist
|
|
911
918
|
|
|
912
919
|
- `shouldDisableDefaultRedact` stays `false`; if it is on, the `LOGGER_BOOTSTRAP_WARNING` must be justified in a security review.
|
|
@@ -1024,7 +1031,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1024
1031
|
| ------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1025
1032
|
| `@InjectLogger(context?)` | Constructor param | Injects `PinoLoggerService` pre-bound to the given context string |
|
|
1026
1033
|
| `@LogContext(name)` | Class | **Deprecated.** Records a context label as class metadata that nothing in this package reads, so the label is never applied, and it does NOT open a `logContext.run()` scope. Use `@InjectLogger(MyClass.name)` for a per-class label |
|
|
1027
|
-
| `@LogPerformance(thresholdMs?)` | Method | Logs `METHOD_EXECUTION` on completion; `METHOD_SLOW_EXECUTION` if duration exceeds threshold
|
|
1034
|
+
| `@LogPerformance(thresholdMs?)` | Method | Logs `METHOD_EXECUTION` on completion; `METHOD_SLOW_EXECUTION` if duration exceeds threshold, which must be a finite number of zero or more (a `TypeError` at class definition otherwise) |
|
|
1028
1035
|
|
|
1029
1036
|
### Injection tokens and helpers
|
|
1030
1037
|
|
package/dist/server/index.cjs
CHANGED
|
@@ -32,6 +32,9 @@ var DEFAULT_DRAIN_TIMEOUT_MS = 5e3;
|
|
|
32
32
|
var DEFAULT_QUEUE_MAX_BYTES = 33554432;
|
|
33
33
|
var MIN_QUEUE_MAX_BYTES = 1024;
|
|
34
34
|
var MAX_QUEUE_MAX_BYTES = 2147483647;
|
|
35
|
+
var MAX_ENTRY_SIZE_BYTES = 2147483647;
|
|
36
|
+
var MIN_STRING_LENGTH_LIMIT = 64;
|
|
37
|
+
var MAX_STRING_LENGTH_LIMIT = 2147483647;
|
|
35
38
|
|
|
36
39
|
// src/server/config/default-options.ts
|
|
37
40
|
var DEFAULT_HTTP = {
|
|
@@ -101,6 +104,7 @@ function applyDefaults(options) {
|
|
|
101
104
|
}),
|
|
102
105
|
otel: Object.freeze(otel),
|
|
103
106
|
maxEntrySizeBytes: options.maxEntrySizeBytes ?? DEFAULT_MAX_ENTRY_SIZE_BYTES,
|
|
107
|
+
maxStringLength: options.maxStringLength,
|
|
104
108
|
destinationHookTimeoutMs: options.destinationHookTimeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS,
|
|
105
109
|
shutdown: resolveShutdown(options.shutdown),
|
|
106
110
|
destinationQueue: Object.freeze({
|
|
@@ -141,16 +145,27 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
|
|
|
141
145
|
|
|
142
146
|
// src/server/config/validate-options.ts
|
|
143
147
|
function reject(path, rule, got) {
|
|
144
|
-
const received = got === void 0 ? "" : `.
|
|
148
|
+
const received = got === void 0 ? "" : `. Received ${describeValue(got)}`;
|
|
145
149
|
throw new Error(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
|
|
146
150
|
}
|
|
147
151
|
function describeValue(value) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
switch (typeof value) {
|
|
153
|
+
case "number":
|
|
154
|
+
return Number.isFinite(value) ? `the number ${String(value)}` : "a number that is not finite";
|
|
155
|
+
case "string":
|
|
156
|
+
return "a string";
|
|
157
|
+
case "boolean":
|
|
158
|
+
return "a boolean";
|
|
159
|
+
case "bigint":
|
|
160
|
+
return "a bigint";
|
|
161
|
+
case "symbol":
|
|
162
|
+
return "a symbol";
|
|
163
|
+
case "function":
|
|
164
|
+
return "a function";
|
|
165
|
+
default:
|
|
166
|
+
if (value === null) return "null";
|
|
167
|
+
return Array.isArray(value) ? "an array" : "an object";
|
|
168
|
+
}
|
|
154
169
|
}
|
|
155
170
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
156
171
|
var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
@@ -188,6 +203,24 @@ function validateQueue(options) {
|
|
|
188
203
|
);
|
|
189
204
|
}
|
|
190
205
|
}
|
|
206
|
+
function validateStringLimit(options) {
|
|
207
|
+
const limit = options.maxStringLength;
|
|
208
|
+
if (limit === void 0) return;
|
|
209
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < MIN_STRING_LENGTH_LIMIT || limit > MAX_STRING_LENGTH_LIMIT) {
|
|
210
|
+
reject(
|
|
211
|
+
"maxStringLength",
|
|
212
|
+
`must be an integer from ${String(MIN_STRING_LENGTH_LIMIT)} to ${String(MAX_STRING_LENGTH_LIMIT)}`,
|
|
213
|
+
limit
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const censor = options.redactCensor;
|
|
217
|
+
if (typeof censor === "string" && censor.length > limit) {
|
|
218
|
+
reject(
|
|
219
|
+
"redactCensor",
|
|
220
|
+
`must be at most ${String(limit)} characters when maxStringLength is set`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
191
224
|
function validateLifecycle(options) {
|
|
192
225
|
checkTimerMs("destinationHookTimeoutMs", options.destinationHookTimeoutMs);
|
|
193
226
|
const shutdown = checkGroup("shutdown", options.shutdown);
|
|
@@ -205,58 +238,46 @@ function validateLifecycle(options) {
|
|
|
205
238
|
}
|
|
206
239
|
}
|
|
207
240
|
function validateCore(options) {
|
|
208
|
-
|
|
241
|
+
const service = options.service;
|
|
242
|
+
if (service === void 0) {
|
|
209
243
|
throw new Error("[BymaxLoggerModule] options.service is required");
|
|
210
244
|
}
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
245
|
+
if (!isRecord(service)) reject("service", "must be an object", service);
|
|
246
|
+
for (const field of ["name", "version"]) {
|
|
247
|
+
const given = service[field];
|
|
248
|
+
if (typeof given !== "string" || given.trim() === "") {
|
|
249
|
+
reject(`service.${field}`, "must be a non-empty string", given);
|
|
250
|
+
}
|
|
216
251
|
}
|
|
217
252
|
if (options.level !== void 0 && !LOG_LEVEL_PRIORITY.includes(options.level)) {
|
|
218
|
-
|
|
219
|
-
`[BymaxLoggerModule] options.level must be one of: ${LOG_LEVEL_PRIORITY.join(
|
|
220
|
-
", "
|
|
221
|
-
)}. Got: ${String(options.level)}`
|
|
222
|
-
);
|
|
253
|
+
reject("level", `must be one of: ${LOG_LEVEL_PRIORITY.join(", ")}`, options.level);
|
|
223
254
|
}
|
|
224
255
|
const size = options.maxEntrySizeBytes;
|
|
225
256
|
if (size !== void 0 && !Number.isFinite(size)) {
|
|
226
257
|
reject("maxEntrySizeBytes", "must be a finite number", size);
|
|
227
258
|
}
|
|
228
259
|
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes <= 0) {
|
|
229
|
-
|
|
260
|
+
reject("maxEntrySizeBytes", "must be > 0", options.maxEntrySizeBytes);
|
|
261
|
+
}
|
|
262
|
+
if (size !== void 0 && !Number.isInteger(size)) {
|
|
263
|
+
reject("maxEntrySizeBytes", "must be an integer", size);
|
|
264
|
+
}
|
|
265
|
+
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes > MAX_ENTRY_SIZE_BYTES) {
|
|
266
|
+
reject("maxEntrySizeBytes", `must be at most ${String(MAX_ENTRY_SIZE_BYTES)}`, size);
|
|
230
267
|
}
|
|
231
268
|
}
|
|
232
269
|
function validateClosedSets(options) {
|
|
233
270
|
if (options.redactStrategy !== void 0 && options.redactStrategy !== "names" && options.redactStrategy !== "paths") {
|
|
234
|
-
|
|
235
|
-
`[BymaxLoggerModule] options.redactStrategy must be 'names' or 'paths'. Got: ${String(
|
|
236
|
-
options.redactStrategy
|
|
237
|
-
)}`
|
|
238
|
-
);
|
|
271
|
+
reject("redactStrategy", "must be 'names' or 'paths'", options.redactStrategy);
|
|
239
272
|
}
|
|
240
273
|
if (options.resourceFormat !== void 0 && options.resourceFormat !== "nested" && options.resourceFormat !== "flat") {
|
|
241
|
-
|
|
242
|
-
`[BymaxLoggerModule] options.resourceFormat must be 'nested' or 'flat'. Got: ${String(
|
|
243
|
-
options.resourceFormat
|
|
244
|
-
)}`
|
|
245
|
-
);
|
|
274
|
+
reject("resourceFormat", "must be 'nested' or 'flat'", options.resourceFormat);
|
|
246
275
|
}
|
|
247
276
|
if (options.errorFormat !== void 0 && options.errorFormat !== "pino" && options.errorFormat !== "semconv" && options.errorFormat !== "both") {
|
|
248
|
-
|
|
249
|
-
`[BymaxLoggerModule] options.errorFormat must be 'pino', 'semconv' or 'both'. Got: ${String(
|
|
250
|
-
options.errorFormat
|
|
251
|
-
)}`
|
|
252
|
-
);
|
|
277
|
+
reject("errorFormat", "must be 'pino', 'semconv' or 'both'", options.errorFormat);
|
|
253
278
|
}
|
|
254
279
|
if (options.eventNameField !== void 0 && options.eventNameField !== false && (typeof options.eventNameField !== "string" || options.eventNameField.length === 0)) {
|
|
255
|
-
|
|
256
|
-
`[BymaxLoggerModule] options.eventNameField must be a non-empty string or false. Got: ${String(
|
|
257
|
-
options.eventNameField
|
|
258
|
-
)}`
|
|
259
|
-
);
|
|
280
|
+
reject("eventNameField", "must be a non-empty string or false", options.eventNameField);
|
|
260
281
|
}
|
|
261
282
|
}
|
|
262
283
|
function validateCustomization(options) {
|
|
@@ -385,6 +406,7 @@ function validateOptions(options) {
|
|
|
385
406
|
validateDestinations(options);
|
|
386
407
|
validateLifecycle(options);
|
|
387
408
|
validateQueue(options);
|
|
409
|
+
validateStringLimit(options);
|
|
388
410
|
validateHttp(options);
|
|
389
411
|
validateOtel(options);
|
|
390
412
|
}
|
|
@@ -445,9 +467,9 @@ var TEXT_TRUNCATED = "\u2026[truncated]";
|
|
|
445
467
|
function cutIfText(value) {
|
|
446
468
|
return typeof value === "string" ? cutText(value) : value;
|
|
447
469
|
}
|
|
448
|
-
function cutText(text, alreadyCut = false) {
|
|
449
|
-
if (!alreadyCut && text.length <=
|
|
450
|
-
const head = text.slice(0,
|
|
470
|
+
function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
|
|
471
|
+
if (!alreadyCut && text.length <= limit) return text;
|
|
472
|
+
const head = text.slice(0, limit);
|
|
451
473
|
const last = head.charCodeAt(head.length - 1);
|
|
452
474
|
const whole = last >= 55296 && last <= 56319 ? head.slice(0, -1) : head;
|
|
453
475
|
return whole + TEXT_TRUNCATED;
|
|
@@ -2152,6 +2174,31 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2152
2174
|
const sources = shouldSkipDefaults ? [extraPaths] : [DEFAULT_REDACT_PATHS, extraPaths];
|
|
2153
2175
|
return Array.from(new Set(sources.flat()));
|
|
2154
2176
|
}
|
|
2177
|
+
|
|
2178
|
+
// 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
|
+
function cutNode(node, limit) {
|
|
2185
|
+
if (typeof node === "string") return cutText(node, false, limit);
|
|
2186
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
|
|
2187
|
+
if (isPlainRecord(node)) {
|
|
2188
|
+
return Object.fromEntries(
|
|
2189
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2192
|
+
return node;
|
|
2193
|
+
}
|
|
2194
|
+
function cutStrings(record, limit, exempt) {
|
|
2195
|
+
return Object.fromEntries(
|
|
2196
|
+
Object.entries(record).map(([key, child]) => [
|
|
2197
|
+
key,
|
|
2198
|
+
exempt.has(key) ? child : cutNode(child, limit)
|
|
2199
|
+
])
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2155
2202
|
function reportWriteFailure(destination, cause, due) {
|
|
2156
2203
|
const name = safeDestinationName(destination);
|
|
2157
2204
|
reportDestinationFailure(
|
|
@@ -2875,20 +2922,31 @@ var PASS_THROUGH = (value) => value;
|
|
|
2875
2922
|
function resolveNameRedactor(options) {
|
|
2876
2923
|
return buildNameRedactor(options, true, options.redactStrategy === "names");
|
|
2877
2924
|
}
|
|
2925
|
+
function resolveRecordRedactor(options) {
|
|
2926
|
+
return buildNameRedactor(
|
|
2927
|
+
options,
|
|
2928
|
+
true,
|
|
2929
|
+
options.redactStrategy === "names",
|
|
2930
|
+
options.maxStringLength !== void 0
|
|
2931
|
+
);
|
|
2932
|
+
}
|
|
2933
|
+
function wholeRootKeys(options) {
|
|
2934
|
+
return /* @__PURE__ */ new Set(["logKey", "err", ...Object.keys(options.serializers)]);
|
|
2935
|
+
}
|
|
2878
2936
|
function ownFieldPolicyOf(options) {
|
|
2879
2937
|
return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
|
|
2880
2938
|
}
|
|
2881
2939
|
function namesInsideErrors(options) {
|
|
2882
2940
|
return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
|
|
2883
2941
|
}
|
|
2884
|
-
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
|
|
2942
|
+
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true, forcesWalk = false) {
|
|
2885
2943
|
const allNames = [
|
|
2886
2944
|
...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
|
|
2887
2945
|
...options.redactPaths.flatMap((path) => leafNameOf(path) ?? [])
|
|
2888
2946
|
];
|
|
2889
2947
|
const names = coversNames ? allNames : [];
|
|
2890
2948
|
const ownFields = ownFieldPolicyOf(options);
|
|
2891
|
-
const walks = names.length > 0 || ownFields.safe;
|
|
2949
|
+
const walks = names.length > 0 || ownFields.safe || forcesWalk;
|
|
2892
2950
|
if (!walks && resolveRedactOption(options) === void 0) {
|
|
2893
2951
|
return PASS_THROUGH;
|
|
2894
2952
|
}
|
|
@@ -2917,14 +2975,10 @@ function resolveRedactOption(options) {
|
|
|
2917
2975
|
}
|
|
2918
2976
|
return { paths, censor: options.redactCensor };
|
|
2919
2977
|
}
|
|
2920
|
-
function
|
|
2978
|
+
function buildSerializers(options, redactSerialized, ownFields) {
|
|
2921
2979
|
const maxBytes = options.maxEntrySizeBytes;
|
|
2922
|
-
const redactRecord = resolveNameRedactor(options);
|
|
2923
|
-
const redactSerialized = buildNameRedactor(options);
|
|
2924
|
-
const ownFields = ownFieldPolicyOf(options);
|
|
2925
2980
|
const bound = (serializer) => createSizeBoundedSerializer((input) => redactSerialized(serializer(input)), maxBytes);
|
|
2926
|
-
|
|
2927
|
-
const serializers = {
|
|
2981
|
+
return {
|
|
2928
2982
|
err: bound((error) => serializeErrorValue(error, ownFields)),
|
|
2929
2983
|
...Object.fromEntries(
|
|
2930
2984
|
Object.entries(options.serializers).map(
|
|
@@ -2932,6 +2986,73 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
2932
2986
|
)
|
|
2933
2987
|
)
|
|
2934
2988
|
};
|
|
2989
|
+
}
|
|
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
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
function buildStreams(options, destinations, health) {
|
|
3002
|
+
return destinations.map((destination) => {
|
|
3003
|
+
const stream = destinationToStream(destination, health, options.destinationQueue.maxBytes);
|
|
3004
|
+
health.registerStream(destination, stream);
|
|
3005
|
+
return {
|
|
3006
|
+
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
3007
|
+
// consumer implementing `minLevel` as a throwing getter would fail the factory
|
|
3008
|
+
// and the application would never start — earlier than any fail-soft path can
|
|
3009
|
+
// contain. Unreadable and absent give the same answer: the module level.
|
|
3010
|
+
level: safeMinLevel(destination) ?? options.level,
|
|
3011
|
+
stream
|
|
3012
|
+
};
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
function buildRecordFormatter(options, redactRecord) {
|
|
3016
|
+
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3017
|
+
const maxStringLength = options.maxStringLength;
|
|
3018
|
+
const wholeRoots = wholeRootKeys(options);
|
|
3019
|
+
return (record) => {
|
|
3020
|
+
const redacted = redactRecord(
|
|
3021
|
+
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3022
|
+
true
|
|
3023
|
+
);
|
|
3024
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3025
|
+
return withSemconvException(withEventName(bounded, options.eventNameField), options.errorFormat);
|
|
3026
|
+
};
|
|
3027
|
+
}
|
|
3028
|
+
function buildFormatters(options, redactRecord, redactBindings) {
|
|
3029
|
+
return {
|
|
3030
|
+
// Emit the level as a string label instead of the numeric code — easier
|
|
3031
|
+
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
3032
|
+
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
3033
|
+
level: (label) => ({ level: label }),
|
|
3034
|
+
// `base` bindings never reach `formatters.log` — Pino pre-serializes them
|
|
3035
|
+
// into the instance's `chindings`, the same reason `child()` has to redact
|
|
3036
|
+
// its own. That matters because `service` is CONSUMER-supplied and
|
|
3037
|
+
// `applyDefaults` keeps whatever it was given: a `{ name, version, apiKey }`
|
|
3038
|
+
// went out in clear, where the path expansion had covered it via `*.*.apiKey`.
|
|
3039
|
+
// Redacting here rather than trimming to the two declared fields keeps a
|
|
3040
|
+
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
3041
|
+
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
3042
|
+
// root, iterated rather than serialized.
|
|
3043
|
+
bindings: (bindings) => redactBindings(bindings, true),
|
|
3044
|
+
// The name-walk redactor runs here, on the merged record (mixin output +
|
|
3045
|
+
// the caller's object), which is exactly the surface a caller controls.
|
|
3046
|
+
// `base` and child bindings are NOT visible at this hook — they are
|
|
3047
|
+
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
3048
|
+
// sensitive, which `pino-factory.spec.ts` pins.
|
|
3049
|
+
log: buildRecordFormatter(options, redactRecord)
|
|
3050
|
+
};
|
|
3051
|
+
}
|
|
3052
|
+
function buildPinoInstance(options, logContext, destinations, health) {
|
|
3053
|
+
const redactRecord = resolveRecordRedactor(options);
|
|
3054
|
+
const redactSerialized = buildNameRedactor(options);
|
|
3055
|
+
const ownFields = ownFieldPolicyOf(options);
|
|
2935
3056
|
const redactOption = resolveRedactOption(options);
|
|
2936
3057
|
const pinoOptions = {
|
|
2937
3058
|
level: options.level,
|
|
@@ -2949,69 +3070,12 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
2949
3070
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
2950
3071
|
// neither break the line nor add fields to it.
|
|
2951
3072
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
2952
|
-
formatters:
|
|
2953
|
-
|
|
2954
|
-
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
2955
|
-
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
2956
|
-
level: (label) => ({ level: label }),
|
|
2957
|
-
// `base` bindings never reach `formatters.log` — Pino pre-serializes them
|
|
2958
|
-
// into the instance's `chindings`, the same reason `child()` has to redact
|
|
2959
|
-
// its own. That matters because `service` is CONSUMER-supplied and
|
|
2960
|
-
// `applyDefaults` keeps whatever it was given: a `{ name, version, apiKey }`
|
|
2961
|
-
// went out in clear, where the path expansion had covered it via `*.*.apiKey`.
|
|
2962
|
-
// Redacting here rather than trimming to the two declared fields keeps a
|
|
2963
|
-
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
2964
|
-
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
2965
|
-
// root, iterated rather than serialized.
|
|
2966
|
-
bindings: (bindings) => redactRecord(bindings, true),
|
|
2967
|
-
// The name-walk redactor runs here, on the merged record (mixin output +
|
|
2968
|
-
// the caller's object), which is exactly the surface a caller controls.
|
|
2969
|
-
// `base` and child bindings are NOT visible at this hook — they are
|
|
2970
|
-
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
2971
|
-
// sensitive, which `pino-factory.spec.ts` pins.
|
|
2972
|
-
log: (record) => withSemconvException(
|
|
2973
|
-
withEventName(
|
|
2974
|
-
redactRecord(
|
|
2975
|
-
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
2976
|
-
true
|
|
2977
|
-
),
|
|
2978
|
-
options.eventNameField
|
|
2979
|
-
),
|
|
2980
|
-
options.errorFormat
|
|
2981
|
-
)
|
|
2982
|
-
},
|
|
2983
|
-
serializers,
|
|
3073
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3074
|
+
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
2984
3075
|
mixin: createTraceContextMixin(logContext, options.otel),
|
|
2985
|
-
|
|
2986
|
-
// merges the mixin result with it first, and the default strategy's
|
|
2987
|
-
// `Object.assign` invokes every own getter. A throwing getter therefore
|
|
2988
|
-
// crashed the log call before the redactor could return its fail-closed
|
|
2989
|
-
// envelope. Owning the merge moves that boundary inside the guarantee.
|
|
2990
|
-
mixinMergeStrategy: (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
|
-
}
|
|
3000
|
-
}
|
|
3076
|
+
mixinMergeStrategy: mergeMixinSafely
|
|
3001
3077
|
};
|
|
3002
|
-
|
|
3003
|
-
const stream = destinationToStream(destination, health, options.destinationQueue.maxBytes);
|
|
3004
|
-
health.registerStream(destination, stream);
|
|
3005
|
-
return {
|
|
3006
|
-
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
3007
|
-
// consumer implementing `minLevel` as a throwing getter would fail the factory
|
|
3008
|
-
// and the application would never start — earlier than any fail-soft path can
|
|
3009
|
-
// contain. Unreadable and absent give the same answer: the module level.
|
|
3010
|
-
level: safeMinLevel(destination) ?? options.level,
|
|
3011
|
-
stream
|
|
3012
|
-
};
|
|
3013
|
-
});
|
|
3014
|
-
return pino__default.default(pinoOptions, pino__default.default.multistream(streams));
|
|
3078
|
+
return pino__default.default(pinoOptions, pino__default.default.multistream(buildStreams(options, destinations, health)));
|
|
3015
3079
|
}
|
|
3016
3080
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3017
3081
|
function countInWindow(records, destination, now) {
|
|
@@ -3904,6 +3968,30 @@ function describeFailure(cause) {
|
|
|
3904
3968
|
return "unreadable value";
|
|
3905
3969
|
}
|
|
3906
3970
|
}
|
|
3971
|
+
function productionRefusal() {
|
|
3972
|
+
return new Error(
|
|
3973
|
+
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
3974
|
+
);
|
|
3975
|
+
}
|
|
3976
|
+
async function buildTransform(view) {
|
|
3977
|
+
const { build } = await import('pino-pretty');
|
|
3978
|
+
return build({
|
|
3979
|
+
...DEFAULT_VIEW,
|
|
3980
|
+
...view,
|
|
3981
|
+
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
3982
|
+
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
3983
|
+
// last is what ENFORCES it, including against an untyped caller reaching
|
|
3984
|
+
// in from JavaScript. A redirected stream would route around the fan-out
|
|
3985
|
+
// and the last-resort rescue.
|
|
3986
|
+
destination: process.stdout
|
|
3987
|
+
});
|
|
3988
|
+
}
|
|
3989
|
+
function initFailure(cause) {
|
|
3990
|
+
return new Error(
|
|
3991
|
+
isPinoPrettyMissing(cause) ? "[PrettyDevDestination] pino-pretty is not installed. Install it as a peer dependency (`pnpm add -D pino-pretty`) or remove PrettyDevDestination from `destinations`." : `[PrettyDevDestination] pino-pretty failed to start: ${describeFailure(cause)}`,
|
|
3992
|
+
{ cause }
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3907
3995
|
var PrettyDevDestination = class {
|
|
3908
3996
|
/**
|
|
3909
3997
|
* @param opts.minLevel — Optional minimum level filter applied by the
|
|
@@ -3960,28 +4048,13 @@ var PrettyDevDestination = class {
|
|
|
3960
4048
|
async onInit() {
|
|
3961
4049
|
if (process.env["NODE_ENV"] === "production") {
|
|
3962
4050
|
this.initFailed = true;
|
|
3963
|
-
throw
|
|
3964
|
-
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
3965
|
-
);
|
|
4051
|
+
throw productionRefusal();
|
|
3966
4052
|
}
|
|
3967
4053
|
try {
|
|
3968
|
-
|
|
3969
|
-
this.stream = build({
|
|
3970
|
-
...DEFAULT_VIEW,
|
|
3971
|
-
...this.view,
|
|
3972
|
-
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
3973
|
-
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
3974
|
-
// last is what ENFORCES it, including against an untyped caller reaching
|
|
3975
|
-
// in from JavaScript. A redirected stream would route around the fan-out
|
|
3976
|
-
// and the last-resort rescue.
|
|
3977
|
-
destination: process.stdout
|
|
3978
|
-
});
|
|
4054
|
+
this.stream = await buildTransform(this.view);
|
|
3979
4055
|
} catch (cause) {
|
|
3980
4056
|
this.initFailed = true;
|
|
3981
|
-
throw
|
|
3982
|
-
isPinoPrettyMissing(cause) ? "[PrettyDevDestination] pino-pretty is not installed. Install it as a peer dependency (`pnpm add -D pino-pretty`) or remove PrettyDevDestination from `destinations`." : `[PrettyDevDestination] pino-pretty failed to start: ${describeFailure(cause)}`,
|
|
3983
|
-
{ cause }
|
|
3984
|
-
);
|
|
4057
|
+
throw initFailure(cause);
|
|
3985
4058
|
}
|
|
3986
4059
|
this.flushBuffer((payload) => {
|
|
3987
4060
|
try {
|
|
@@ -4392,6 +4465,11 @@ function emitTimingLog(logger, method, duration, thresholdMs) {
|
|
|
4392
4465
|
}
|
|
4393
4466
|
}
|
|
4394
4467
|
function LogPerformance(thresholdMs = DEFAULT_THRESHOLD_MS) {
|
|
4468
|
+
if (!Number.isFinite(thresholdMs) || thresholdMs < 0) {
|
|
4469
|
+
throw new TypeError(
|
|
4470
|
+
"[LogPerformance] thresholdMs must be a finite number of milliseconds, zero or more"
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4395
4473
|
return (target, propertyKey, descriptor) => {
|
|
4396
4474
|
const original = descriptor.value;
|
|
4397
4475
|
const method = `${target.constructor.name}.${String(propertyKey)}`;
|
package/dist/server/index.d.cts
CHANGED
|
@@ -618,8 +618,28 @@ interface BymaxLoggerModuleOptions {
|
|
|
618
618
|
http?: HttpOptions;
|
|
619
619
|
/** OpenTelemetry integration tuning. */
|
|
620
620
|
otel?: OtelOptions;
|
|
621
|
-
/** Maximum size in bytes per log entry. Default: 65536. */
|
|
621
|
+
/** Maximum size in bytes per log entry: an integer from 1 to 2147483647. Default: 65536. */
|
|
622
622
|
maxEntrySizeBytes?: number;
|
|
623
|
+
/**
|
|
624
|
+
* The most characters a string of a log record is written with. A longer string is cut to this
|
|
625
|
+
* many characters, without splitting a surrogate pair, and ends with `…[truncated]`, so what is
|
|
626
|
+
* written is up to 12 characters longer than the limit. An integer from 64 to 2147483647.
|
|
627
|
+
* Default: not set, and a string is written whole.
|
|
628
|
+
*
|
|
629
|
+
* Applies to every string value of the record at any depth, but not to a key, a value that is
|
|
630
|
+
* not text, the log message (already capped at 16384 characters), the `logKey`, the bindings of a
|
|
631
|
+
* logger (the service identity and a `context`), a value a redaction rule censors, or anything
|
|
632
|
+
* under a key that has a serializer (`err` and the keys of `serializers`; see
|
|
633
|
+
* `maxEntrySizeBytes`), so the stack of an error logged under `err` is never cut by it. The event
|
|
634
|
+
* name and the `exception.*` and `error.type` fields the library writes are added after the cut,
|
|
635
|
+
* so the limit does not apply to them, and a key of your own with one of those names is cut like
|
|
636
|
+
* any other. The names left whole are matched on the root key, so a key of your own named like a
|
|
637
|
+
* serializer key is left whole too. An `Error` placed in the metadata under any other key is
|
|
638
|
+
* data of the record when the cut runs, and its message and stack are cut like any other string.
|
|
639
|
+
* A string the caller supplies, such as a `userId` longer than the limit, is cut like any other.
|
|
640
|
+
* A `redactCensor` longer than the limit is refused at startup, so a censor is never cut.
|
|
641
|
+
*/
|
|
642
|
+
maxStringLength?: number;
|
|
623
643
|
/**
|
|
624
644
|
* The longest a destination's `onInit` or `onRegistryReady` may take, in milliseconds. Default:
|
|
625
645
|
* 10000. An integer from 1 to 2147483647 (the largest delay a timer holds).
|
|
@@ -669,7 +689,8 @@ interface BymaxLoggerModuleOptions {
|
|
|
669
689
|
* middleware) consumes — distinct from the loosely-typed
|
|
670
690
|
* `BymaxLoggerModuleOptions` the consumer supplies.
|
|
671
691
|
*/
|
|
672
|
-
type ResolvedBymaxLoggerModuleOptions = Readonly<Required<Omit<BymaxLoggerModuleOptions, 'http' | 'otel' | 'shutdown' | 'destinationQueue'>> & {
|
|
692
|
+
type ResolvedBymaxLoggerModuleOptions = Readonly<Required<Omit<BymaxLoggerModuleOptions, 'http' | 'otel' | 'shutdown' | 'destinationQueue' | 'maxStringLength'>> & {
|
|
693
|
+
maxStringLength: number | undefined;
|
|
673
694
|
http: ResolvedHttpOptions;
|
|
674
695
|
otel: Required<OtelOptions>;
|
|
675
696
|
shutdown: Required<ShutdownOptions>;
|
|
@@ -1974,6 +1995,8 @@ declare const LogContext: (name: string) => CustomDecorator<string>;
|
|
|
1974
1995
|
* @param thresholdMs - Duration (ms) above which the call is logged as slow.
|
|
1975
1996
|
* Defaults to {@link DEFAULT_THRESHOLD_MS} (1000).
|
|
1976
1997
|
* @returns A method decorator that wraps the original implementation.
|
|
1998
|
+
* @throws TypeError When `thresholdMs` is not a finite number of zero or more: `NaN` or `Infinity`
|
|
1999
|
+
* would switch slow-call logging off, and a negative value would log every call as slow.
|
|
1977
2000
|
* @remarks The wrapped method always returns a `Promise` (see the file header):
|
|
1978
2001
|
* apply only to async methods or callers that can await the result.
|
|
1979
2002
|
* @example
|
package/dist/server/index.d.ts
CHANGED
|
@@ -618,8 +618,28 @@ interface BymaxLoggerModuleOptions {
|
|
|
618
618
|
http?: HttpOptions;
|
|
619
619
|
/** OpenTelemetry integration tuning. */
|
|
620
620
|
otel?: OtelOptions;
|
|
621
|
-
/** Maximum size in bytes per log entry. Default: 65536. */
|
|
621
|
+
/** Maximum size in bytes per log entry: an integer from 1 to 2147483647. Default: 65536. */
|
|
622
622
|
maxEntrySizeBytes?: number;
|
|
623
|
+
/**
|
|
624
|
+
* The most characters a string of a log record is written with. A longer string is cut to this
|
|
625
|
+
* many characters, without splitting a surrogate pair, and ends with `…[truncated]`, so what is
|
|
626
|
+
* written is up to 12 characters longer than the limit. An integer from 64 to 2147483647.
|
|
627
|
+
* Default: not set, and a string is written whole.
|
|
628
|
+
*
|
|
629
|
+
* Applies to every string value of the record at any depth, but not to a key, a value that is
|
|
630
|
+
* not text, the log message (already capped at 16384 characters), the `logKey`, the bindings of a
|
|
631
|
+
* logger (the service identity and a `context`), a value a redaction rule censors, or anything
|
|
632
|
+
* under a key that has a serializer (`err` and the keys of `serializers`; see
|
|
633
|
+
* `maxEntrySizeBytes`), so the stack of an error logged under `err` is never cut by it. The event
|
|
634
|
+
* name and the `exception.*` and `error.type` fields the library writes are added after the cut,
|
|
635
|
+
* so the limit does not apply to them, and a key of your own with one of those names is cut like
|
|
636
|
+
* any other. The names left whole are matched on the root key, so a key of your own named like a
|
|
637
|
+
* serializer key is left whole too. An `Error` placed in the metadata under any other key is
|
|
638
|
+
* data of the record when the cut runs, and its message and stack are cut like any other string.
|
|
639
|
+
* A string the caller supplies, such as a `userId` longer than the limit, is cut like any other.
|
|
640
|
+
* A `redactCensor` longer than the limit is refused at startup, so a censor is never cut.
|
|
641
|
+
*/
|
|
642
|
+
maxStringLength?: number;
|
|
623
643
|
/**
|
|
624
644
|
* The longest a destination's `onInit` or `onRegistryReady` may take, in milliseconds. Default:
|
|
625
645
|
* 10000. An integer from 1 to 2147483647 (the largest delay a timer holds).
|
|
@@ -669,7 +689,8 @@ interface BymaxLoggerModuleOptions {
|
|
|
669
689
|
* middleware) consumes — distinct from the loosely-typed
|
|
670
690
|
* `BymaxLoggerModuleOptions` the consumer supplies.
|
|
671
691
|
*/
|
|
672
|
-
type ResolvedBymaxLoggerModuleOptions = Readonly<Required<Omit<BymaxLoggerModuleOptions, 'http' | 'otel' | 'shutdown' | 'destinationQueue'>> & {
|
|
692
|
+
type ResolvedBymaxLoggerModuleOptions = Readonly<Required<Omit<BymaxLoggerModuleOptions, 'http' | 'otel' | 'shutdown' | 'destinationQueue' | 'maxStringLength'>> & {
|
|
693
|
+
maxStringLength: number | undefined;
|
|
673
694
|
http: ResolvedHttpOptions;
|
|
674
695
|
otel: Required<OtelOptions>;
|
|
675
696
|
shutdown: Required<ShutdownOptions>;
|
|
@@ -1974,6 +1995,8 @@ declare const LogContext: (name: string) => CustomDecorator<string>;
|
|
|
1974
1995
|
* @param thresholdMs - Duration (ms) above which the call is logged as slow.
|
|
1975
1996
|
* Defaults to {@link DEFAULT_THRESHOLD_MS} (1000).
|
|
1976
1997
|
* @returns A method decorator that wraps the original implementation.
|
|
1998
|
+
* @throws TypeError When `thresholdMs` is not a finite number of zero or more: `NaN` or `Infinity`
|
|
1999
|
+
* would switch slow-call logging off, and a negative value would log every call as slow.
|
|
1977
2000
|
* @remarks The wrapped method always returns a `Promise` (see the file header):
|
|
1978
2001
|
* apply only to async methods or callers that can await the result.
|
|
1979
2002
|
* @example
|
package/dist/server/index.mjs
CHANGED
|
@@ -29,6 +29,9 @@ var DEFAULT_DRAIN_TIMEOUT_MS = 5e3;
|
|
|
29
29
|
var DEFAULT_QUEUE_MAX_BYTES = 33554432;
|
|
30
30
|
var MIN_QUEUE_MAX_BYTES = 1024;
|
|
31
31
|
var MAX_QUEUE_MAX_BYTES = 2147483647;
|
|
32
|
+
var MAX_ENTRY_SIZE_BYTES = 2147483647;
|
|
33
|
+
var MIN_STRING_LENGTH_LIMIT = 64;
|
|
34
|
+
var MAX_STRING_LENGTH_LIMIT = 2147483647;
|
|
32
35
|
|
|
33
36
|
// src/server/config/default-options.ts
|
|
34
37
|
var DEFAULT_HTTP = {
|
|
@@ -98,6 +101,7 @@ function applyDefaults(options) {
|
|
|
98
101
|
}),
|
|
99
102
|
otel: Object.freeze(otel),
|
|
100
103
|
maxEntrySizeBytes: options.maxEntrySizeBytes ?? DEFAULT_MAX_ENTRY_SIZE_BYTES,
|
|
104
|
+
maxStringLength: options.maxStringLength,
|
|
101
105
|
destinationHookTimeoutMs: options.destinationHookTimeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS,
|
|
102
106
|
shutdown: resolveShutdown(options.shutdown),
|
|
103
107
|
destinationQueue: Object.freeze({
|
|
@@ -138,16 +142,27 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
|
|
|
138
142
|
|
|
139
143
|
// src/server/config/validate-options.ts
|
|
140
144
|
function reject(path2, rule, got) {
|
|
141
|
-
const received = got === void 0 ? "" : `.
|
|
145
|
+
const received = got === void 0 ? "" : `. Received ${describeValue(got)}`;
|
|
142
146
|
throw new Error(`[BymaxLoggerModule] options.${path2} ${rule}${received}`);
|
|
143
147
|
}
|
|
144
148
|
function describeValue(value) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
switch (typeof value) {
|
|
150
|
+
case "number":
|
|
151
|
+
return Number.isFinite(value) ? `the number ${String(value)}` : "a number that is not finite";
|
|
152
|
+
case "string":
|
|
153
|
+
return "a string";
|
|
154
|
+
case "boolean":
|
|
155
|
+
return "a boolean";
|
|
156
|
+
case "bigint":
|
|
157
|
+
return "a bigint";
|
|
158
|
+
case "symbol":
|
|
159
|
+
return "a symbol";
|
|
160
|
+
case "function":
|
|
161
|
+
return "a function";
|
|
162
|
+
default:
|
|
163
|
+
if (value === null) return "null";
|
|
164
|
+
return Array.isArray(value) ? "an array" : "an object";
|
|
165
|
+
}
|
|
151
166
|
}
|
|
152
167
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
153
168
|
var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
@@ -185,6 +200,24 @@ function validateQueue(options) {
|
|
|
185
200
|
);
|
|
186
201
|
}
|
|
187
202
|
}
|
|
203
|
+
function validateStringLimit(options) {
|
|
204
|
+
const limit = options.maxStringLength;
|
|
205
|
+
if (limit === void 0) return;
|
|
206
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < MIN_STRING_LENGTH_LIMIT || limit > MAX_STRING_LENGTH_LIMIT) {
|
|
207
|
+
reject(
|
|
208
|
+
"maxStringLength",
|
|
209
|
+
`must be an integer from ${String(MIN_STRING_LENGTH_LIMIT)} to ${String(MAX_STRING_LENGTH_LIMIT)}`,
|
|
210
|
+
limit
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const censor = options.redactCensor;
|
|
214
|
+
if (typeof censor === "string" && censor.length > limit) {
|
|
215
|
+
reject(
|
|
216
|
+
"redactCensor",
|
|
217
|
+
`must be at most ${String(limit)} characters when maxStringLength is set`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
188
221
|
function validateLifecycle(options) {
|
|
189
222
|
checkTimerMs("destinationHookTimeoutMs", options.destinationHookTimeoutMs);
|
|
190
223
|
const shutdown = checkGroup("shutdown", options.shutdown);
|
|
@@ -202,58 +235,46 @@ function validateLifecycle(options) {
|
|
|
202
235
|
}
|
|
203
236
|
}
|
|
204
237
|
function validateCore(options) {
|
|
205
|
-
|
|
238
|
+
const service = options.service;
|
|
239
|
+
if (service === void 0) {
|
|
206
240
|
throw new Error("[BymaxLoggerModule] options.service is required");
|
|
207
241
|
}
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
242
|
+
if (!isRecord(service)) reject("service", "must be an object", service);
|
|
243
|
+
for (const field of ["name", "version"]) {
|
|
244
|
+
const given = service[field];
|
|
245
|
+
if (typeof given !== "string" || given.trim() === "") {
|
|
246
|
+
reject(`service.${field}`, "must be a non-empty string", given);
|
|
247
|
+
}
|
|
213
248
|
}
|
|
214
249
|
if (options.level !== void 0 && !LOG_LEVEL_PRIORITY.includes(options.level)) {
|
|
215
|
-
|
|
216
|
-
`[BymaxLoggerModule] options.level must be one of: ${LOG_LEVEL_PRIORITY.join(
|
|
217
|
-
", "
|
|
218
|
-
)}. Got: ${String(options.level)}`
|
|
219
|
-
);
|
|
250
|
+
reject("level", `must be one of: ${LOG_LEVEL_PRIORITY.join(", ")}`, options.level);
|
|
220
251
|
}
|
|
221
252
|
const size = options.maxEntrySizeBytes;
|
|
222
253
|
if (size !== void 0 && !Number.isFinite(size)) {
|
|
223
254
|
reject("maxEntrySizeBytes", "must be a finite number", size);
|
|
224
255
|
}
|
|
225
256
|
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes <= 0) {
|
|
226
|
-
|
|
257
|
+
reject("maxEntrySizeBytes", "must be > 0", options.maxEntrySizeBytes);
|
|
258
|
+
}
|
|
259
|
+
if (size !== void 0 && !Number.isInteger(size)) {
|
|
260
|
+
reject("maxEntrySizeBytes", "must be an integer", size);
|
|
261
|
+
}
|
|
262
|
+
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes > MAX_ENTRY_SIZE_BYTES) {
|
|
263
|
+
reject("maxEntrySizeBytes", `must be at most ${String(MAX_ENTRY_SIZE_BYTES)}`, size);
|
|
227
264
|
}
|
|
228
265
|
}
|
|
229
266
|
function validateClosedSets(options) {
|
|
230
267
|
if (options.redactStrategy !== void 0 && options.redactStrategy !== "names" && options.redactStrategy !== "paths") {
|
|
231
|
-
|
|
232
|
-
`[BymaxLoggerModule] options.redactStrategy must be 'names' or 'paths'. Got: ${String(
|
|
233
|
-
options.redactStrategy
|
|
234
|
-
)}`
|
|
235
|
-
);
|
|
268
|
+
reject("redactStrategy", "must be 'names' or 'paths'", options.redactStrategy);
|
|
236
269
|
}
|
|
237
270
|
if (options.resourceFormat !== void 0 && options.resourceFormat !== "nested" && options.resourceFormat !== "flat") {
|
|
238
|
-
|
|
239
|
-
`[BymaxLoggerModule] options.resourceFormat must be 'nested' or 'flat'. Got: ${String(
|
|
240
|
-
options.resourceFormat
|
|
241
|
-
)}`
|
|
242
|
-
);
|
|
271
|
+
reject("resourceFormat", "must be 'nested' or 'flat'", options.resourceFormat);
|
|
243
272
|
}
|
|
244
273
|
if (options.errorFormat !== void 0 && options.errorFormat !== "pino" && options.errorFormat !== "semconv" && options.errorFormat !== "both") {
|
|
245
|
-
|
|
246
|
-
`[BymaxLoggerModule] options.errorFormat must be 'pino', 'semconv' or 'both'. Got: ${String(
|
|
247
|
-
options.errorFormat
|
|
248
|
-
)}`
|
|
249
|
-
);
|
|
274
|
+
reject("errorFormat", "must be 'pino', 'semconv' or 'both'", options.errorFormat);
|
|
250
275
|
}
|
|
251
276
|
if (options.eventNameField !== void 0 && options.eventNameField !== false && (typeof options.eventNameField !== "string" || options.eventNameField.length === 0)) {
|
|
252
|
-
|
|
253
|
-
`[BymaxLoggerModule] options.eventNameField must be a non-empty string or false. Got: ${String(
|
|
254
|
-
options.eventNameField
|
|
255
|
-
)}`
|
|
256
|
-
);
|
|
277
|
+
reject("eventNameField", "must be a non-empty string or false", options.eventNameField);
|
|
257
278
|
}
|
|
258
279
|
}
|
|
259
280
|
function validateCustomization(options) {
|
|
@@ -382,6 +403,7 @@ function validateOptions(options) {
|
|
|
382
403
|
validateDestinations(options);
|
|
383
404
|
validateLifecycle(options);
|
|
384
405
|
validateQueue(options);
|
|
406
|
+
validateStringLimit(options);
|
|
385
407
|
validateHttp(options);
|
|
386
408
|
validateOtel(options);
|
|
387
409
|
}
|
|
@@ -442,9 +464,9 @@ var TEXT_TRUNCATED = "\u2026[truncated]";
|
|
|
442
464
|
function cutIfText(value) {
|
|
443
465
|
return typeof value === "string" ? cutText(value) : value;
|
|
444
466
|
}
|
|
445
|
-
function cutText(text, alreadyCut = false) {
|
|
446
|
-
if (!alreadyCut && text.length <=
|
|
447
|
-
const head = text.slice(0,
|
|
467
|
+
function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
|
|
468
|
+
if (!alreadyCut && text.length <= limit) return text;
|
|
469
|
+
const head = text.slice(0, limit);
|
|
448
470
|
const last = head.charCodeAt(head.length - 1);
|
|
449
471
|
const whole = last >= 55296 && last <= 56319 ? head.slice(0, -1) : head;
|
|
450
472
|
return whole + TEXT_TRUNCATED;
|
|
@@ -2149,6 +2171,31 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2149
2171
|
const sources = shouldSkipDefaults ? [extraPaths] : [DEFAULT_REDACT_PATHS, extraPaths];
|
|
2150
2172
|
return Array.from(new Set(sources.flat()));
|
|
2151
2173
|
}
|
|
2174
|
+
|
|
2175
|
+
// 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
|
+
function cutNode(node, limit) {
|
|
2182
|
+
if (typeof node === "string") return cutText(node, false, limit);
|
|
2183
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
|
|
2184
|
+
if (isPlainRecord(node)) {
|
|
2185
|
+
return Object.fromEntries(
|
|
2186
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
return node;
|
|
2190
|
+
}
|
|
2191
|
+
function cutStrings(record, limit, exempt) {
|
|
2192
|
+
return Object.fromEntries(
|
|
2193
|
+
Object.entries(record).map(([key, child]) => [
|
|
2194
|
+
key,
|
|
2195
|
+
exempt.has(key) ? child : cutNode(child, limit)
|
|
2196
|
+
])
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2152
2199
|
function reportWriteFailure(destination, cause, due) {
|
|
2153
2200
|
const name = safeDestinationName(destination);
|
|
2154
2201
|
reportDestinationFailure(
|
|
@@ -2872,20 +2919,31 @@ var PASS_THROUGH = (value) => value;
|
|
|
2872
2919
|
function resolveNameRedactor(options) {
|
|
2873
2920
|
return buildNameRedactor(options, true, options.redactStrategy === "names");
|
|
2874
2921
|
}
|
|
2922
|
+
function resolveRecordRedactor(options) {
|
|
2923
|
+
return buildNameRedactor(
|
|
2924
|
+
options,
|
|
2925
|
+
true,
|
|
2926
|
+
options.redactStrategy === "names",
|
|
2927
|
+
options.maxStringLength !== void 0
|
|
2928
|
+
);
|
|
2929
|
+
}
|
|
2930
|
+
function wholeRootKeys(options) {
|
|
2931
|
+
return /* @__PURE__ */ new Set(["logKey", "err", ...Object.keys(options.serializers)]);
|
|
2932
|
+
}
|
|
2875
2933
|
function ownFieldPolicyOf(options) {
|
|
2876
2934
|
return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
|
|
2877
2935
|
}
|
|
2878
2936
|
function namesInsideErrors(options) {
|
|
2879
2937
|
return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
|
|
2880
2938
|
}
|
|
2881
|
-
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
|
|
2939
|
+
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true, forcesWalk = false) {
|
|
2882
2940
|
const allNames = [
|
|
2883
2941
|
...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
|
|
2884
2942
|
...options.redactPaths.flatMap((path2) => leafNameOf(path2) ?? [])
|
|
2885
2943
|
];
|
|
2886
2944
|
const names = coversNames ? allNames : [];
|
|
2887
2945
|
const ownFields = ownFieldPolicyOf(options);
|
|
2888
|
-
const walks = names.length > 0 || ownFields.safe;
|
|
2946
|
+
const walks = names.length > 0 || ownFields.safe || forcesWalk;
|
|
2889
2947
|
if (!walks && resolveRedactOption(options) === void 0) {
|
|
2890
2948
|
return PASS_THROUGH;
|
|
2891
2949
|
}
|
|
@@ -2914,14 +2972,10 @@ function resolveRedactOption(options) {
|
|
|
2914
2972
|
}
|
|
2915
2973
|
return { paths, censor: options.redactCensor };
|
|
2916
2974
|
}
|
|
2917
|
-
function
|
|
2975
|
+
function buildSerializers(options, redactSerialized, ownFields) {
|
|
2918
2976
|
const maxBytes = options.maxEntrySizeBytes;
|
|
2919
|
-
const redactRecord = resolveNameRedactor(options);
|
|
2920
|
-
const redactSerialized = buildNameRedactor(options);
|
|
2921
|
-
const ownFields = ownFieldPolicyOf(options);
|
|
2922
2977
|
const bound = (serializer) => createSizeBoundedSerializer((input) => redactSerialized(serializer(input)), maxBytes);
|
|
2923
|
-
|
|
2924
|
-
const serializers = {
|
|
2978
|
+
return {
|
|
2925
2979
|
err: bound((error) => serializeErrorValue(error, ownFields)),
|
|
2926
2980
|
...Object.fromEntries(
|
|
2927
2981
|
Object.entries(options.serializers).map(
|
|
@@ -2929,6 +2983,73 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
2929
2983
|
)
|
|
2930
2984
|
)
|
|
2931
2985
|
};
|
|
2986
|
+
}
|
|
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
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
function buildStreams(options, destinations, health) {
|
|
2999
|
+
return destinations.map((destination) => {
|
|
3000
|
+
const stream = destinationToStream(destination, health, options.destinationQueue.maxBytes);
|
|
3001
|
+
health.registerStream(destination, stream);
|
|
3002
|
+
return {
|
|
3003
|
+
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
3004
|
+
// consumer implementing `minLevel` as a throwing getter would fail the factory
|
|
3005
|
+
// and the application would never start — earlier than any fail-soft path can
|
|
3006
|
+
// contain. Unreadable and absent give the same answer: the module level.
|
|
3007
|
+
level: safeMinLevel(destination) ?? options.level,
|
|
3008
|
+
stream
|
|
3009
|
+
};
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
function buildRecordFormatter(options, redactRecord) {
|
|
3013
|
+
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3014
|
+
const maxStringLength = options.maxStringLength;
|
|
3015
|
+
const wholeRoots = wholeRootKeys(options);
|
|
3016
|
+
return (record) => {
|
|
3017
|
+
const redacted = redactRecord(
|
|
3018
|
+
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3019
|
+
true
|
|
3020
|
+
);
|
|
3021
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3022
|
+
return withSemconvException(withEventName(bounded, options.eventNameField), options.errorFormat);
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
function buildFormatters(options, redactRecord, redactBindings) {
|
|
3026
|
+
return {
|
|
3027
|
+
// Emit the level as a string label instead of the numeric code — easier
|
|
3028
|
+
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
3029
|
+
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
3030
|
+
level: (label) => ({ level: label }),
|
|
3031
|
+
// `base` bindings never reach `formatters.log` — Pino pre-serializes them
|
|
3032
|
+
// into the instance's `chindings`, the same reason `child()` has to redact
|
|
3033
|
+
// its own. That matters because `service` is CONSUMER-supplied and
|
|
3034
|
+
// `applyDefaults` keeps whatever it was given: a `{ name, version, apiKey }`
|
|
3035
|
+
// went out in clear, where the path expansion had covered it via `*.*.apiKey`.
|
|
3036
|
+
// Redacting here rather than trimming to the two declared fields keeps a
|
|
3037
|
+
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
3038
|
+
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
3039
|
+
// root, iterated rather than serialized.
|
|
3040
|
+
bindings: (bindings) => redactBindings(bindings, true),
|
|
3041
|
+
// The name-walk redactor runs here, on the merged record (mixin output +
|
|
3042
|
+
// the caller's object), which is exactly the surface a caller controls.
|
|
3043
|
+
// `base` and child bindings are NOT visible at this hook — they are
|
|
3044
|
+
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
3045
|
+
// sensitive, which `pino-factory.spec.ts` pins.
|
|
3046
|
+
log: buildRecordFormatter(options, redactRecord)
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
function buildPinoInstance(options, logContext, destinations, health) {
|
|
3050
|
+
const redactRecord = resolveRecordRedactor(options);
|
|
3051
|
+
const redactSerialized = buildNameRedactor(options);
|
|
3052
|
+
const ownFields = ownFieldPolicyOf(options);
|
|
2932
3053
|
const redactOption = resolveRedactOption(options);
|
|
2933
3054
|
const pinoOptions = {
|
|
2934
3055
|
level: options.level,
|
|
@@ -2946,69 +3067,12 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
2946
3067
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
2947
3068
|
// neither break the line nor add fields to it.
|
|
2948
3069
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
2949
|
-
formatters:
|
|
2950
|
-
|
|
2951
|
-
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
2952
|
-
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
2953
|
-
level: (label) => ({ level: label }),
|
|
2954
|
-
// `base` bindings never reach `formatters.log` — Pino pre-serializes them
|
|
2955
|
-
// into the instance's `chindings`, the same reason `child()` has to redact
|
|
2956
|
-
// its own. That matters because `service` is CONSUMER-supplied and
|
|
2957
|
-
// `applyDefaults` keeps whatever it was given: a `{ name, version, apiKey }`
|
|
2958
|
-
// went out in clear, where the path expansion had covered it via `*.*.apiKey`.
|
|
2959
|
-
// Redacting here rather than trimming to the two declared fields keeps a
|
|
2960
|
-
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
2961
|
-
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
2962
|
-
// root, iterated rather than serialized.
|
|
2963
|
-
bindings: (bindings) => redactRecord(bindings, true),
|
|
2964
|
-
// The name-walk redactor runs here, on the merged record (mixin output +
|
|
2965
|
-
// the caller's object), which is exactly the surface a caller controls.
|
|
2966
|
-
// `base` and child bindings are NOT visible at this hook — they are
|
|
2967
|
-
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
2968
|
-
// sensitive, which `pino-factory.spec.ts` pins.
|
|
2969
|
-
log: (record) => withSemconvException(
|
|
2970
|
-
withEventName(
|
|
2971
|
-
redactRecord(
|
|
2972
|
-
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
2973
|
-
true
|
|
2974
|
-
),
|
|
2975
|
-
options.eventNameField
|
|
2976
|
-
),
|
|
2977
|
-
options.errorFormat
|
|
2978
|
-
)
|
|
2979
|
-
},
|
|
2980
|
-
serializers,
|
|
3070
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3071
|
+
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
2981
3072
|
mixin: createTraceContextMixin(logContext, options.otel),
|
|
2982
|
-
|
|
2983
|
-
// merges the mixin result with it first, and the default strategy's
|
|
2984
|
-
// `Object.assign` invokes every own getter. A throwing getter therefore
|
|
2985
|
-
// crashed the log call before the redactor could return its fail-closed
|
|
2986
|
-
// envelope. Owning the merge moves that boundary inside the guarantee.
|
|
2987
|
-
mixinMergeStrategy: (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
|
-
}
|
|
2997
|
-
}
|
|
3073
|
+
mixinMergeStrategy: mergeMixinSafely
|
|
2998
3074
|
};
|
|
2999
|
-
|
|
3000
|
-
const stream = destinationToStream(destination, health, options.destinationQueue.maxBytes);
|
|
3001
|
-
health.registerStream(destination, stream);
|
|
3002
|
-
return {
|
|
3003
|
-
// Guarded: this runs at provider construction, BEFORE any lifecycle hook, so a
|
|
3004
|
-
// consumer implementing `minLevel` as a throwing getter would fail the factory
|
|
3005
|
-
// and the application would never start — earlier than any fail-soft path can
|
|
3006
|
-
// contain. Unreadable and absent give the same answer: the module level.
|
|
3007
|
-
level: safeMinLevel(destination) ?? options.level,
|
|
3008
|
-
stream
|
|
3009
|
-
};
|
|
3010
|
-
});
|
|
3011
|
-
return pino(pinoOptions, pino.multistream(streams));
|
|
3075
|
+
return pino(pinoOptions, pino.multistream(buildStreams(options, destinations, health)));
|
|
3012
3076
|
}
|
|
3013
3077
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3014
3078
|
function countInWindow(records, destination, now) {
|
|
@@ -3901,6 +3965,30 @@ function describeFailure(cause) {
|
|
|
3901
3965
|
return "unreadable value";
|
|
3902
3966
|
}
|
|
3903
3967
|
}
|
|
3968
|
+
function productionRefusal() {
|
|
3969
|
+
return new Error(
|
|
3970
|
+
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
3971
|
+
);
|
|
3972
|
+
}
|
|
3973
|
+
async function buildTransform(view) {
|
|
3974
|
+
const { build } = await import('pino-pretty');
|
|
3975
|
+
return build({
|
|
3976
|
+
...DEFAULT_VIEW,
|
|
3977
|
+
...view,
|
|
3978
|
+
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
3979
|
+
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
3980
|
+
// last is what ENFORCES it, including against an untyped caller reaching
|
|
3981
|
+
// in from JavaScript. A redirected stream would route around the fan-out
|
|
3982
|
+
// and the last-resort rescue.
|
|
3983
|
+
destination: process.stdout
|
|
3984
|
+
});
|
|
3985
|
+
}
|
|
3986
|
+
function initFailure(cause) {
|
|
3987
|
+
return new Error(
|
|
3988
|
+
isPinoPrettyMissing(cause) ? "[PrettyDevDestination] pino-pretty is not installed. Install it as a peer dependency (`pnpm add -D pino-pretty`) or remove PrettyDevDestination from `destinations`." : `[PrettyDevDestination] pino-pretty failed to start: ${describeFailure(cause)}`,
|
|
3989
|
+
{ cause }
|
|
3990
|
+
);
|
|
3991
|
+
}
|
|
3904
3992
|
var PrettyDevDestination = class {
|
|
3905
3993
|
/**
|
|
3906
3994
|
* @param opts.minLevel — Optional minimum level filter applied by the
|
|
@@ -3957,28 +4045,13 @@ var PrettyDevDestination = class {
|
|
|
3957
4045
|
async onInit() {
|
|
3958
4046
|
if (process.env["NODE_ENV"] === "production") {
|
|
3959
4047
|
this.initFailed = true;
|
|
3960
|
-
throw
|
|
3961
|
-
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
3962
|
-
);
|
|
4048
|
+
throw productionRefusal();
|
|
3963
4049
|
}
|
|
3964
4050
|
try {
|
|
3965
|
-
|
|
3966
|
-
this.stream = build({
|
|
3967
|
-
...DEFAULT_VIEW,
|
|
3968
|
-
...this.view,
|
|
3969
|
-
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
3970
|
-
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
3971
|
-
// last is what ENFORCES it, including against an untyped caller reaching
|
|
3972
|
-
// in from JavaScript. A redirected stream would route around the fan-out
|
|
3973
|
-
// and the last-resort rescue.
|
|
3974
|
-
destination: process.stdout
|
|
3975
|
-
});
|
|
4051
|
+
this.stream = await buildTransform(this.view);
|
|
3976
4052
|
} catch (cause) {
|
|
3977
4053
|
this.initFailed = true;
|
|
3978
|
-
throw
|
|
3979
|
-
isPinoPrettyMissing(cause) ? "[PrettyDevDestination] pino-pretty is not installed. Install it as a peer dependency (`pnpm add -D pino-pretty`) or remove PrettyDevDestination from `destinations`." : `[PrettyDevDestination] pino-pretty failed to start: ${describeFailure(cause)}`,
|
|
3980
|
-
{ cause }
|
|
3981
|
-
);
|
|
4054
|
+
throw initFailure(cause);
|
|
3982
4055
|
}
|
|
3983
4056
|
this.flushBuffer((payload) => {
|
|
3984
4057
|
try {
|
|
@@ -4389,6 +4462,11 @@ function emitTimingLog(logger, method, duration, thresholdMs) {
|
|
|
4389
4462
|
}
|
|
4390
4463
|
}
|
|
4391
4464
|
function LogPerformance(thresholdMs = DEFAULT_THRESHOLD_MS) {
|
|
4465
|
+
if (!Number.isFinite(thresholdMs) || thresholdMs < 0) {
|
|
4466
|
+
throw new TypeError(
|
|
4467
|
+
"[LogPerformance] thresholdMs must be a finite number of milliseconds, zero or more"
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4392
4470
|
return (target, propertyKey, descriptor) => {
|
|
4393
4471
|
const original = descriptor.value;
|
|
4394
4472
|
const method = `${target.constructor.name}.${String(propertyKey)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-logger",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.22",
|
|
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",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"check:mutants": "node scripts/check-mutation-directives.mjs",
|
|
63
63
|
"check:published": "node scripts/check-published-surface.mjs",
|
|
64
64
|
"check:file-length": "node scripts/check-file-length.mjs",
|
|
65
|
+
"check:function-length": "node scripts/check-function-length.mjs",
|
|
65
66
|
"check:spec-headers": "node scripts/check-spec-headers.mjs",
|
|
66
67
|
"check:suppressions": "node scripts/check-suppressions-baseline.mjs",
|
|
67
68
|
"clean": "rm -rf dist coverage",
|