@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.cjs
CHANGED
|
@@ -9499,6 +9499,7 @@ var LoggingInterceptor = class {
|
|
|
9499
9499
|
if (context.getType() !== "http") {
|
|
9500
9500
|
return next.handle();
|
|
9501
9501
|
}
|
|
9502
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
9502
9503
|
const httpContext = context.switchToHttp();
|
|
9503
9504
|
const req = httpContext.getRequest();
|
|
9504
9505
|
const res = httpContext.getResponse();
|
|
@@ -9533,10 +9534,6 @@ var LoggingInterceptor = class {
|
|
|
9533
9534
|
res.__finalResponseBody = body;
|
|
9534
9535
|
return originalSend(body);
|
|
9535
9536
|
};
|
|
9536
|
-
if (process.env.NODE_ENV === "development") {
|
|
9537
|
-
this.appLogger.log(`HTTP request started
|
|
9538
|
-
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9539
|
-
}
|
|
9540
9537
|
const requestMeta = {
|
|
9541
9538
|
...baseMeta
|
|
9542
9539
|
};
|
|
@@ -9546,6 +9543,10 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9546
9543
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
9547
9544
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
9548
9545
|
}
|
|
9546
|
+
if (isDev) {
|
|
9547
|
+
this.appLogger.log(`HTTP request started
|
|
9548
|
+
url=${req.url}`, "HTTPTraceInterceptor");
|
|
9549
|
+
}
|
|
9549
9550
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
9550
9551
|
let logged = false;
|
|
9551
9552
|
res.on("finish", () => {
|
|
@@ -9581,9 +9582,39 @@ url=${req.url}`, "HTTPTraceInterceptor");
|
|
|
9581
9582
|
responseData.response = JSON.parse(finalResponseBody);
|
|
9582
9583
|
}
|
|
9583
9584
|
const reportData = JSON.stringify(responseData);
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9585
|
+
if (!isDev) {
|
|
9586
|
+
this.appLogger.log(reportData, {
|
|
9587
|
+
source_type: "platform"
|
|
9588
|
+
}, "HTTPTraceInterceptor");
|
|
9589
|
+
}
|
|
9590
|
+
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
9591
|
+
if (isError) {
|
|
9592
|
+
if (shouldLogBody) {
|
|
9593
|
+
appLog(`HTTP request failed
|
|
9594
|
+
url=${req.url}
|
|
9595
|
+
status_code=${statusCode}
|
|
9596
|
+
duration_ms=${durationMs}
|
|
9597
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9598
|
+
} else {
|
|
9599
|
+
appLog(`HTTP request failed
|
|
9600
|
+
url=${req.url}
|
|
9601
|
+
status_code=${statusCode}
|
|
9602
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9603
|
+
}
|
|
9604
|
+
} else if (isDev) {
|
|
9605
|
+
if (shouldLogBody) {
|
|
9606
|
+
appLog(`HTTP request completed
|
|
9607
|
+
url=${req.url}
|
|
9608
|
+
status_code=${statusCode}
|
|
9609
|
+
duration_ms=${durationMs}
|
|
9610
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
9611
|
+
} else {
|
|
9612
|
+
appLog(`HTTP request completed
|
|
9613
|
+
url=${req.url}
|
|
9614
|
+
status_code=${statusCode}
|
|
9615
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
9616
|
+
}
|
|
9617
|
+
}
|
|
9587
9618
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
9588
9619
|
});
|
|
9589
9620
|
return next.handle().pipe((0, import_operators.catchError)((error) => {
|