@lark-apaas/nestjs-logger 1.0.1-alpha.1 → 1.0.1-alpha.3
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 +88 -5
- package/dist/index.cjs +38 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14371,7 +14371,7 @@ 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 {
|
|
14374
|
+
import { inspect } from "util";
|
|
14375
14375
|
|
|
14376
14376
|
// src/helper/constants.ts
|
|
14377
14377
|
var PINO_ROOT_LOGGER = Symbol("PINO_ROOT_LOGGER");
|
|
@@ -14667,8 +14667,12 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14667
14667
|
messageText: message
|
|
14668
14668
|
};
|
|
14669
14669
|
}
|
|
14670
|
+
const allMessages = [
|
|
14671
|
+
message,
|
|
14672
|
+
...extras.map((e) => stringifyParam(e))
|
|
14673
|
+
].join(" ");
|
|
14670
14674
|
return {
|
|
14671
|
-
messageText:
|
|
14675
|
+
messageText: allMessages
|
|
14672
14676
|
};
|
|
14673
14677
|
}
|
|
14674
14678
|
if (typeof message === "object" && message !== null) {
|
|
@@ -14728,6 +14732,18 @@ function mapLogLevelToPino(level) {
|
|
|
14728
14732
|
}
|
|
14729
14733
|
}
|
|
14730
14734
|
__name(mapLogLevelToPino, "mapLogLevelToPino");
|
|
14735
|
+
function stringifyParam(param) {
|
|
14736
|
+
if (typeof param === "string") {
|
|
14737
|
+
return param;
|
|
14738
|
+
}
|
|
14739
|
+
const inspectOptions = {
|
|
14740
|
+
depth: 4,
|
|
14741
|
+
colors: false,
|
|
14742
|
+
compact: true
|
|
14743
|
+
};
|
|
14744
|
+
return inspect(param, inspectOptions);
|
|
14745
|
+
}
|
|
14746
|
+
__name(stringifyParam, "stringifyParam");
|
|
14731
14747
|
function sanitizeValue(value) {
|
|
14732
14748
|
if (value === null || value === void 0) {
|
|
14733
14749
|
return value;
|
|
@@ -14773,7 +14789,7 @@ function normalizeLevel(level) {
|
|
|
14773
14789
|
}
|
|
14774
14790
|
__name(normalizeLevel, "normalizeLevel");
|
|
14775
14791
|
var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
14776
|
-
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "
|
|
14792
|
+
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "trace" : "trace"));
|
|
14777
14793
|
const maxBodyLengthEnv = process.env.LOG_MAX_BODY_LENGTH;
|
|
14778
14794
|
const maxBodyLength = maxBodyLengthEnv ? Number(maxBodyLengthEnv) : null;
|
|
14779
14795
|
return {
|
|
@@ -14863,7 +14879,8 @@ var LoggingInterceptor = class {
|
|
|
14863
14879
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
14864
14880
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
14865
14881
|
}
|
|
14866
|
-
this.appLogger.log(
|
|
14882
|
+
this.appLogger.log(`HTTP request started
|
|
14883
|
+
url=${req.url}`, "HTTPTraceInterceptor");
|
|
14867
14884
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
14868
14885
|
let logged = false;
|
|
14869
14886
|
res.on("finish", () => {
|
|
@@ -14890,15 +14907,29 @@ var LoggingInterceptor = class {
|
|
|
14890
14907
|
const shouldLogBody = this.config.logResponseBody && isJsonResponse && finalResponseBody !== void 0;
|
|
14891
14908
|
if (isError) {
|
|
14892
14909
|
if (shouldLogBody) {
|
|
14893
|
-
appLog(
|
|
14910
|
+
appLog(`HTTP request failed
|
|
14911
|
+
url=${req.url}
|
|
14912
|
+
status_code=${statusCode}
|
|
14913
|
+
duration_ms=${durationMs}
|
|
14914
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
14894
14915
|
} else {
|
|
14895
|
-
appLog(
|
|
14916
|
+
appLog(`HTTP request failed
|
|
14917
|
+
url=${req.url}
|
|
14918
|
+
status_code=${statusCode}
|
|
14919
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
14896
14920
|
}
|
|
14897
14921
|
} else {
|
|
14898
14922
|
if (shouldLogBody) {
|
|
14899
|
-
appLog(
|
|
14923
|
+
appLog(`HTTP request completed
|
|
14924
|
+
url=${req.url}
|
|
14925
|
+
status_code=${statusCode}
|
|
14926
|
+
duration_ms=${durationMs}
|
|
14927
|
+
response_body=${JSON.stringify(finalResponseBody ?? {})}`, "HTTPTraceInterceptor");
|
|
14900
14928
|
} else {
|
|
14901
|
-
appLog(
|
|
14929
|
+
appLog(`HTTP request completed
|
|
14930
|
+
url=${req.url}
|
|
14931
|
+
status_code=${statusCode}
|
|
14932
|
+
duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
14902
14933
|
}
|
|
14903
14934
|
}
|
|
14904
14935
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|