@lark-apaas/nestjs-logger 1.0.2-alpha.37 → 1.0.2-alpha.39
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/dist/index.cjs +72 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +72 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -25,6 +25,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
25
25
|
*/
|
|
26
26
|
logStructured(level: LogLevel, message: string, meta: Record<string, unknown>, context?: string): void;
|
|
27
27
|
protected write(level: LogLevel, message: unknown, optionalParams: unknown[], treatStack?: boolean): void;
|
|
28
|
+
private processLogParams;
|
|
28
29
|
private extractOptionalParams;
|
|
29
30
|
private buildMessagePayload;
|
|
30
31
|
private static looksLikeStack;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ declare abstract class BasePinoLogger implements LoggerService {
|
|
|
25
25
|
*/
|
|
26
26
|
logStructured(level: LogLevel, message: string, meta: Record<string, unknown>, context?: string): void;
|
|
27
27
|
protected write(level: LogLevel, message: unknown, optionalParams: unknown[], treatStack?: boolean): void;
|
|
28
|
+
private processLogParams;
|
|
28
29
|
private extractOptionalParams;
|
|
29
30
|
private buildMessagePayload;
|
|
30
31
|
private static looksLikeStack;
|
package/dist/index.js
CHANGED
|
@@ -9224,6 +9224,7 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
9224
9224
|
const { context, stack, extras } = this.extractOptionalParams(optionalParams, treatStack);
|
|
9225
9225
|
const requestState = this.contextStore.getContext();
|
|
9226
9226
|
const traceId = requestState?.requestId ?? null;
|
|
9227
|
+
const firstParam = optionalParams[0];
|
|
9227
9228
|
const flatObject = /* @__PURE__ */ __name((extra) => {
|
|
9228
9229
|
let res = {};
|
|
9229
9230
|
try {
|
|
@@ -9268,8 +9269,10 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
9268
9269
|
}
|
|
9269
9270
|
const pinoLevel = mapLogLevelToPino(level);
|
|
9270
9271
|
const sanitizedPayload = sanitizeValue(payload);
|
|
9272
|
+
const isTriggerLog = firstParam?.module === "trigger";
|
|
9273
|
+
const platformModule = isTriggerLog ? "trigger" : firstParam?.paas_attributes_module;
|
|
9271
9274
|
if (process.env.NODE_ENV === "development") {
|
|
9272
|
-
if (
|
|
9275
|
+
if (platformModule) {
|
|
9273
9276
|
return;
|
|
9274
9277
|
}
|
|
9275
9278
|
if (messageText) {
|
|
@@ -9279,11 +9282,36 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
9279
9282
|
}
|
|
9280
9283
|
} else {
|
|
9281
9284
|
let finalMessage = messageText;
|
|
9282
|
-
if (
|
|
9283
|
-
|
|
9285
|
+
if (platformModule) {
|
|
9286
|
+
if (typeof message !== "string") {
|
|
9287
|
+
finalMessage = safeStringify(message);
|
|
9288
|
+
}
|
|
9289
|
+
this.observableService.log(level, finalMessage ?? "", {
|
|
9290
|
+
...payload,
|
|
9291
|
+
module: platformModule
|
|
9292
|
+
});
|
|
9293
|
+
} else {
|
|
9294
|
+
const reportMessage = this.processLogParams([
|
|
9295
|
+
message,
|
|
9296
|
+
...optionalParams
|
|
9297
|
+
]);
|
|
9298
|
+
this.observableService.log(level, reportMessage, {});
|
|
9299
|
+
}
|
|
9300
|
+
}
|
|
9301
|
+
}
|
|
9302
|
+
processLogParams(args) {
|
|
9303
|
+
if (args.length === 1) {
|
|
9304
|
+
const firstParam = args[0];
|
|
9305
|
+
if (typeof firstParam !== "string") {
|
|
9306
|
+
return safeStringify(firstParam);
|
|
9284
9307
|
}
|
|
9285
|
-
|
|
9308
|
+
return firstParam;
|
|
9309
|
+
}
|
|
9310
|
+
const obj = {};
|
|
9311
|
+
for (let i = 0; i < args.length; i++) {
|
|
9312
|
+
obj[i.toString()] = args[i];
|
|
9286
9313
|
}
|
|
9314
|
+
return safeStringify(obj);
|
|
9287
9315
|
}
|
|
9288
9316
|
extractOptionalParams(optionalParams, treatStack) {
|
|
9289
9317
|
const params = [
|
|
@@ -9482,6 +9510,7 @@ var LoggingInterceptor = class {
|
|
|
9482
9510
|
if (context.getType() !== "http") {
|
|
9483
9511
|
return next.handle();
|
|
9484
9512
|
}
|
|
9513
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
9485
9514
|
const httpContext = context.switchToHttp();
|
|
9486
9515
|
const req = httpContext.getRequest();
|
|
9487
9516
|
const res = httpContext.getResponse();
|
|
@@ -9516,10 +9545,6 @@ var LoggingInterceptor = class {
|
|
|
9516
9545
|
res.__finalResponseBody = body;
|
|
9517
9546
|
return originalSend(body);
|
|
9518
9547
|
};
|
|
9519
|
-
if (process.env.NODE_ENV === "development") {
|
|
9520
|
-
this.appLogger.log(`HTTP request started
|
|
9521
|
-
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9522
|
-
}
|
|
9523
9548
|
const requestMeta = {
|
|
9524
9549
|
...baseMeta
|
|
9525
9550
|
};
|
|
@@ -9529,6 +9554,10 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9529
9554
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
9530
9555
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
9531
9556
|
}
|
|
9557
|
+
if (isDev) {
|
|
9558
|
+
this.appLogger.log(`HTTP request started
|
|
9559
|
+
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9560
|
+
}
|
|
9532
9561
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
9533
9562
|
let logged = false;
|
|
9534
9563
|
res.on("finish", () => {
|
|
@@ -9564,13 +9593,45 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9564
9593
|
responseData.response = JSON.parse(finalResponseBody);
|
|
9565
9594
|
}
|
|
9566
9595
|
const reportData = JSON.stringify(responseData);
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9596
|
+
if (!isDev) {
|
|
9597
|
+
this.appLogger.log(reportData, {
|
|
9598
|
+
paas_attributes_module: "app_server",
|
|
9599
|
+
source_type: "platform"
|
|
9600
|
+
}, "HTTPTraceInterceptor");
|
|
9601
|
+
}
|
|
9602
|
+
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
9603
|
+
if (isError) {
|
|
9604
|
+
if (shouldLogBody) {
|
|
9605
|
+
appLog(`HTTP request failed
|
|
9606
|
+
url=${req.url}
|
|
9607
|
+
status_code=${statusCode}
|
|
9608
|
+
duration_ms=${durationMs}
|
|
9609
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9610
|
+
} else {
|
|
9611
|
+
appLog(`HTTP request failed
|
|
9612
|
+
url=${req.url}
|
|
9613
|
+
status_code=${statusCode}
|
|
9614
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9615
|
+
}
|
|
9616
|
+
} else if (isDev) {
|
|
9617
|
+
if (shouldLogBody) {
|
|
9618
|
+
appLog(`HTTP request completed
|
|
9619
|
+
url=${req.url}
|
|
9620
|
+
status_code=${statusCode}
|
|
9621
|
+
duration_ms=${durationMs}
|
|
9622
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9623
|
+
} else {
|
|
9624
|
+
appLog(`HTTP request completed
|
|
9625
|
+
url=${req.url}
|
|
9626
|
+
status_code=${statusCode}
|
|
9627
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9628
|
+
}
|
|
9629
|
+
}
|
|
9570
9630
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
9571
9631
|
});
|
|
9572
9632
|
return next.handle().pipe((0, import_operators.catchError)((error) => {
|
|
9573
9633
|
this.appLogger.error(format("HTTP request exception\nmethod=%s url=%s\nerror=%o", req.method, req.url, error), {
|
|
9634
|
+
paas_attributes_module: "app_server",
|
|
9574
9635
|
source_type: "platform"
|
|
9575
9636
|
}, "HTTPTraceInterceptor");
|
|
9576
9637
|
throw error;
|