@lark-apaas/nestjs-logger 1.0.1-alpha.0 → 1.0.1-alpha.1
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/README.md +14 -1
- package/dist/index.cjs +14 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14879,16 +14879,27 @@ var LoggingInterceptor = class {
|
|
|
14879
14879
|
duration_ms: durationMs
|
|
14880
14880
|
};
|
|
14881
14881
|
const finalResponseBody = res.__finalResponseBody;
|
|
14882
|
-
|
|
14882
|
+
const contentType = res.getHeader("content-type");
|
|
14883
|
+
const isJsonResponse = typeof contentType === "string" && contentType.includes("application/json");
|
|
14884
|
+
if (this.config.logResponseBody && finalResponseBody !== void 0 && isJsonResponse) {
|
|
14883
14885
|
responseMeta["response_body"] = this.sanitizeAndTruncate(finalResponseBody);
|
|
14884
14886
|
}
|
|
14885
14887
|
const isError = statusCode >= 400;
|
|
14886
14888
|
const appLog = this.appLogger[isError ? "error" : "log"].bind(this.appLogger);
|
|
14887
14889
|
const traceLevel = isError ? "error" : "verbose";
|
|
14890
|
+
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
14888
14891
|
if (isError) {
|
|
14889
|
-
|
|
14892
|
+
if (shouldLogBody) {
|
|
14893
|
+
appLog("HTTP request failed\n url=%s \n status_code=%d \n duration_ms=%d \n response_body=%o", req.url, statusCode, durationMs, finalResponseBody);
|
|
14894
|
+
} else {
|
|
14895
|
+
appLog("HTTP request failed\n url=%s \n status_code=%d \n duration_ms=%d", req.url, statusCode, durationMs);
|
|
14896
|
+
}
|
|
14890
14897
|
} else {
|
|
14891
|
-
|
|
14898
|
+
if (shouldLogBody) {
|
|
14899
|
+
appLog("HTTP request completed\n url=%s \n status_code=%d \n duration_ms=%d \n response_body=%o", req.url, statusCode, durationMs, finalResponseBody);
|
|
14900
|
+
} else {
|
|
14901
|
+
appLog("HTTP request completed\n url=%s \n status_code=%d \n duration_ms=%d", req.url, statusCode, durationMs);
|
|
14902
|
+
}
|
|
14892
14903
|
}
|
|
14893
14904
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14894
14905
|
});
|