@lark-apaas/nestjs-logger 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +66 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -14450,13 +14450,7 @@ var LogLevelState = class LogLevelState2 {
|
|
|
14450
14450
|
static {
|
|
14451
14451
|
__name(this, "LogLevelState");
|
|
14452
14452
|
}
|
|
14453
|
-
levels = /* @__PURE__ */ new Set(
|
|
14454
|
-
"log",
|
|
14455
|
-
"error",
|
|
14456
|
-
"warn",
|
|
14457
|
-
"debug",
|
|
14458
|
-
"verbose"
|
|
14459
|
-
]);
|
|
14453
|
+
levels = /* @__PURE__ */ new Set();
|
|
14460
14454
|
set(levels) {
|
|
14461
14455
|
this.levels = new Set(levels);
|
|
14462
14456
|
}
|
|
@@ -14487,6 +14481,61 @@ var LogLevelState = class LogLevelState2 {
|
|
|
14487
14481
|
}
|
|
14488
14482
|
return "fatal";
|
|
14489
14483
|
}
|
|
14484
|
+
/**
|
|
14485
|
+
* 根据 Pino 级别转换为 NestJS LogLevel 数组
|
|
14486
|
+
*/
|
|
14487
|
+
static fromPinoLevel(pinoLevel) {
|
|
14488
|
+
switch (pinoLevel) {
|
|
14489
|
+
case "trace":
|
|
14490
|
+
return [
|
|
14491
|
+
"verbose",
|
|
14492
|
+
"debug",
|
|
14493
|
+
"log",
|
|
14494
|
+
"warn",
|
|
14495
|
+
"error",
|
|
14496
|
+
"fatal"
|
|
14497
|
+
];
|
|
14498
|
+
case "debug":
|
|
14499
|
+
return [
|
|
14500
|
+
"debug",
|
|
14501
|
+
"log",
|
|
14502
|
+
"warn",
|
|
14503
|
+
"error",
|
|
14504
|
+
"fatal"
|
|
14505
|
+
];
|
|
14506
|
+
case "info":
|
|
14507
|
+
return [
|
|
14508
|
+
"log",
|
|
14509
|
+
"warn",
|
|
14510
|
+
"error",
|
|
14511
|
+
"fatal"
|
|
14512
|
+
];
|
|
14513
|
+
case "warn":
|
|
14514
|
+
return [
|
|
14515
|
+
"warn",
|
|
14516
|
+
"error",
|
|
14517
|
+
"fatal"
|
|
14518
|
+
];
|
|
14519
|
+
case "error":
|
|
14520
|
+
return [
|
|
14521
|
+
"error",
|
|
14522
|
+
"fatal"
|
|
14523
|
+
];
|
|
14524
|
+
case "fatal":
|
|
14525
|
+
return [
|
|
14526
|
+
"fatal"
|
|
14527
|
+
];
|
|
14528
|
+
case "silent":
|
|
14529
|
+
return [];
|
|
14530
|
+
default:
|
|
14531
|
+
return [
|
|
14532
|
+
"log",
|
|
14533
|
+
"warn",
|
|
14534
|
+
"error",
|
|
14535
|
+
"fatal"
|
|
14536
|
+
];
|
|
14537
|
+
}
|
|
14538
|
+
}
|
|
14490
14539
|
};
|
|
14491
14540
|
var BasePinoLogger = class _BasePinoLogger {
|
|
14492
14541
|
static {
|
|
@@ -14498,7 +14547,9 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14498
14547
|
constructor(logger, contextStore) {
|
|
14499
14548
|
this.logger = logger;
|
|
14500
14549
|
this.contextStore = contextStore;
|
|
14501
|
-
|
|
14550
|
+
const pinoLevel = this.logger.level;
|
|
14551
|
+
const nestLevels = LogLevelState.fromPinoLevel(pinoLevel);
|
|
14552
|
+
this.levelState.set(nestLevels);
|
|
14502
14553
|
}
|
|
14503
14554
|
setLogLevels(levels) {
|
|
14504
14555
|
this.levelState.set(levels);
|
|
@@ -14733,7 +14784,7 @@ function normalizeLevel(level) {
|
|
|
14733
14784
|
}
|
|
14734
14785
|
__name(normalizeLevel, "normalizeLevel");
|
|
14735
14786
|
var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
14736
|
-
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "
|
|
14787
|
+
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "trace"));
|
|
14737
14788
|
const maxBodyLengthEnv = process.env.LOG_MAX_BODY_LENGTH;
|
|
14738
14789
|
const maxBodyLength = maxBodyLengthEnv ? Number(maxBodyLengthEnv) : null;
|
|
14739
14790
|
return {
|
|
@@ -14742,7 +14793,7 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14742
14793
|
logRequestBody: process.env.LOG_REQUEST_BODY === "true",
|
|
14743
14794
|
logResponseBody: process.env.LOG_RESPONSE_BODY === "true",
|
|
14744
14795
|
maxBodyLength,
|
|
14745
|
-
sensitiveFields: (process.env.LOG_SENSITIVE_FIELDS || "
|
|
14796
|
+
sensitiveFields: (process.env.LOG_SENSITIVE_FIELDS || "").split(",").map((f) => f.trim())
|
|
14746
14797
|
};
|
|
14747
14798
|
});
|
|
14748
14799
|
|
|
@@ -14830,11 +14881,7 @@ var LoggingInterceptor = class {
|
|
|
14830
14881
|
duration_ms: durationMs
|
|
14831
14882
|
};
|
|
14832
14883
|
if (this.config.logResponseBody && responseData !== void 0) {
|
|
14833
|
-
|
|
14834
|
-
const isJsonResponse = this.isJsonContentType(contentType);
|
|
14835
|
-
if (isJsonResponse) {
|
|
14836
|
-
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14837
|
-
}
|
|
14884
|
+
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14838
14885
|
}
|
|
14839
14886
|
this.traceLogger.logStructured("verbose", "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14840
14887
|
}), (0, import_operators.catchError)((error) => {
|
|
@@ -14887,21 +14934,12 @@ var LoggingInterceptor = class {
|
|
|
14887
14934
|
} catch (error) {
|
|
14888
14935
|
return {
|
|
14889
14936
|
_error: "Failed to serialize data",
|
|
14890
|
-
|
|
14937
|
+
_type: typeof data,
|
|
14938
|
+
_constructor: data?.constructor?.name
|
|
14891
14939
|
};
|
|
14892
14940
|
}
|
|
14893
14941
|
}
|
|
14894
14942
|
/**
|
|
14895
|
-
* 判断是否是 JSON 响应类型
|
|
14896
|
-
*/
|
|
14897
|
-
isJsonContentType(contentType) {
|
|
14898
|
-
if (typeof contentType !== "string") {
|
|
14899
|
-
return false;
|
|
14900
|
-
}
|
|
14901
|
-
const contentTypeLower = contentType.toLowerCase();
|
|
14902
|
-
return contentTypeLower.includes("application/json");
|
|
14903
|
-
}
|
|
14904
|
-
/**
|
|
14905
14943
|
* 脱敏敏感字段
|
|
14906
14944
|
*/
|
|
14907
14945
|
maskSensitiveFields(data) {
|
|
@@ -15066,7 +15104,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15066
15104
|
provide: PINO_ROOT_LOGGER,
|
|
15067
15105
|
useFactory: /* @__PURE__ */ __name((config) => {
|
|
15068
15106
|
return createPinoLogger({
|
|
15069
|
-
level:
|
|
15107
|
+
level: config.level,
|
|
15070
15108
|
filePath: `${config.logDir}/app.log`
|
|
15071
15109
|
});
|
|
15072
15110
|
}, "useFactory"),
|
|
@@ -15077,7 +15115,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15077
15115
|
{
|
|
15078
15116
|
provide: TRACE_LOGGER,
|
|
15079
15117
|
useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
|
|
15080
|
-
level:
|
|
15118
|
+
level: config.level,
|
|
15081
15119
|
filePath: `${config.logDir}/trace.log`
|
|
15082
15120
|
}), requestContext), "useFactory"),
|
|
15083
15121
|
inject: [
|