@lark-apaas/nestjs-logger 1.0.1-alpha.0 → 1.0.1-alpha.2
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 +101 -5
- package/dist/index.cjs +36 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14371,7 +14371,6 @@ var require_operators = __commonJS({
|
|
|
14371
14371
|
|
|
14372
14372
|
// src/service/app-logger.service.ts
|
|
14373
14373
|
import { Inject, Injectable as Injectable2, Logger } from "@nestjs/common";
|
|
14374
|
-
import { format } from "util";
|
|
14375
14374
|
|
|
14376
14375
|
// src/helper/constants.ts
|
|
14377
14376
|
var PINO_ROOT_LOGGER = Symbol("PINO_ROOT_LOGGER");
|
|
@@ -14667,8 +14666,12 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14667
14666
|
messageText: message
|
|
14668
14667
|
};
|
|
14669
14668
|
}
|
|
14669
|
+
const allMessages = [
|
|
14670
|
+
message,
|
|
14671
|
+
...extras.map((e) => String(e))
|
|
14672
|
+
].join(" ");
|
|
14670
14673
|
return {
|
|
14671
|
-
messageText:
|
|
14674
|
+
messageText: allMessages
|
|
14672
14675
|
};
|
|
14673
14676
|
}
|
|
14674
14677
|
if (typeof message === "object" && message !== null) {
|
|
@@ -14773,7 +14776,7 @@ function normalizeLevel(level) {
|
|
|
14773
14776
|
}
|
|
14774
14777
|
__name(normalizeLevel, "normalizeLevel");
|
|
14775
14778
|
var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
14776
|
-
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "
|
|
14779
|
+
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "trace" : "trace"));
|
|
14777
14780
|
const maxBodyLengthEnv = process.env.LOG_MAX_BODY_LENGTH;
|
|
14778
14781
|
const maxBodyLength = maxBodyLengthEnv ? Number(maxBodyLengthEnv) : null;
|
|
14779
14782
|
return {
|
|
@@ -14863,7 +14866,8 @@ var LoggingInterceptor = class {
|
|
|
14863
14866
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
14864
14867
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
14865
14868
|
}
|
|
14866
|
-
this.appLogger.log(
|
|
14869
|
+
this.appLogger.log(`HTTP request started
|
|
14870
|
+
url=${req.url}`, "HTTPTraceInterceptor");
|
|
14867
14871
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
14868
14872
|
let logged = false;
|
|
14869
14873
|
res.on("finish", () => {
|
|
@@ -14879,16 +14883,41 @@ var LoggingInterceptor = class {
|
|
|
14879
14883
|
duration_ms: durationMs
|
|
14880
14884
|
};
|
|
14881
14885
|
const finalResponseBody = res.__finalResponseBody;
|
|
14882
|
-
|
|
14886
|
+
const contentType = res.getHeader("content-type");
|
|
14887
|
+
const isJsonResponse = typeof contentType === "string" && contentType.includes("application/json");
|
|
14888
|
+
if (this.config.logResponseBody && finalResponseBody !== void 0 && isJsonResponse) {
|
|
14883
14889
|
responseMeta["response_body"] = this.sanitizeAndTruncate(finalResponseBody);
|
|
14884
14890
|
}
|
|
14885
14891
|
const isError = statusCode >= 400;
|
|
14886
14892
|
const appLog = this.appLogger[isError ? "error" : "log"].bind(this.appLogger);
|
|
14887
14893
|
const traceLevel = isError ? "error" : "verbose";
|
|
14894
|
+
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
14888
14895
|
if (isError) {
|
|
14889
|
-
|
|
14896
|
+
if (shouldLogBody) {
|
|
14897
|
+
appLog(`HTTP request failed
|
|
14898
|
+
url=${req.url}
|
|
14899
|
+
status_code=${statusCode}
|
|
14900
|
+
duration_ms=${durationMs}
|
|
14901
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
14902
|
+
} else {
|
|
14903
|
+
appLog(`HTTP request failed
|
|
14904
|
+
url=${req.url}
|
|
14905
|
+
status_code=${statusCode}
|
|
14906
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
14907
|
+
}
|
|
14890
14908
|
} else {
|
|
14891
|
-
|
|
14909
|
+
if (shouldLogBody) {
|
|
14910
|
+
appLog(`HTTP request completed
|
|
14911
|
+
url=${req.url}
|
|
14912
|
+
status_code=${statusCode}
|
|
14913
|
+
duration_ms=${durationMs}
|
|
14914
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
14915
|
+
} else {
|
|
14916
|
+
appLog(`HTTP request completed
|
|
14917
|
+
url=${req.url}
|
|
14918
|
+
status_code=${statusCode}
|
|
14919
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
14920
|
+
}
|
|
14892
14921
|
}
|
|
14893
14922
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14894
14923
|
});
|