@bymax-one/nest-logger 1.4.34 → 1.4.35
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 +17 -1
- package/README.md +3 -1
- package/dist/server/index.cjs +93 -23
- package/dist/server/index.mjs +93 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,21 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.35] - 2026-11-27
|
|
16
|
+
|
|
17
|
+
### Breaking
|
|
18
|
+
|
|
19
|
+
- **Behaviour change under `redactStrategy: 'names'`:** the `bindings` formatter and the serializers receive a redacted copy of the bindings instead of your objects. In the copy a `Date` arrives as a string, a `Map` as `{}` and a class instance can arrive as a plain object, so a callback that calls a method of one of these can throw. A value in bindings of the raw logger is written as `service.child()` writes it. Migration: have the callback read the copy (a `Date` is an ISO string), or compute the value before you pass it, for example `raw.child({ at: at.getTime() })`. `redactStrategy: 'paths'` keeps your objects, but bindings are then not redacted by name.
|
|
20
|
+
|
|
21
|
+
### Security
|
|
22
|
+
|
|
23
|
+
- **Under the default `redactStrategy: 'names'`, bindings passed to `child()` and `setBindings()` on the raw logger are now redacted.** Under both strategies, so is what the `serializers`, `formatters.log` and `formatters.level` of child options return.
|
|
24
|
+
- Under `redactStrategy: 'paths'`, bindings of the raw logger are handled as before: Pino's redact paths apply, and your own objects reach the formatters and serializers.
|
|
25
|
+
|
|
26
|
+
### Documentation
|
|
27
|
+
|
|
28
|
+
- **The message text is not redacted by name**: a value the raw logger formats into it is not walked. The `redact` and `msgPrefix` options of a child are applied as you set them.
|
|
29
|
+
|
|
15
30
|
## [1.4.34] - 2026-11-27
|
|
16
31
|
|
|
17
32
|
No behaviour change: the published JavaScript is byte-identical to `1.4.33`, and the type declarations differ in comments only.
|
|
@@ -3606,7 +3621,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
3606
3621
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
3607
3622
|
`release.yml`, Dependabot, and issue templates
|
|
3608
3623
|
|
|
3609
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3624
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.35...HEAD
|
|
3625
|
+
[1.4.35]: https://github.com/bymaxone/nest-logger/compare/v1.4.34...v1.4.35
|
|
3610
3626
|
[1.4.34]: https://github.com/bymaxone/nest-logger/compare/v1.4.33...v1.4.34
|
|
3611
3627
|
[1.4.33]: https://github.com/bymaxone/nest-logger/compare/v1.4.32...v1.4.33
|
|
3612
3628
|
[1.4.32]: https://github.com/bymaxone/nest-logger/compare/v1.4.31...v1.4.32
|
package/README.md
CHANGED
|
@@ -952,6 +952,8 @@ No name rule reaches the second case, and scanning values for secret-shaped text
|
|
|
952
952
|
|
|
953
953
|
`redactStrategy` governs **your** payload: the record, child bindings and the output of any serializer you supply. The built-in `err` serializer is always name-walked, even under `'paths'`, because the four-level ceiling cannot reach the depth of a `cause` chain. Under `'paths'`, an `Error` anywhere in the record is converted with the default names censored in its own fields and its `cause` chain at any depth, with your paths applied on top; non-`Error` data is matched only by the configured paths.
|
|
954
954
|
|
|
955
|
+
What you pass to `child()` and `setBindings()`, on the raw logger from `getRawLogger()` too, is redacted, and so is what the `formatters` and `serializers` of child options return. How bindings of the raw logger are redacted follows `redactStrategy`. Under `'names'` they are walked by name, and the `bindings` formatter and the serializers receive that redacted copy, not your objects: a `Date` as a string, a `Map` as `{}`. Under `'paths'`, `child()` of the raw logger leaves them to Pino's redact paths, and your own objects reach the formatters and serializers; the conversion `service.child()` applies does not happen there, so an `Error` under a key other than `err` is written without it, `errorOwnFields: 'safe'` is not applied to that `Error`, and a `Buffer` binding throws. `redact` and `msgPrefix` are applied as you set them: `redact` replaces the Pino paths for that child (under `redactStrategy: 'paths'`, that includes the ones that redact its bindings), and `msgPrefix` is your own text before each message. **The message text is not redacted by name**: a value the raw logger formats into it (`raw.info('user %o', user)`) is not walked, so pass it as a field instead.
|
|
956
|
+
|
|
955
957
|
#### A value interpolated into the message has no name to redact
|
|
956
958
|
|
|
957
959
|
```ts
|
|
@@ -1059,7 +1061,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1059
1061
|
| `warnStructured` | `(logKey, msg, userId?, meta?)` | Structured warn log — takes a **message string** |
|
|
1060
1062
|
| `errorStructured` | `(logKey, error, userId?, meta?)` | Structured error log — takes an **`Error`**, serialized to `err` |
|
|
1061
1063
|
|
|
1062
|
-
`meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them), `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` are written by the logger itself and are dropped from `meta`, as are `exception.type`, `exception.message`, `exception.stacktrace` and `error.type`, which the logger derives from an error and which are matched by their own spelling, whatever the case, and not folded further (`exceptionType` is a field of yours, and so is `event.name` on a call that has no log key), and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field. A key the logger writes from the request context or from the active span (`requestId`, `tenantId`, the trace fields) keeps the logger's value when the payload carries the same key, for `meta`, an object message and the raw Pino logger alike, except `userId`, which a call names as an argument and which wins over the one of the request context; a key the logger does not write, such as a `requestId` outside a request, keeps the payload's own value. A key that only spells one of these keys, or an owned key, is dropped like the key itself (`Level`, `log_key`, `trace_id` for `traceId`, `request.id` for `requestId`): names are compared with the case, the separators `_`, `.` and `-`, white space, control characters, combining marks and the characters that print as nothing folded, the compatibility forms Unicode defines read as the letter they stand for, and a short list of Cyrillic and Greek letters, the dotless `ı` and the small capitals drawn like a Latin one read as it (`trace id`, `trace\u200bId`, `RequestId`, `rеquestId`), and `service_name`, `service-version` and the other spellings of the dotted resource keys are the keys themselves (a key such as `service_tier`, which spells none of them, is yours), so a backend that normalises names cannot read the payload's copy as the logger's field. A lookalike letter that is not on the list is kept: the list is not every lookalike Unicode has. The raw Pino logger from `getRawLogger()` bypasses the owned-key guards of `meta` and of an object message, so a payload can still repeat `level`, `service` or `userId` there; the request and trace keys still win, and
|
|
1064
|
+
`meta` carries arbitrary fields, except that `logKey`, `userId` and `context` belong to the payload (read from the authenticated ALS scope, so a metadata bag cannot forge them), `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` are written by the logger itself and are dropped from `meta`, as are `exception.type`, `exception.message`, `exception.stacktrace` and `error.type`, which the logger derives from an error and which are matched by their own spelling, whatever the case, and not folded further (`exceptionType` is a field of yours, and so is `event.name` on a call that has no log key), and `__proto__`, `constructor` and `prototype` are dropped, since they name a prototype chain rather than a field. A key the logger writes from the request context or from the active span (`requestId`, `tenantId`, the trace fields) keeps the logger's value when the payload carries the same key, for `meta`, an object message and the raw Pino logger alike, except `userId`, which a call names as an argument and which wins over the one of the request context; a key the logger does not write, such as a `requestId` outside a request, keeps the payload's own value. A key that only spells one of these keys, or an owned key, is dropped like the key itself (`Level`, `log_key`, `trace_id` for `traceId`, `request.id` for `requestId`): names are compared with the case, the separators `_`, `.` and `-`, white space, control characters, combining marks and the characters that print as nothing folded, the compatibility forms Unicode defines read as the letter they stand for, and a short list of Cyrillic and Greek letters, the dotless `ı` and the small capitals drawn like a Latin one read as it (`trace id`, `trace\u200bId`, `RequestId`, `rеquestId`), and `service_name`, `service-version` and the other spellings of the dotted resource keys are the keys themselves (a key such as `service_tier`, which spells none of them, is yours), so a backend that normalises names cannot read the payload's copy as the logger's field. A lookalike letter that is not on the list is kept: the list is not every lookalike Unicode has. The raw Pino logger from `getRawLogger()` bypasses the owned-key guards of `meta` and of an object message, so a payload can still repeat `level`, `service` or `userId` there; the request and trace keys still win, and its fields are still redacted (its message text is not walked by name: see [what redaction covers](#what-redaction-covers-and-what-it-cannot)).
|
|
1063
1065
|
|
|
1064
1066
|
**NestJS `LoggerService` bridge** — the variadic contract NestJS calls, so `app.useLogger()` works. These take a message, not a log key.
|
|
1065
1067
|
|
package/dist/server/index.cjs
CHANGED
|
@@ -1381,8 +1381,8 @@ function writeName(value, level, host, depth2) {
|
|
|
1381
1381
|
const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
|
|
1382
1382
|
return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
|
|
1383
1383
|
}
|
|
1384
|
-
function addErrorParts(copy, error,
|
|
1385
|
-
const taken = capturedSet(
|
|
1384
|
+
function addErrorParts(copy, error, ownKeys2, host, depth2) {
|
|
1385
|
+
const taken = capturedSet(ownKeys2);
|
|
1386
1386
|
const level = linkDepths.get(error) ?? 0;
|
|
1387
1387
|
let incomplete = false;
|
|
1388
1388
|
const add = (key, covers, read, write = (value) => walkChainPart(value, level, host, depth2)) => {
|
|
@@ -3366,6 +3366,82 @@ function destinationToStream(destination, health, maxQueueBytes = 0, censorMessa
|
|
|
3366
3366
|
return stream;
|
|
3367
3367
|
}
|
|
3368
3368
|
|
|
3369
|
+
// src/server/utils/guard-child-bindings.util.ts
|
|
3370
|
+
var apply = Reflect.apply;
|
|
3371
|
+
var create = Object.create;
|
|
3372
|
+
var defineProperty2 = Object.defineProperty;
|
|
3373
|
+
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
|
3374
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
3375
|
+
var hasOwn2 = Object.hasOwn;
|
|
3376
|
+
var ownKeys = Reflect.ownKeys;
|
|
3377
|
+
function followedBy(run2, then) {
|
|
3378
|
+
if (typeof run2 !== "function") return run2;
|
|
3379
|
+
return function(...inputs) {
|
|
3380
|
+
return then(apply(run2, this, inputs));
|
|
3381
|
+
};
|
|
3382
|
+
}
|
|
3383
|
+
var asPassed = (value) => value;
|
|
3384
|
+
function replacing(source, replaced) {
|
|
3385
|
+
const descriptors = getOwnPropertyDescriptors(source);
|
|
3386
|
+
for (const key in replaced) descriptors[key] = { value: replaced[key] };
|
|
3387
|
+
for (const name of ownKeys(descriptors)) {
|
|
3388
|
+
descriptors[name] = bareDescriptor(descriptors[name]);
|
|
3389
|
+
}
|
|
3390
|
+
return create(getPrototypeOf(source), descriptors);
|
|
3391
|
+
}
|
|
3392
|
+
function guardFormatters(formatters, guard) {
|
|
3393
|
+
const { bindings, level, log } = formatters;
|
|
3394
|
+
return replacing(formatters, {
|
|
3395
|
+
bindings: followedBy(bindings, (output) => guard.redactBindings(output, true)),
|
|
3396
|
+
level: followedBy(level, (output) => guard.redactSerialized(output)),
|
|
3397
|
+
// A formatter that returns nothing is passed on as it is: Pino writes no fields for it.
|
|
3398
|
+
log: followedBy(
|
|
3399
|
+
log,
|
|
3400
|
+
(output) => output ? guard.formatRecord(output) : output
|
|
3401
|
+
)
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3404
|
+
function guardSerializers(serializers, redact) {
|
|
3405
|
+
const source = serializers;
|
|
3406
|
+
const guarded = {};
|
|
3407
|
+
for (const key in source) {
|
|
3408
|
+
const value = followedBy(source[key], (output) => redact(output));
|
|
3409
|
+
defineProperty2(guarded, key, bareDescriptor({ value, enumerable: true }));
|
|
3410
|
+
}
|
|
3411
|
+
return guarded;
|
|
3412
|
+
}
|
|
3413
|
+
function guardOptions2(options, guard) {
|
|
3414
|
+
if (typeof options !== "object" || options === null) return options;
|
|
3415
|
+
const { formatters, serializers } = options;
|
|
3416
|
+
const replaced = {};
|
|
3417
|
+
if (hasOwn2(options, "formatters") && formatters) {
|
|
3418
|
+
replaced["formatters"] = guardFormatters(formatters, guard);
|
|
3419
|
+
}
|
|
3420
|
+
if (hasOwn2(options, "serializers") && serializers) {
|
|
3421
|
+
replaced["serializers"] = guardSerializers(serializers, guard.redactSerialized);
|
|
3422
|
+
}
|
|
3423
|
+
return replacing(options, replaced);
|
|
3424
|
+
}
|
|
3425
|
+
function guardChildBindings(logger, redaction, options) {
|
|
3426
|
+
const guard = options.redactStrategy === "names" ? redaction : { ...redaction, redactBindings: asPassed };
|
|
3427
|
+
const nativeChild = logger.child;
|
|
3428
|
+
const nativeSetBindings = logger.setBindings;
|
|
3429
|
+
const redacted = (bindings) => bindings ? guard.redactBindings(bindings, true) : bindings;
|
|
3430
|
+
const child = function(bindings, options2) {
|
|
3431
|
+
return apply(nativeChild, this, [
|
|
3432
|
+
redacted(bindings),
|
|
3433
|
+
guardOptions2(options2, guard)
|
|
3434
|
+
]);
|
|
3435
|
+
};
|
|
3436
|
+
const setBindings = function(bindings) {
|
|
3437
|
+
apply(nativeSetBindings, this, [redacted(bindings)]);
|
|
3438
|
+
};
|
|
3439
|
+
const open = { writable: true, configurable: true };
|
|
3440
|
+
defineProperty2(logger, "child", bareDescriptor({ ...open, value: child }));
|
|
3441
|
+
defineProperty2(logger, "setBindings", bareDescriptor({ ...open, value: setBindings }));
|
|
3442
|
+
return logger;
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3369
3445
|
// src/server/utils/merge-mixin-safely.util.ts
|
|
3370
3446
|
var PROTOTYPE_KEY = "__proto__";
|
|
3371
3447
|
var EXPLICIT_USER_KEY = "userId";
|
|
@@ -4100,28 +4176,19 @@ function buildRecordFormatter(options, redactRecord, onTruncate) {
|
|
|
4100
4176
|
);
|
|
4101
4177
|
};
|
|
4102
4178
|
}
|
|
4103
|
-
function buildFormatters(
|
|
4179
|
+
function buildFormatters(redactBindings, formatRecord) {
|
|
4104
4180
|
return {
|
|
4105
|
-
//
|
|
4106
|
-
//
|
|
4107
|
-
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
4181
|
+
// The level as a label, easier for log aggregators. Trace context comes from `mixin`:
|
|
4182
|
+
// `formatters.log` cannot see ambient ALS / OTel state.
|
|
4108
4183
|
level: (label) => ({ level: label }),
|
|
4109
|
-
// `base` bindings never reach `formatters.log
|
|
4110
|
-
//
|
|
4111
|
-
//
|
|
4112
|
-
//
|
|
4113
|
-
//
|
|
4114
|
-
// Redacting here rather than trimming to the two declared fields keeps a
|
|
4115
|
-
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
4116
|
-
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
4117
|
-
// root, iterated rather than serialized.
|
|
4184
|
+
// `base` bindings never reach `formatters.log`: Pino pre-serializes them into `chindings`.
|
|
4185
|
+
// `service` is CONSUMER-supplied and `applyDefaults` keeps whatever it was given, so a
|
|
4186
|
+
// `{ name, version, apiKey }` is redacted here, which keeps the consumer's extra metadata
|
|
4187
|
+
// where trimming to the two declared fields would drop it. Runs ONCE, at logger
|
|
4188
|
+
// construction. `true`: bindings are a record root, iterated rather than serialized.
|
|
4118
4189
|
bindings: (bindings) => redactBindings(bindings, true),
|
|
4119
|
-
// The
|
|
4120
|
-
|
|
4121
|
-
// `base` and child bindings are NOT visible at this hook — they are
|
|
4122
|
-
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
4123
|
-
// sensitive, which `pino-factory.spec.ts` pins.
|
|
4124
|
-
log: buildRecordFormatter(options, redactRecord, onTruncate)
|
|
4190
|
+
// The record, not bindings: `base` is redacted above, and a child's by `guardChildBindings`.
|
|
4191
|
+
log: formatRecord
|
|
4125
4192
|
};
|
|
4126
4193
|
}
|
|
4127
4194
|
var UNSET_PINO_NAMES = {
|
|
@@ -4144,9 +4211,11 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
4144
4211
|
refuseUnsafeOptions(options);
|
|
4145
4212
|
const redactRecord = resolveRecordRedactor(options);
|
|
4146
4213
|
const redactSerialized = buildNameRedactor(options);
|
|
4214
|
+
const redactBindings = resolveNameRedactor(options);
|
|
4147
4215
|
const ownFields = ownFieldPolicyOf(options);
|
|
4148
4216
|
const redactOption = resolveRedactOption(options);
|
|
4149
4217
|
const onTruncate = (reason) => health.recordTruncation(reason);
|
|
4218
|
+
const formatRecord = buildRecordFormatter(options, redactRecord, onTruncate);
|
|
4150
4219
|
const pinoOptions = {
|
|
4151
4220
|
level: options.level,
|
|
4152
4221
|
...redactOption === void 0 ? {} : { redact: { ...redactOption, remove: false } },
|
|
@@ -4163,13 +4232,14 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
4163
4232
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
4164
4233
|
// neither break the line nor add fields to it.
|
|
4165
4234
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
4166
|
-
formatters: buildFormatters(
|
|
4235
|
+
formatters: buildFormatters(redactBindings, formatRecord),
|
|
4167
4236
|
serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
|
|
4168
4237
|
mixin: buildTraceMixin(logContext, options),
|
|
4169
4238
|
mixinMergeStrategy: mergeMixinSafely
|
|
4170
4239
|
};
|
|
4171
4240
|
const streams = pino__default.default.multistream(buildStreams(options, destinations, health));
|
|
4172
|
-
|
|
4241
|
+
const logger = withEntryTextFinisher(pino__default.default(pinoOptions, streams), options, onTruncate);
|
|
4242
|
+
return guardChildBindings(logger, { redactBindings, redactSerialized, formatRecord }, options);
|
|
4173
4243
|
}
|
|
4174
4244
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
4175
4245
|
function countInWindow(records, destination, now) {
|
package/dist/server/index.mjs
CHANGED
|
@@ -1378,8 +1378,8 @@ function writeName(value, level, host, depth2) {
|
|
|
1378
1378
|
const censored = host.censorName(typeof value === "string" ? cutText(value) : value);
|
|
1379
1379
|
return censored === value ? cutOrWalk(value, level, host, depth2) : censored;
|
|
1380
1380
|
}
|
|
1381
|
-
function addErrorParts(copy, error,
|
|
1382
|
-
const taken = capturedSet(
|
|
1381
|
+
function addErrorParts(copy, error, ownKeys2, host, depth2) {
|
|
1382
|
+
const taken = capturedSet(ownKeys2);
|
|
1383
1383
|
const level = linkDepths.get(error) ?? 0;
|
|
1384
1384
|
let incomplete = false;
|
|
1385
1385
|
const add = (key, covers, read, write = (value) => walkChainPart(value, level, host, depth2)) => {
|
|
@@ -3363,6 +3363,82 @@ function destinationToStream(destination, health, maxQueueBytes = 0, censorMessa
|
|
|
3363
3363
|
return stream;
|
|
3364
3364
|
}
|
|
3365
3365
|
|
|
3366
|
+
// src/server/utils/guard-child-bindings.util.ts
|
|
3367
|
+
var apply = Reflect.apply;
|
|
3368
|
+
var create = Object.create;
|
|
3369
|
+
var defineProperty2 = Object.defineProperty;
|
|
3370
|
+
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
|
3371
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
3372
|
+
var hasOwn2 = Object.hasOwn;
|
|
3373
|
+
var ownKeys = Reflect.ownKeys;
|
|
3374
|
+
function followedBy(run2, then) {
|
|
3375
|
+
if (typeof run2 !== "function") return run2;
|
|
3376
|
+
return function(...inputs) {
|
|
3377
|
+
return then(apply(run2, this, inputs));
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
var asPassed = (value) => value;
|
|
3381
|
+
function replacing(source, replaced) {
|
|
3382
|
+
const descriptors = getOwnPropertyDescriptors(source);
|
|
3383
|
+
for (const key in replaced) descriptors[key] = { value: replaced[key] };
|
|
3384
|
+
for (const name of ownKeys(descriptors)) {
|
|
3385
|
+
descriptors[name] = bareDescriptor(descriptors[name]);
|
|
3386
|
+
}
|
|
3387
|
+
return create(getPrototypeOf(source), descriptors);
|
|
3388
|
+
}
|
|
3389
|
+
function guardFormatters(formatters, guard) {
|
|
3390
|
+
const { bindings, level, log } = formatters;
|
|
3391
|
+
return replacing(formatters, {
|
|
3392
|
+
bindings: followedBy(bindings, (output) => guard.redactBindings(output, true)),
|
|
3393
|
+
level: followedBy(level, (output) => guard.redactSerialized(output)),
|
|
3394
|
+
// A formatter that returns nothing is passed on as it is: Pino writes no fields for it.
|
|
3395
|
+
log: followedBy(
|
|
3396
|
+
log,
|
|
3397
|
+
(output) => output ? guard.formatRecord(output) : output
|
|
3398
|
+
)
|
|
3399
|
+
});
|
|
3400
|
+
}
|
|
3401
|
+
function guardSerializers(serializers, redact) {
|
|
3402
|
+
const source = serializers;
|
|
3403
|
+
const guarded = {};
|
|
3404
|
+
for (const key in source) {
|
|
3405
|
+
const value = followedBy(source[key], (output) => redact(output));
|
|
3406
|
+
defineProperty2(guarded, key, bareDescriptor({ value, enumerable: true }));
|
|
3407
|
+
}
|
|
3408
|
+
return guarded;
|
|
3409
|
+
}
|
|
3410
|
+
function guardOptions2(options, guard) {
|
|
3411
|
+
if (typeof options !== "object" || options === null) return options;
|
|
3412
|
+
const { formatters, serializers } = options;
|
|
3413
|
+
const replaced = {};
|
|
3414
|
+
if (hasOwn2(options, "formatters") && formatters) {
|
|
3415
|
+
replaced["formatters"] = guardFormatters(formatters, guard);
|
|
3416
|
+
}
|
|
3417
|
+
if (hasOwn2(options, "serializers") && serializers) {
|
|
3418
|
+
replaced["serializers"] = guardSerializers(serializers, guard.redactSerialized);
|
|
3419
|
+
}
|
|
3420
|
+
return replacing(options, replaced);
|
|
3421
|
+
}
|
|
3422
|
+
function guardChildBindings(logger, redaction, options) {
|
|
3423
|
+
const guard = options.redactStrategy === "names" ? redaction : { ...redaction, redactBindings: asPassed };
|
|
3424
|
+
const nativeChild = logger.child;
|
|
3425
|
+
const nativeSetBindings = logger.setBindings;
|
|
3426
|
+
const redacted = (bindings) => bindings ? guard.redactBindings(bindings, true) : bindings;
|
|
3427
|
+
const child = function(bindings, options2) {
|
|
3428
|
+
return apply(nativeChild, this, [
|
|
3429
|
+
redacted(bindings),
|
|
3430
|
+
guardOptions2(options2, guard)
|
|
3431
|
+
]);
|
|
3432
|
+
};
|
|
3433
|
+
const setBindings = function(bindings) {
|
|
3434
|
+
apply(nativeSetBindings, this, [redacted(bindings)]);
|
|
3435
|
+
};
|
|
3436
|
+
const open = { writable: true, configurable: true };
|
|
3437
|
+
defineProperty2(logger, "child", bareDescriptor({ ...open, value: child }));
|
|
3438
|
+
defineProperty2(logger, "setBindings", bareDescriptor({ ...open, value: setBindings }));
|
|
3439
|
+
return logger;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3366
3442
|
// src/server/utils/merge-mixin-safely.util.ts
|
|
3367
3443
|
var PROTOTYPE_KEY = "__proto__";
|
|
3368
3444
|
var EXPLICIT_USER_KEY = "userId";
|
|
@@ -4097,28 +4173,19 @@ function buildRecordFormatter(options, redactRecord, onTruncate) {
|
|
|
4097
4173
|
);
|
|
4098
4174
|
};
|
|
4099
4175
|
}
|
|
4100
|
-
function buildFormatters(
|
|
4176
|
+
function buildFormatters(redactBindings, formatRecord) {
|
|
4101
4177
|
return {
|
|
4102
|
-
//
|
|
4103
|
-
//
|
|
4104
|
-
// `formatters.log` (which cannot see ambient ALS / OTel state).
|
|
4178
|
+
// The level as a label, easier for log aggregators. Trace context comes from `mixin`:
|
|
4179
|
+
// `formatters.log` cannot see ambient ALS / OTel state.
|
|
4105
4180
|
level: (label) => ({ level: label }),
|
|
4106
|
-
// `base` bindings never reach `formatters.log
|
|
4107
|
-
//
|
|
4108
|
-
//
|
|
4109
|
-
//
|
|
4110
|
-
//
|
|
4111
|
-
// Redacting here rather than trimming to the two declared fields keeps a
|
|
4112
|
-
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
4113
|
-
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
4114
|
-
// root, iterated rather than serialized.
|
|
4181
|
+
// `base` bindings never reach `formatters.log`: Pino pre-serializes them into `chindings`.
|
|
4182
|
+
// `service` is CONSUMER-supplied and `applyDefaults` keeps whatever it was given, so a
|
|
4183
|
+
// `{ name, version, apiKey }` is redacted here, which keeps the consumer's extra metadata
|
|
4184
|
+
// where trimming to the two declared fields would drop it. Runs ONCE, at logger
|
|
4185
|
+
// construction. `true`: bindings are a record root, iterated rather than serialized.
|
|
4115
4186
|
bindings: (bindings) => redactBindings(bindings, true),
|
|
4116
|
-
// The
|
|
4117
|
-
|
|
4118
|
-
// `base` and child bindings are NOT visible at this hook — they are
|
|
4119
|
-
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
4120
|
-
// sensitive, which `pino-factory.spec.ts` pins.
|
|
4121
|
-
log: buildRecordFormatter(options, redactRecord, onTruncate)
|
|
4187
|
+
// The record, not bindings: `base` is redacted above, and a child's by `guardChildBindings`.
|
|
4188
|
+
log: formatRecord
|
|
4122
4189
|
};
|
|
4123
4190
|
}
|
|
4124
4191
|
var UNSET_PINO_NAMES = {
|
|
@@ -4141,9 +4208,11 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
4141
4208
|
refuseUnsafeOptions(options);
|
|
4142
4209
|
const redactRecord = resolveRecordRedactor(options);
|
|
4143
4210
|
const redactSerialized = buildNameRedactor(options);
|
|
4211
|
+
const redactBindings = resolveNameRedactor(options);
|
|
4144
4212
|
const ownFields = ownFieldPolicyOf(options);
|
|
4145
4213
|
const redactOption = resolveRedactOption(options);
|
|
4146
4214
|
const onTruncate = (reason) => health.recordTruncation(reason);
|
|
4215
|
+
const formatRecord = buildRecordFormatter(options, redactRecord, onTruncate);
|
|
4147
4216
|
const pinoOptions = {
|
|
4148
4217
|
level: options.level,
|
|
4149
4218
|
...redactOption === void 0 ? {} : { redact: { ...redactOption, remove: false } },
|
|
@@ -4160,13 +4229,14 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
4160
4229
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
4161
4230
|
// neither break the line nor add fields to it.
|
|
4162
4231
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
4163
|
-
formatters: buildFormatters(
|
|
4232
|
+
formatters: buildFormatters(redactBindings, formatRecord),
|
|
4164
4233
|
serializers: buildSerializers(options, redactSerialized, ownFields, onTruncate),
|
|
4165
4234
|
mixin: buildTraceMixin(logContext, options),
|
|
4166
4235
|
mixinMergeStrategy: mergeMixinSafely
|
|
4167
4236
|
};
|
|
4168
4237
|
const streams = pino.multistream(buildStreams(options, destinations, health));
|
|
4169
|
-
|
|
4238
|
+
const logger = withEntryTextFinisher(pino(pinoOptions, streams), options, onTruncate);
|
|
4239
|
+
return guardChildBindings(logger, { redactBindings, redactSerialized, formatRecord }, options);
|
|
4170
4240
|
}
|
|
4171
4241
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
4172
4242
|
function countInWindow(records, destination, now) {
|
package/package.json
CHANGED