@bymax-one/nest-logger 1.4.21 → 1.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +157 -1
- package/README.md +14 -3
- package/dist/server/index.cjs +340 -137
- package/dist/server/index.d.cts +33 -17
- package/dist/server/index.d.ts +33 -17
- package/dist/server/index.mjs +340 -137
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -25,6 +25,73 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
25
25
|
};
|
|
26
26
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
27
27
|
|
|
28
|
+
// src/server/config/drop-unset-options.ts
|
|
29
|
+
var OPTION_KEYS = {
|
|
30
|
+
service: true,
|
|
31
|
+
level: true,
|
|
32
|
+
isGlobal: true,
|
|
33
|
+
shouldUseAsNestLogger: true,
|
|
34
|
+
redactPaths: true,
|
|
35
|
+
redactStrategy: true,
|
|
36
|
+
resourceFormat: true,
|
|
37
|
+
eventNameField: true,
|
|
38
|
+
errorFormat: true,
|
|
39
|
+
redactCensor: true,
|
|
40
|
+
shouldDisableDefaultRedact: true,
|
|
41
|
+
destinations: true,
|
|
42
|
+
http: true,
|
|
43
|
+
otel: true,
|
|
44
|
+
maxEntrySizeBytes: true,
|
|
45
|
+
maxStringLength: true,
|
|
46
|
+
destinationHookTimeoutMs: true,
|
|
47
|
+
shutdown: true,
|
|
48
|
+
destinationQueue: true,
|
|
49
|
+
errorOwnFields: true,
|
|
50
|
+
errorOwnFieldNames: true,
|
|
51
|
+
serializers: true,
|
|
52
|
+
timestamp: true
|
|
53
|
+
};
|
|
54
|
+
var GROUP_KEYS = {
|
|
55
|
+
http: {
|
|
56
|
+
isEnabled: true,
|
|
57
|
+
shouldCaptureExceptions: true,
|
|
58
|
+
shouldGenerateRequestId: true,
|
|
59
|
+
excludePaths: true,
|
|
60
|
+
secretPathSegments: true,
|
|
61
|
+
tenantIdHeader: true,
|
|
62
|
+
tenantIdResolver: true
|
|
63
|
+
},
|
|
64
|
+
otel: {
|
|
65
|
+
shouldAutoInjectTraceContext: true,
|
|
66
|
+
fieldFormat: true,
|
|
67
|
+
traceIdField: true,
|
|
68
|
+
spanIdField: true,
|
|
69
|
+
traceFlagsField: true
|
|
70
|
+
},
|
|
71
|
+
shutdown: { timeoutMs: true, drainTimeoutMs: true },
|
|
72
|
+
destinationQueue: { maxBytes: true }
|
|
73
|
+
};
|
|
74
|
+
var GROUP_NAMES = Object.keys(GROUP_KEYS);
|
|
75
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
76
|
+
function readSet(source, keys) {
|
|
77
|
+
const set = {};
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
const value = Reflect.get(source, key);
|
|
80
|
+
if (value !== void 0 && value !== null) Reflect.set(set, key, value);
|
|
81
|
+
}
|
|
82
|
+
return set;
|
|
83
|
+
}
|
|
84
|
+
function dropUnsetOptions(options) {
|
|
85
|
+
if (!isRecord(options)) return options;
|
|
86
|
+
const set = readSet(options, Object.keys(OPTION_KEYS));
|
|
87
|
+
for (const group of GROUP_NAMES) {
|
|
88
|
+
const value = Reflect.get(set, group);
|
|
89
|
+
if (isRecord(value))
|
|
90
|
+
Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
|
|
91
|
+
}
|
|
92
|
+
return set;
|
|
93
|
+
}
|
|
94
|
+
|
|
28
95
|
// src/server/constants/lifecycle-timeouts.constants.ts
|
|
29
96
|
var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
|
|
30
97
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
@@ -32,6 +99,9 @@ var DEFAULT_DRAIN_TIMEOUT_MS = 5e3;
|
|
|
32
99
|
var DEFAULT_QUEUE_MAX_BYTES = 33554432;
|
|
33
100
|
var MIN_QUEUE_MAX_BYTES = 1024;
|
|
34
101
|
var MAX_QUEUE_MAX_BYTES = 2147483647;
|
|
102
|
+
var MAX_ENTRY_SIZE_BYTES = 2147483647;
|
|
103
|
+
var MIN_STRING_LENGTH_LIMIT = 64;
|
|
104
|
+
var MAX_STRING_LENGTH_LIMIT = 2147483647;
|
|
35
105
|
|
|
36
106
|
// src/server/config/default-options.ts
|
|
37
107
|
var DEFAULT_HTTP = {
|
|
@@ -69,7 +139,8 @@ function applyOtelFieldFormat(merged, user) {
|
|
|
69
139
|
}
|
|
70
140
|
return merged;
|
|
71
141
|
}
|
|
72
|
-
function applyDefaults(
|
|
142
|
+
function applyDefaults(given) {
|
|
143
|
+
const options = dropUnsetOptions(given);
|
|
73
144
|
const isProduction = process.env["NODE_ENV"] === "production";
|
|
74
145
|
const http = { ...DEFAULT_HTTP, ...options.http ?? {} };
|
|
75
146
|
const otel = applyOtelFieldFormat(
|
|
@@ -101,6 +172,7 @@ function applyDefaults(options) {
|
|
|
101
172
|
}),
|
|
102
173
|
otel: Object.freeze(otel),
|
|
103
174
|
maxEntrySizeBytes: options.maxEntrySizeBytes ?? DEFAULT_MAX_ENTRY_SIZE_BYTES,
|
|
175
|
+
maxStringLength: options.maxStringLength,
|
|
104
176
|
destinationHookTimeoutMs: options.destinationHookTimeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS,
|
|
105
177
|
shutdown: resolveShutdown(options.shutdown),
|
|
106
178
|
destinationQueue: Object.freeze({
|
|
@@ -140,19 +212,32 @@ var LOG_LEVEL_PRIORITY = Object.freeze([
|
|
|
140
212
|
]);
|
|
141
213
|
|
|
142
214
|
// src/server/config/validate-options.ts
|
|
143
|
-
function reject(path, rule, got) {
|
|
144
|
-
const received =
|
|
215
|
+
function reject(path, rule, got, wasGiven = got !== void 0) {
|
|
216
|
+
const received = wasGiven ? `. Received ${describeValue(got)}` : "";
|
|
145
217
|
throw new Error(`[BymaxLoggerModule] options.${path} ${rule}${received}`);
|
|
146
218
|
}
|
|
147
219
|
function describeValue(value) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
220
|
+
switch (typeof value) {
|
|
221
|
+
case "number":
|
|
222
|
+
return Number.isFinite(value) ? `the number ${String(value)}` : "a number that is not finite";
|
|
223
|
+
case "string":
|
|
224
|
+
return "a string";
|
|
225
|
+
case "boolean":
|
|
226
|
+
return "a boolean";
|
|
227
|
+
case "bigint":
|
|
228
|
+
return "a bigint";
|
|
229
|
+
case "symbol":
|
|
230
|
+
return "a symbol";
|
|
231
|
+
case "function":
|
|
232
|
+
return "a function";
|
|
233
|
+
case "undefined":
|
|
234
|
+
return "undefined";
|
|
235
|
+
default:
|
|
236
|
+
if (value === null) return "null";
|
|
237
|
+
return Array.isArray(value) ? "an array" : "an object";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
156
241
|
var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
157
242
|
function checkBoolean(path, value) {
|
|
158
243
|
if (value !== void 0 && typeof value !== "boolean") {
|
|
@@ -166,7 +251,7 @@ function checkNonEmptyString(path, value) {
|
|
|
166
251
|
}
|
|
167
252
|
function checkGroup(path, value) {
|
|
168
253
|
if (value === void 0) return void 0;
|
|
169
|
-
if (!
|
|
254
|
+
if (!isRecord2(value)) reject(path, "must be an object", value);
|
|
170
255
|
return value;
|
|
171
256
|
}
|
|
172
257
|
var MAX_TIMER_MS = 2147483647;
|
|
@@ -188,6 +273,26 @@ function validateQueue(options) {
|
|
|
188
273
|
);
|
|
189
274
|
}
|
|
190
275
|
}
|
|
276
|
+
function validateStringLimit(options) {
|
|
277
|
+
const limit = options.maxStringLength;
|
|
278
|
+
if (limit === void 0) return;
|
|
279
|
+
if (typeof limit !== "number" || !Number.isInteger(limit) || limit < MIN_STRING_LENGTH_LIMIT || limit > MAX_STRING_LENGTH_LIMIT) {
|
|
280
|
+
reject(
|
|
281
|
+
"maxStringLength",
|
|
282
|
+
`must be an integer from ${String(MIN_STRING_LENGTH_LIMIT)} to ${String(MAX_STRING_LENGTH_LIMIT)}`,
|
|
283
|
+
limit
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
refuseCensorBeyondLimit(options.redactCensor, limit);
|
|
287
|
+
}
|
|
288
|
+
function refuseCensorBeyondLimit(censor, limit) {
|
|
289
|
+
if (typeof censor === "string" && censor.length > limit) {
|
|
290
|
+
reject(
|
|
291
|
+
"redactCensor",
|
|
292
|
+
`must be at most ${String(limit)} characters when maxStringLength is set`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
191
296
|
function validateLifecycle(options) {
|
|
192
297
|
checkTimerMs("destinationHookTimeoutMs", options.destinationHookTimeoutMs);
|
|
193
298
|
const shutdown = checkGroup("shutdown", options.shutdown);
|
|
@@ -205,61 +310,46 @@ function validateLifecycle(options) {
|
|
|
205
310
|
}
|
|
206
311
|
}
|
|
207
312
|
function validateCore(options) {
|
|
208
|
-
|
|
313
|
+
const service = options.service;
|
|
314
|
+
if (service === void 0) {
|
|
209
315
|
throw new Error("[BymaxLoggerModule] options.service is required");
|
|
210
316
|
}
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
317
|
+
if (!isRecord2(service)) reject("service", "must be an object", service);
|
|
318
|
+
for (const field of ["name", "version"]) {
|
|
319
|
+
const given = service[field];
|
|
320
|
+
if (typeof given !== "string" || given.trim() === "") {
|
|
321
|
+
reject(`service.${field}`, "must be a non-empty string", given);
|
|
322
|
+
}
|
|
216
323
|
}
|
|
217
324
|
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
|
-
);
|
|
325
|
+
reject("level", `must be one of: ${LOG_LEVEL_PRIORITY.join(", ")}`, options.level);
|
|
223
326
|
}
|
|
224
327
|
const size = options.maxEntrySizeBytes;
|
|
225
328
|
if (size !== void 0 && !Number.isFinite(size)) {
|
|
226
329
|
reject("maxEntrySizeBytes", "must be a finite number", size);
|
|
227
330
|
}
|
|
228
331
|
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes <= 0) {
|
|
229
|
-
|
|
332
|
+
reject("maxEntrySizeBytes", "must be > 0", options.maxEntrySizeBytes);
|
|
230
333
|
}
|
|
231
334
|
if (size !== void 0 && !Number.isInteger(size)) {
|
|
232
335
|
reject("maxEntrySizeBytes", "must be an integer", size);
|
|
233
336
|
}
|
|
337
|
+
if (options.maxEntrySizeBytes !== void 0 && options.maxEntrySizeBytes > MAX_ENTRY_SIZE_BYTES) {
|
|
338
|
+
reject("maxEntrySizeBytes", `must be at most ${String(MAX_ENTRY_SIZE_BYTES)}`, size);
|
|
339
|
+
}
|
|
234
340
|
}
|
|
235
341
|
function validateClosedSets(options) {
|
|
236
342
|
if (options.redactStrategy !== void 0 && options.redactStrategy !== "names" && options.redactStrategy !== "paths") {
|
|
237
|
-
|
|
238
|
-
`[BymaxLoggerModule] options.redactStrategy must be 'names' or 'paths'. Got: ${String(
|
|
239
|
-
options.redactStrategy
|
|
240
|
-
)}`
|
|
241
|
-
);
|
|
343
|
+
reject("redactStrategy", "must be 'names' or 'paths'", options.redactStrategy);
|
|
242
344
|
}
|
|
243
345
|
if (options.resourceFormat !== void 0 && options.resourceFormat !== "nested" && options.resourceFormat !== "flat") {
|
|
244
|
-
|
|
245
|
-
`[BymaxLoggerModule] options.resourceFormat must be 'nested' or 'flat'. Got: ${String(
|
|
246
|
-
options.resourceFormat
|
|
247
|
-
)}`
|
|
248
|
-
);
|
|
346
|
+
reject("resourceFormat", "must be 'nested' or 'flat'", options.resourceFormat);
|
|
249
347
|
}
|
|
250
348
|
if (options.errorFormat !== void 0 && options.errorFormat !== "pino" && options.errorFormat !== "semconv" && options.errorFormat !== "both") {
|
|
251
|
-
|
|
252
|
-
`[BymaxLoggerModule] options.errorFormat must be 'pino', 'semconv' or 'both'. Got: ${String(
|
|
253
|
-
options.errorFormat
|
|
254
|
-
)}`
|
|
255
|
-
);
|
|
349
|
+
reject("errorFormat", "must be 'pino', 'semconv' or 'both'", options.errorFormat);
|
|
256
350
|
}
|
|
257
351
|
if (options.eventNameField !== void 0 && options.eventNameField !== false && (typeof options.eventNameField !== "string" || options.eventNameField.length === 0)) {
|
|
258
|
-
|
|
259
|
-
`[BymaxLoggerModule] options.eventNameField must be a non-empty string or false. Got: ${String(
|
|
260
|
-
options.eventNameField
|
|
261
|
-
)}`
|
|
262
|
-
);
|
|
352
|
+
reject("eventNameField", "must be a non-empty string or false", options.eventNameField);
|
|
263
353
|
}
|
|
264
354
|
}
|
|
265
355
|
function validateCustomization(options) {
|
|
@@ -276,16 +366,16 @@ function validateCustomization(options) {
|
|
|
276
366
|
if (!Array.isArray(paths)) reject("redactPaths", "must be an array of strings", paths);
|
|
277
367
|
paths.forEach((entry, index) => {
|
|
278
368
|
if (!isNonEmptyString(entry)) {
|
|
279
|
-
reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry);
|
|
369
|
+
reject(`redactPaths[${String(index)}]`, "must be a non-empty string", entry, true);
|
|
280
370
|
}
|
|
281
371
|
});
|
|
282
372
|
}
|
|
283
373
|
const serializers = options.serializers;
|
|
284
374
|
if (serializers !== void 0) {
|
|
285
|
-
if (!
|
|
286
|
-
for (const
|
|
375
|
+
if (!isRecord2(serializers)) reject("serializers", "must be an object", serializers);
|
|
376
|
+
for (const serializer of Object.values(serializers)) {
|
|
287
377
|
if (typeof serializer !== "function") {
|
|
288
|
-
reject(
|
|
378
|
+
reject("serializers", "must map every serializer key to a function", serializer);
|
|
289
379
|
}
|
|
290
380
|
}
|
|
291
381
|
}
|
|
@@ -300,7 +390,7 @@ function validateErrorFields(options) {
|
|
|
300
390
|
if (!Array.isArray(names)) reject("errorOwnFieldNames", "must be an array of strings", names);
|
|
301
391
|
names.forEach((entry, index) => {
|
|
302
392
|
if (!isNonEmptyString(entry)) {
|
|
303
|
-
reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry);
|
|
393
|
+
reject(`errorOwnFieldNames[${String(index)}]`, "must be a non-empty string", entry, true);
|
|
304
394
|
}
|
|
305
395
|
});
|
|
306
396
|
}
|
|
@@ -314,8 +404,8 @@ function readMember(destination, key) {
|
|
|
314
404
|
}
|
|
315
405
|
function validateDestination(entry, index) {
|
|
316
406
|
const path = `destinations[${String(index)}]`;
|
|
317
|
-
if (!
|
|
318
|
-
reject(path, "must be an object implementing ILogDestination", entry);
|
|
407
|
+
if (!isRecord2(entry)) {
|
|
408
|
+
reject(path, "must be an object implementing ILogDestination", entry, true);
|
|
319
409
|
}
|
|
320
410
|
const write = readMember(entry, "write");
|
|
321
411
|
if (write !== UNREADABLE && typeof write !== "function") {
|
|
@@ -347,7 +437,7 @@ function checkRegExpList(path, value) {
|
|
|
347
437
|
}
|
|
348
438
|
value.forEach((pattern, index) => {
|
|
349
439
|
if (!util.types.isRegExp(pattern)) {
|
|
350
|
-
reject(`${path}[${String(index)}]`, "must be a RegExp", pattern);
|
|
440
|
+
reject(`${path}[${String(index)}]`, "must be a RegExp", pattern, true);
|
|
351
441
|
}
|
|
352
442
|
});
|
|
353
443
|
}
|
|
@@ -380,7 +470,8 @@ function validateOtel(options) {
|
|
|
380
470
|
checkNonEmptyString("otel.spanIdField", otel["spanIdField"]);
|
|
381
471
|
checkNonEmptyString("otel.traceFlagsField", otel["traceFlagsField"]);
|
|
382
472
|
}
|
|
383
|
-
function validateOptions(
|
|
473
|
+
function validateOptions(given) {
|
|
474
|
+
const options = dropUnsetOptions(given);
|
|
384
475
|
validateCore(options);
|
|
385
476
|
validateClosedSets(options);
|
|
386
477
|
validateCustomization(options);
|
|
@@ -388,6 +479,7 @@ function validateOptions(options) {
|
|
|
388
479
|
validateDestinations(options);
|
|
389
480
|
validateLifecycle(options);
|
|
390
481
|
validateQueue(options);
|
|
482
|
+
validateStringLimit(options);
|
|
391
483
|
validateHttp(options);
|
|
392
484
|
validateOtel(options);
|
|
393
485
|
}
|
|
@@ -448,14 +540,28 @@ var TEXT_TRUNCATED = "\u2026[truncated]";
|
|
|
448
540
|
function cutIfText(value) {
|
|
449
541
|
return typeof value === "string" ? cutText(value) : value;
|
|
450
542
|
}
|
|
451
|
-
function cutText(text, alreadyCut = false) {
|
|
452
|
-
if (!alreadyCut && text.length <=
|
|
453
|
-
const head = text.slice(0,
|
|
543
|
+
function cutText(text, alreadyCut = false, limit = MAX_TEXT_LENGTH) {
|
|
544
|
+
if (!alreadyCut && text.length <= limit) return text;
|
|
545
|
+
const head = text.slice(0, limit);
|
|
454
546
|
const last = head.charCodeAt(head.length - 1);
|
|
455
547
|
const whole = last >= 55296 && last <= 56319 ? head.slice(0, -1) : head;
|
|
456
548
|
return whole + TEXT_TRUNCATED;
|
|
457
549
|
}
|
|
458
550
|
|
|
551
|
+
// src/server/utils/entry-text-finisher.util.ts
|
|
552
|
+
var ENTRY_TEXT_FINISHER = /* @__PURE__ */ Symbol("bymax.entryTextFinisher");
|
|
553
|
+
function createEntryTextFinisher(redact, limit) {
|
|
554
|
+
return (key, text) => {
|
|
555
|
+
try {
|
|
556
|
+
const censored = Reflect.get(redact({ [key]: text }, true), key);
|
|
557
|
+
if (typeof censored !== "string") return "";
|
|
558
|
+
return limit === void 0 ? censored : cutText(censored, false, limit);
|
|
559
|
+
} catch {
|
|
560
|
+
return "";
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
459
565
|
// src/server/utils/escape-log-text.util.ts
|
|
460
566
|
var LINE_TERMINATORS = /* @__PURE__ */ new Set(["\r", "\n", "\x85", "\u2028", "\u2029"]);
|
|
461
567
|
var UNSAFE_IN_SINGLE_LINE = /[\u0000-\u0008\u000A-\u001F\u007F-\u009F\u2028\u2029]/g;
|
|
@@ -475,6 +581,16 @@ function toBoundedMessage(text) {
|
|
|
475
581
|
function escapeControlCharacters(text) {
|
|
476
582
|
return text.replace(UNSAFE_IN_MULTILINE, toEscapeSequence);
|
|
477
583
|
}
|
|
584
|
+
|
|
585
|
+
// src/server/utils/is-plain-record.util.ts
|
|
586
|
+
function isPlainRecord(node) {
|
|
587
|
+
try {
|
|
588
|
+
const prototype = Object.getPrototypeOf(node);
|
|
589
|
+
return prototype === Object.prototype || prototype === null;
|
|
590
|
+
} catch {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
478
594
|
function isError(value) {
|
|
479
595
|
try {
|
|
480
596
|
return util.types.isNativeError(value) || value instanceof Error;
|
|
@@ -671,14 +787,22 @@ function createWidthMarker(omitted) {
|
|
|
671
787
|
|
|
672
788
|
// src/server/services/pino-logger.service.ts
|
|
673
789
|
var OWNED_PAYLOAD_KEYS = ["logKey", "userId", "context"];
|
|
674
|
-
|
|
790
|
+
var ENTRY_STRUCTURE_KEYS = /* @__PURE__ */ new Set([
|
|
791
|
+
"level",
|
|
792
|
+
"time",
|
|
793
|
+
"msg",
|
|
794
|
+
"service",
|
|
795
|
+
"deployment"
|
|
796
|
+
]);
|
|
797
|
+
var isEntryStructureKey = (key) => ENTRY_STRUCTURE_KEYS.has(key) || key.startsWith("service.") || key.startsWith("deployment.");
|
|
798
|
+
function withoutOwnedKeys(metadata, omit) {
|
|
675
799
|
if (metadata === void 0) {
|
|
676
800
|
return {};
|
|
677
801
|
}
|
|
678
802
|
try {
|
|
679
803
|
const safe = {};
|
|
680
804
|
for (const key of Object.keys(metadata)) {
|
|
681
|
-
if (!OWNED_PAYLOAD_KEYS.includes(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
|
|
805
|
+
if (key !== omit && !OWNED_PAYLOAD_KEYS.includes(key) && !isEntryStructureKey(key) && !PROTOTYPE_POLLUTING_KEYS.has(key)) {
|
|
682
806
|
Reflect.set(safe, key, Reflect.get(metadata, key));
|
|
683
807
|
}
|
|
684
808
|
}
|
|
@@ -697,6 +821,23 @@ function safeErrorMessage(error) {
|
|
|
697
821
|
return "Unreadable error message";
|
|
698
822
|
}
|
|
699
823
|
}
|
|
824
|
+
function objectMessageText(fields) {
|
|
825
|
+
for (const key of ["message", "event"]) {
|
|
826
|
+
try {
|
|
827
|
+
const value = Reflect.get(fields, key);
|
|
828
|
+
if (typeof value === "string") return { key, text: value };
|
|
829
|
+
} catch {
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return void 0;
|
|
833
|
+
}
|
|
834
|
+
function readObjectMessage(message) {
|
|
835
|
+
const fields = isPlainRecord(message) && !isErrorLike(message) ? message : void 0;
|
|
836
|
+
const text = fields === void 0 ? void 0 : objectMessageText(fields);
|
|
837
|
+
const omit = text?.key === "message" ? "message" : void 0;
|
|
838
|
+
const payload = withoutOwnedKeys(fields, omit);
|
|
839
|
+
return { fields, text, payload };
|
|
840
|
+
}
|
|
700
841
|
function safeLogMessage(message) {
|
|
701
842
|
try {
|
|
702
843
|
return toBoundedMessage(typeof message === "string" ? message : String(message));
|
|
@@ -771,11 +912,11 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
771
912
|
}
|
|
772
913
|
const stack = typeof optionalParams[0] === "string" ? optionalParams[0] : void 0;
|
|
773
914
|
const context = typeof optionalParams[1] === "string" ? optionalParams[1] : this.context;
|
|
774
|
-
const payload =
|
|
915
|
+
const { fields, text, payload } = readObjectMessage(message);
|
|
775
916
|
assignIfDefined(payload, "context", context);
|
|
776
917
|
assignIfDefined(payload, "stack", stack === void 0 ? stack : cutText(stack));
|
|
777
918
|
assignIfDefined(payload, "err", findErrorParam(optionalParams));
|
|
778
|
-
this.pino.error(payload,
|
|
919
|
+
this.pino.error(payload, this.nestStyleMessage(void 0, fields, text, message));
|
|
779
920
|
}
|
|
780
921
|
/**
|
|
781
922
|
* NestJS `warn` (warn level).
|
|
@@ -927,12 +1068,30 @@ exports.PinoLoggerService = class PinoLoggerService {
|
|
|
927
1068
|
}
|
|
928
1069
|
}
|
|
929
1070
|
/** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
|
|
1071
|
+
nestStyleMessage(leading, fields, text, message) {
|
|
1072
|
+
if (leading !== void 0) return safeErrorMessage(leading);
|
|
1073
|
+
if (fields !== void 0) return toBoundedMessage(this.censorText(text));
|
|
1074
|
+
return safeLogMessage(message);
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* The entry text of an object message, censored under the names of the field it came from and cut
|
|
1078
|
+
* like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
|
|
1079
|
+
* value the pipeline censors or cuts in the field itself.
|
|
1080
|
+
*
|
|
1081
|
+
* @param text - The text and the member it came from.
|
|
1082
|
+
* @returns The censored text, or an empty one when the redactor cannot be applied.
|
|
1083
|
+
*/
|
|
1084
|
+
censorText(text) {
|
|
1085
|
+
if (text === void 0) return "";
|
|
1086
|
+
const finish = Reflect.get(this.pino, ENTRY_TEXT_FINISHER) ?? createEntryTextFinisher(this.redact, void 0);
|
|
1087
|
+
return finish(text.key, text.text);
|
|
1088
|
+
}
|
|
930
1089
|
emitNestStyle(level, message, optionalParams) {
|
|
931
|
-
const payload =
|
|
1090
|
+
const { fields, text, payload } = readObjectMessage(message);
|
|
932
1091
|
assignIfDefined(payload, "context", this.resolveContext(optionalParams));
|
|
933
1092
|
const leading = isErrorLike(message) ? message : void 0;
|
|
934
1093
|
assignIfDefined(payload, "err", leading ?? findErrorParam(optionalParams));
|
|
935
|
-
const msg = leading
|
|
1094
|
+
const msg = this.nestStyleMessage(leading, fields, text, message);
|
|
936
1095
|
switch (level) {
|
|
937
1096
|
case "info":
|
|
938
1097
|
this.pino.info(payload, msg);
|
|
@@ -2155,6 +2314,26 @@ function compileRedactPaths(extraPaths, shouldSkipDefaults) {
|
|
|
2155
2314
|
const sources = shouldSkipDefaults ? [extraPaths] : [DEFAULT_REDACT_PATHS, extraPaths];
|
|
2156
2315
|
return Array.from(new Set(sources.flat()));
|
|
2157
2316
|
}
|
|
2317
|
+
|
|
2318
|
+
// src/server/utils/cut-strings.util.ts
|
|
2319
|
+
function cutNode(node, limit) {
|
|
2320
|
+
if (typeof node === "string") return cutText(node, false, limit);
|
|
2321
|
+
if (Array.isArray(node)) return node.map((child) => cutNode(child, limit));
|
|
2322
|
+
if (isPlainRecord(node)) {
|
|
2323
|
+
return Object.fromEntries(
|
|
2324
|
+
Object.entries(node).map(([key, child]) => [key, cutNode(child, limit)])
|
|
2325
|
+
);
|
|
2326
|
+
}
|
|
2327
|
+
return node;
|
|
2328
|
+
}
|
|
2329
|
+
function cutStrings(record, limit, exempt) {
|
|
2330
|
+
return Object.fromEntries(
|
|
2331
|
+
Object.entries(record).map(([key, child]) => [
|
|
2332
|
+
key,
|
|
2333
|
+
exempt.has(key) ? child : cutNode(child, limit)
|
|
2334
|
+
])
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2158
2337
|
function reportWriteFailure(destination, cause, due) {
|
|
2159
2338
|
const name = safeDestinationName(destination);
|
|
2160
2339
|
reportDestinationFailure(
|
|
@@ -2292,6 +2471,30 @@ function destinationToStream(destination, health, maxQueueBytes = 0) {
|
|
|
2292
2471
|
return stream;
|
|
2293
2472
|
}
|
|
2294
2473
|
|
|
2474
|
+
// src/server/utils/merge-mixin-safely.util.ts
|
|
2475
|
+
var PROTOTYPE_KEY = "__proto__";
|
|
2476
|
+
var EXPLICIT_USER_KEY = "userId";
|
|
2477
|
+
function mergeMixinSafely(mergeObject, mixinObject) {
|
|
2478
|
+
try {
|
|
2479
|
+
const merged = {};
|
|
2480
|
+
for (const key of Object.keys(mergeObject)) {
|
|
2481
|
+
if (key !== PROTOTYPE_KEY) Reflect.set(merged, key, Reflect.get(mergeObject, key));
|
|
2482
|
+
}
|
|
2483
|
+
for (const [key, value] of Object.entries(mixinObject)) {
|
|
2484
|
+
if (value === void 0) continue;
|
|
2485
|
+
if (key === EXPLICIT_USER_KEY && Reflect.get(merged, key) !== void 0) continue;
|
|
2486
|
+
Reflect.set(merged, key, value);
|
|
2487
|
+
}
|
|
2488
|
+
return merged;
|
|
2489
|
+
} catch {
|
|
2490
|
+
return {
|
|
2491
|
+
...mixinObject,
|
|
2492
|
+
_redactionFailed: true,
|
|
2493
|
+
_logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2295
2498
|
// src/server/utils/censor-raw-headers.util.ts
|
|
2296
2499
|
function censorRawHeaders(raw, sensitive, censor) {
|
|
2297
2500
|
return raw.map((entry, index) => {
|
|
@@ -2878,20 +3081,31 @@ var PASS_THROUGH = (value) => value;
|
|
|
2878
3081
|
function resolveNameRedactor(options) {
|
|
2879
3082
|
return buildNameRedactor(options, true, options.redactStrategy === "names");
|
|
2880
3083
|
}
|
|
3084
|
+
function resolveRecordRedactor(options) {
|
|
3085
|
+
return buildNameRedactor(
|
|
3086
|
+
options,
|
|
3087
|
+
true,
|
|
3088
|
+
options.redactStrategy === "names",
|
|
3089
|
+
options.maxStringLength !== void 0
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
3092
|
+
function wholeRootKeys(options) {
|
|
3093
|
+
return /* @__PURE__ */ new Set(["logKey", "err", ...Object.keys(options.serializers)]);
|
|
3094
|
+
}
|
|
2881
3095
|
function ownFieldPolicyOf(options) {
|
|
2882
3096
|
return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
|
|
2883
3097
|
}
|
|
2884
3098
|
function namesInsideErrors(options) {
|
|
2885
3099
|
return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
|
|
2886
3100
|
}
|
|
2887
|
-
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
|
|
3101
|
+
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true, forcesWalk = false) {
|
|
2888
3102
|
const allNames = [
|
|
2889
3103
|
...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
|
|
2890
3104
|
...options.redactPaths.flatMap((path) => leafNameOf(path) ?? [])
|
|
2891
3105
|
];
|
|
2892
3106
|
const names = coversNames ? allNames : [];
|
|
2893
3107
|
const ownFields = ownFieldPolicyOf(options);
|
|
2894
|
-
const walks = names.length > 0 || ownFields.safe;
|
|
3108
|
+
const walks = names.length > 0 || ownFields.safe || forcesWalk;
|
|
2895
3109
|
if (!walks && resolveRedactOption(options) === void 0) {
|
|
2896
3110
|
return PASS_THROUGH;
|
|
2897
3111
|
}
|
|
@@ -2932,16 +3146,10 @@ function buildSerializers(options, redactSerialized, ownFields) {
|
|
|
2932
3146
|
)
|
|
2933
3147
|
};
|
|
2934
3148
|
}
|
|
2935
|
-
function
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
return {
|
|
2940
|
-
...mixinObject,
|
|
2941
|
-
_redactionFailed: true,
|
|
2942
|
-
_logKey: RESERVED_LOG_KEYS.LOGGER_REDACTION_FAILED
|
|
2943
|
-
};
|
|
2944
|
-
}
|
|
3149
|
+
function withEntryTextFinisher(logger, options) {
|
|
3150
|
+
const redact = buildNameRedactor(options);
|
|
3151
|
+
Reflect.set(logger, ENTRY_TEXT_FINISHER, createEntryTextFinisher(redact, options.maxStringLength));
|
|
3152
|
+
return logger;
|
|
2945
3153
|
}
|
|
2946
3154
|
function buildStreams(options, destinations, health) {
|
|
2947
3155
|
return destinations.map((destination) => {
|
|
@@ -2957,8 +3165,20 @@ function buildStreams(options, destinations, health) {
|
|
|
2957
3165
|
};
|
|
2958
3166
|
});
|
|
2959
3167
|
}
|
|
2960
|
-
function
|
|
3168
|
+
function buildRecordFormatter(options, redactRecord) {
|
|
2961
3169
|
const hostSerializesRequest = Object.hasOwn(options.serializers, "req");
|
|
3170
|
+
const maxStringLength = options.maxStringLength;
|
|
3171
|
+
const wholeRoots = wholeRootKeys(options);
|
|
3172
|
+
return (record) => {
|
|
3173
|
+
const redacted = redactRecord(
|
|
3174
|
+
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
3175
|
+
true
|
|
3176
|
+
);
|
|
3177
|
+
const bounded = maxStringLength === void 0 ? redacted : cutStrings(redacted, maxStringLength, wholeRoots);
|
|
3178
|
+
return withSemconvException(withEventName(bounded, options.eventNameField), options.errorFormat);
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
function buildFormatters(options, redactRecord, redactBindings) {
|
|
2962
3182
|
return {
|
|
2963
3183
|
// Emit the level as a string label instead of the numeric code — easier
|
|
2964
3184
|
// for log aggregators. Trace context is injected via `mixin`, never via
|
|
@@ -2973,26 +3193,20 @@ function buildFormatters(options, redactRecord) {
|
|
|
2973
3193
|
// consumer's extra metadata instead of silently dropping it. Runs ONCE, at
|
|
2974
3194
|
// logger construction — no per-entry cost. `true`: bindings are a record
|
|
2975
3195
|
// root, iterated rather than serialized.
|
|
2976
|
-
bindings: (bindings) =>
|
|
3196
|
+
bindings: (bindings) => redactBindings(bindings, true),
|
|
2977
3197
|
// The name-walk redactor runs here, on the merged record (mixin output +
|
|
2978
3198
|
// the caller's object), which is exactly the surface a caller controls.
|
|
2979
3199
|
// `base` and child bindings are NOT visible at this hook — they are
|
|
2980
3200
|
// library-owned (`service`, the `@InjectLogger` context) and carry nothing
|
|
2981
3201
|
// sensitive, which `pino-factory.spec.ts` pins.
|
|
2982
|
-
log: (
|
|
2983
|
-
withEventName(
|
|
2984
|
-
redactRecord(
|
|
2985
|
-
hostSerializesRequest ? record : withSerializedRequest(record, options.http.secretPathSegments),
|
|
2986
|
-
true
|
|
2987
|
-
),
|
|
2988
|
-
options.eventNameField
|
|
2989
|
-
),
|
|
2990
|
-
options.errorFormat
|
|
2991
|
-
)
|
|
3202
|
+
log: buildRecordFormatter(options, redactRecord)
|
|
2992
3203
|
};
|
|
2993
3204
|
}
|
|
2994
3205
|
function buildPinoInstance(options, logContext, destinations, health) {
|
|
2995
|
-
|
|
3206
|
+
if (options.maxStringLength !== void 0) {
|
|
3207
|
+
refuseCensorBeyondLimit(options.redactCensor, options.maxStringLength);
|
|
3208
|
+
}
|
|
3209
|
+
const redactRecord = resolveRecordRedactor(options);
|
|
2996
3210
|
const redactSerialized = buildNameRedactor(options);
|
|
2997
3211
|
const ownFields = ownFieldPolicyOf(options);
|
|
2998
3212
|
const redactOption = resolveRedactOption(options);
|
|
@@ -3012,12 +3226,13 @@ function buildPinoInstance(options, logContext, destinations, health) {
|
|
|
3012
3226
|
// is encoded as a JSON string here: a quote, a backslash or a newline in it must
|
|
3013
3227
|
// neither break the line nor add fields to it.
|
|
3014
3228
|
timestamp: () => `,"time":${JSON.stringify(String(options.timestamp()))}`,
|
|
3015
|
-
formatters: buildFormatters(options, redactRecord),
|
|
3229
|
+
formatters: buildFormatters(options, redactRecord, resolveNameRedactor(options)),
|
|
3016
3230
|
serializers: buildSerializers(options, redactSerialized, ownFields),
|
|
3017
3231
|
mixin: createTraceContextMixin(logContext, options.otel),
|
|
3018
3232
|
mixinMergeStrategy: mergeMixinSafely
|
|
3019
3233
|
};
|
|
3020
|
-
|
|
3234
|
+
const streams = pino__default.default.multistream(buildStreams(options, destinations, health));
|
|
3235
|
+
return withEntryTextFinisher(pino__default.default(pinoOptions, streams), options);
|
|
3021
3236
|
}
|
|
3022
3237
|
var DROP_REPORT_INTERVAL_MS = 1e4;
|
|
3023
3238
|
function countInWindow(records, destination, now) {
|
|
@@ -3910,6 +4125,30 @@ function describeFailure(cause) {
|
|
|
3910
4125
|
return "unreadable value";
|
|
3911
4126
|
}
|
|
3912
4127
|
}
|
|
4128
|
+
function productionRefusal() {
|
|
4129
|
+
return new Error(
|
|
4130
|
+
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
4131
|
+
);
|
|
4132
|
+
}
|
|
4133
|
+
async function buildTransform(view) {
|
|
4134
|
+
const { build } = await import('pino-pretty');
|
|
4135
|
+
return build({
|
|
4136
|
+
...DEFAULT_VIEW,
|
|
4137
|
+
...view,
|
|
4138
|
+
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
4139
|
+
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
4140
|
+
// last is what ENFORCES it, including against an untyped caller reaching
|
|
4141
|
+
// in from JavaScript. A redirected stream would route around the fan-out
|
|
4142
|
+
// and the last-resort rescue.
|
|
4143
|
+
destination: process.stdout
|
|
4144
|
+
});
|
|
4145
|
+
}
|
|
4146
|
+
function initFailure(cause) {
|
|
4147
|
+
return new Error(
|
|
4148
|
+
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)}`,
|
|
4149
|
+
{ cause }
|
|
4150
|
+
);
|
|
4151
|
+
}
|
|
3913
4152
|
var PrettyDevDestination = class {
|
|
3914
4153
|
/**
|
|
3915
4154
|
* @param opts.minLevel — Optional minimum level filter applied by the
|
|
@@ -3964,11 +4203,15 @@ var PrettyDevDestination = class {
|
|
|
3964
4203
|
* message telling the consumer to install it or drop this destination.
|
|
3965
4204
|
*/
|
|
3966
4205
|
async onInit() {
|
|
3967
|
-
|
|
4206
|
+
if (process.env["NODE_ENV"] === "production") {
|
|
4207
|
+
this.initFailed = true;
|
|
4208
|
+
throw productionRefusal();
|
|
4209
|
+
}
|
|
3968
4210
|
try {
|
|
3969
|
-
this.stream = await this.
|
|
4211
|
+
this.stream = await buildTransform(this.view);
|
|
3970
4212
|
} catch (cause) {
|
|
3971
|
-
|
|
4213
|
+
this.initFailed = true;
|
|
4214
|
+
throw initFailure(cause);
|
|
3972
4215
|
}
|
|
3973
4216
|
this.flushBuffer((payload) => {
|
|
3974
4217
|
try {
|
|
@@ -3978,46 +4221,6 @@ var PrettyDevDestination = class {
|
|
|
3978
4221
|
}
|
|
3979
4222
|
});
|
|
3980
4223
|
}
|
|
3981
|
-
/** Refuse to start when `NODE_ENV` is `production`. */
|
|
3982
|
-
refuseInProduction() {
|
|
3983
|
-
if (process.env["NODE_ENV"] === "production") {
|
|
3984
|
-
this.initFailed = true;
|
|
3985
|
-
throw new Error(
|
|
3986
|
-
"[PrettyDevDestination] refused in production (NODE_ENV=production): it renders ANSI colour through a main-thread transform. Use DefaultStdoutDestination, or register PrettyDevDestination only outside production."
|
|
3987
|
-
);
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
/**
|
|
3991
|
-
* Resolve `pino-pretty` and build the colorized transform that renders to `process.stdout`.
|
|
3992
|
-
*
|
|
3993
|
-
* @returns The transform every entry is written to.
|
|
3994
|
-
*/
|
|
3995
|
-
async buildTransform() {
|
|
3996
|
-
const { build } = await import('pino-pretty');
|
|
3997
|
-
return build({
|
|
3998
|
-
...DEFAULT_VIEW,
|
|
3999
|
-
...this.view,
|
|
4000
|
-
// AFTER the consumer's view, deliberately. Omitting `destination` from
|
|
4001
|
-
// `PrettyViewOptions` states that the library owns the sink; applying it
|
|
4002
|
-
// last is what ENFORCES it, including against an untyped caller reaching
|
|
4003
|
-
// in from JavaScript. A redirected stream would route around the fan-out
|
|
4004
|
-
// and the last-resort rescue.
|
|
4005
|
-
destination: process.stdout
|
|
4006
|
-
});
|
|
4007
|
-
}
|
|
4008
|
-
/**
|
|
4009
|
-
* Mark the destination as failed and build the error `onInit` rejects with.
|
|
4010
|
-
*
|
|
4011
|
-
* @param cause - What the import or `build()` threw.
|
|
4012
|
-
* @returns The error to throw.
|
|
4013
|
-
*/
|
|
4014
|
-
initFailure(cause) {
|
|
4015
|
-
this.initFailed = true;
|
|
4016
|
-
return new Error(
|
|
4017
|
-
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)}`,
|
|
4018
|
-
{ cause }
|
|
4019
|
-
);
|
|
4020
|
-
}
|
|
4021
4224
|
/**
|
|
4022
4225
|
* Write a serialized NDJSON entry to the pretty transform.
|
|
4023
4226
|
*
|
|
@@ -4358,23 +4561,23 @@ var MAX_CODE_LENGTH = 128;
|
|
|
4358
4561
|
function isCount(value) {
|
|
4359
4562
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
4360
4563
|
}
|
|
4361
|
-
function
|
|
4564
|
+
function isRecord3(value) {
|
|
4362
4565
|
return typeof value === "object" && value !== null;
|
|
4363
4566
|
}
|
|
4364
4567
|
function exceptionFields(error) {
|
|
4365
4568
|
try {
|
|
4366
|
-
if (!
|
|
4569
|
+
if (!isRecord3(error) || typeof error["getResponse"] !== "function") return {};
|
|
4367
4570
|
const response = error["getResponse"]();
|
|
4368
|
-
if (!
|
|
4571
|
+
if (!isRecord3(response)) return {};
|
|
4369
4572
|
const nested = response["error"];
|
|
4370
|
-
const carrier =
|
|
4573
|
+
const carrier = isRecord3(nested) && typeof nested["code"] === "string" ? nested : response;
|
|
4371
4574
|
const fields = {};
|
|
4372
4575
|
const code = carrier["code"];
|
|
4373
4576
|
if (typeof code === "string") {
|
|
4374
4577
|
fields["errorCode"] = code.slice(0, MAX_CODE_LENGTH);
|
|
4375
4578
|
}
|
|
4376
4579
|
const details = carrier["details"];
|
|
4377
|
-
if (
|
|
4580
|
+
if (isRecord3(details)) {
|
|
4378
4581
|
fields["errorDetails"] = details;
|
|
4379
4582
|
}
|
|
4380
4583
|
return fields;
|