@lark-apaas/nestjs-logger 1.0.2-alpha.37 → 1.0.2-alpha.38
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 +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9482,6 +9482,7 @@ var LoggingInterceptor = class {
|
|
|
9482
9482
|
if (context.getType() !== "http") {
|
|
9483
9483
|
return next.handle();
|
|
9484
9484
|
}
|
|
9485
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
9485
9486
|
const httpContext = context.switchToHttp();
|
|
9486
9487
|
const req = httpContext.getRequest();
|
|
9487
9488
|
const res = httpContext.getResponse();
|
|
@@ -9516,10 +9517,6 @@ var LoggingInterceptor = class {
|
|
|
9516
9517
|
res.__finalResponseBody = body;
|
|
9517
9518
|
return originalSend(body);
|
|
9518
9519
|
};
|
|
9519
|
-
if (process.env.NODE_ENV === "development") {
|
|
9520
|
-
this.appLogger.log(`HTTP request started
|
|
9521
|
-
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9522
|
-
}
|
|
9523
9520
|
const requestMeta = {
|
|
9524
9521
|
...baseMeta
|
|
9525
9522
|
};
|
|
@@ -9529,6 +9526,10 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9529
9526
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
9530
9527
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
9531
9528
|
}
|
|
9529
|
+
if (isDev) {
|
|
9530
|
+
this.appLogger.log(`HTTP request started
|
|
9531
|
+
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9532
|
+
}
|
|
9532
9533
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
9533
9534
|
let logged = false;
|
|
9534
9535
|
res.on("finish", () => {
|
|
@@ -9564,9 +9565,39 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9564
9565
|
responseData.response = JSON.parse(finalResponseBody);
|
|
9565
9566
|
}
|
|
9566
9567
|
const reportData = JSON.stringify(responseData);
|
|
9567
|
-
|
|
9568
|
-
|
|
9569
|
-
|
|
9568
|
+
if (!isDev) {
|
|
9569
|
+
this.appLogger.log(reportData, {
|
|
9570
|
+
source_type: "platform"
|
|
9571
|
+
}, "HTTPTraceInterceptor");
|
|
9572
|
+
}
|
|
9573
|
+
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
9574
|
+
if (isError) {
|
|
9575
|
+
if (shouldLogBody) {
|
|
9576
|
+
appLog(`HTTP request failed
|
|
9577
|
+
url=${req.url}
|
|
9578
|
+
status_code=${statusCode}
|
|
9579
|
+
duration_ms=${durationMs}
|
|
9580
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9581
|
+
} else {
|
|
9582
|
+
appLog(`HTTP request failed
|
|
9583
|
+
url=${req.url}
|
|
9584
|
+
status_code=${statusCode}
|
|
9585
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9586
|
+
}
|
|
9587
|
+
} else if (isDev) {
|
|
9588
|
+
if (shouldLogBody) {
|
|
9589
|
+
appLog(`HTTP request completed
|
|
9590
|
+
url=${req.url}
|
|
9591
|
+
status_code=${statusCode}
|
|
9592
|
+
duration_ms=${durationMs}
|
|
9593
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9594
|
+
} else {
|
|
9595
|
+
appLog(`HTTP request completed
|
|
9596
|
+
url=${req.url}
|
|
9597
|
+
status_code=${statusCode}
|
|
9598
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9599
|
+
}
|
|
9600
|
+
}
|
|
9570
9601
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
9571
9602
|
});
|
|
9572
9603
|
return next.handle().pipe((0, import_operators.catchError)((error) => {
|