@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.js
CHANGED
|
@@ -14439,13 +14439,7 @@ var LogLevelState = class LogLevelState2 {
|
|
|
14439
14439
|
static {
|
|
14440
14440
|
__name(this, "LogLevelState");
|
|
14441
14441
|
}
|
|
14442
|
-
levels = /* @__PURE__ */ new Set(
|
|
14443
|
-
"log",
|
|
14444
|
-
"error",
|
|
14445
|
-
"warn",
|
|
14446
|
-
"debug",
|
|
14447
|
-
"verbose"
|
|
14448
|
-
]);
|
|
14442
|
+
levels = /* @__PURE__ */ new Set();
|
|
14449
14443
|
set(levels) {
|
|
14450
14444
|
this.levels = new Set(levels);
|
|
14451
14445
|
}
|
|
@@ -14476,6 +14470,61 @@ var LogLevelState = class LogLevelState2 {
|
|
|
14476
14470
|
}
|
|
14477
14471
|
return "fatal";
|
|
14478
14472
|
}
|
|
14473
|
+
/**
|
|
14474
|
+
* 根据 Pino 级别转换为 NestJS LogLevel 数组
|
|
14475
|
+
*/
|
|
14476
|
+
static fromPinoLevel(pinoLevel) {
|
|
14477
|
+
switch (pinoLevel) {
|
|
14478
|
+
case "trace":
|
|
14479
|
+
return [
|
|
14480
|
+
"verbose",
|
|
14481
|
+
"debug",
|
|
14482
|
+
"log",
|
|
14483
|
+
"warn",
|
|
14484
|
+
"error",
|
|
14485
|
+
"fatal"
|
|
14486
|
+
];
|
|
14487
|
+
case "debug":
|
|
14488
|
+
return [
|
|
14489
|
+
"debug",
|
|
14490
|
+
"log",
|
|
14491
|
+
"warn",
|
|
14492
|
+
"error",
|
|
14493
|
+
"fatal"
|
|
14494
|
+
];
|
|
14495
|
+
case "info":
|
|
14496
|
+
return [
|
|
14497
|
+
"log",
|
|
14498
|
+
"warn",
|
|
14499
|
+
"error",
|
|
14500
|
+
"fatal"
|
|
14501
|
+
];
|
|
14502
|
+
case "warn":
|
|
14503
|
+
return [
|
|
14504
|
+
"warn",
|
|
14505
|
+
"error",
|
|
14506
|
+
"fatal"
|
|
14507
|
+
];
|
|
14508
|
+
case "error":
|
|
14509
|
+
return [
|
|
14510
|
+
"error",
|
|
14511
|
+
"fatal"
|
|
14512
|
+
];
|
|
14513
|
+
case "fatal":
|
|
14514
|
+
return [
|
|
14515
|
+
"fatal"
|
|
14516
|
+
];
|
|
14517
|
+
case "silent":
|
|
14518
|
+
return [];
|
|
14519
|
+
default:
|
|
14520
|
+
return [
|
|
14521
|
+
"log",
|
|
14522
|
+
"warn",
|
|
14523
|
+
"error",
|
|
14524
|
+
"fatal"
|
|
14525
|
+
];
|
|
14526
|
+
}
|
|
14527
|
+
}
|
|
14479
14528
|
};
|
|
14480
14529
|
var BasePinoLogger = class _BasePinoLogger {
|
|
14481
14530
|
static {
|
|
@@ -14487,7 +14536,9 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14487
14536
|
constructor(logger, contextStore) {
|
|
14488
14537
|
this.logger = logger;
|
|
14489
14538
|
this.contextStore = contextStore;
|
|
14490
|
-
|
|
14539
|
+
const pinoLevel = this.logger.level;
|
|
14540
|
+
const nestLevels = LogLevelState.fromPinoLevel(pinoLevel);
|
|
14541
|
+
this.levelState.set(nestLevels);
|
|
14491
14542
|
}
|
|
14492
14543
|
setLogLevels(levels) {
|
|
14493
14544
|
this.levelState.set(levels);
|
|
@@ -14722,7 +14773,7 @@ function normalizeLevel(level) {
|
|
|
14722
14773
|
}
|
|
14723
14774
|
__name(normalizeLevel, "normalizeLevel");
|
|
14724
14775
|
var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
14725
|
-
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "
|
|
14776
|
+
const level = normalizeLevel(process.env.LOGGER_LEVEL || (process.env.NODE_ENV === "production" ? "info" : "trace"));
|
|
14726
14777
|
const maxBodyLengthEnv = process.env.LOG_MAX_BODY_LENGTH;
|
|
14727
14778
|
const maxBodyLength = maxBodyLengthEnv ? Number(maxBodyLengthEnv) : null;
|
|
14728
14779
|
return {
|
|
@@ -14731,7 +14782,7 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14731
14782
|
logRequestBody: process.env.LOG_REQUEST_BODY === "true",
|
|
14732
14783
|
logResponseBody: process.env.LOG_RESPONSE_BODY === "true",
|
|
14733
14784
|
maxBodyLength,
|
|
14734
|
-
sensitiveFields: (process.env.LOG_SENSITIVE_FIELDS || "
|
|
14785
|
+
sensitiveFields: (process.env.LOG_SENSITIVE_FIELDS || "").split(",").map((f) => f.trim())
|
|
14735
14786
|
};
|
|
14736
14787
|
});
|
|
14737
14788
|
|
|
@@ -14819,11 +14870,7 @@ var LoggingInterceptor = class {
|
|
|
14819
14870
|
duration_ms: durationMs
|
|
14820
14871
|
};
|
|
14821
14872
|
if (this.config.logResponseBody && responseData !== void 0) {
|
|
14822
|
-
|
|
14823
|
-
const isJsonResponse = this.isJsonContentType(contentType);
|
|
14824
|
-
if (isJsonResponse) {
|
|
14825
|
-
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14826
|
-
}
|
|
14873
|
+
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14827
14874
|
}
|
|
14828
14875
|
this.traceLogger.logStructured("verbose", "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14829
14876
|
}), (0, import_operators.catchError)((error) => {
|
|
@@ -14876,21 +14923,12 @@ var LoggingInterceptor = class {
|
|
|
14876
14923
|
} catch (error) {
|
|
14877
14924
|
return {
|
|
14878
14925
|
_error: "Failed to serialize data",
|
|
14879
|
-
|
|
14926
|
+
_type: typeof data,
|
|
14927
|
+
_constructor: data?.constructor?.name
|
|
14880
14928
|
};
|
|
14881
14929
|
}
|
|
14882
14930
|
}
|
|
14883
14931
|
/**
|
|
14884
|
-
* 判断是否是 JSON 响应类型
|
|
14885
|
-
*/
|
|
14886
|
-
isJsonContentType(contentType) {
|
|
14887
|
-
if (typeof contentType !== "string") {
|
|
14888
|
-
return false;
|
|
14889
|
-
}
|
|
14890
|
-
const contentTypeLower = contentType.toLowerCase();
|
|
14891
|
-
return contentTypeLower.includes("application/json");
|
|
14892
|
-
}
|
|
14893
|
-
/**
|
|
14894
14932
|
* 脱敏敏感字段
|
|
14895
14933
|
*/
|
|
14896
14934
|
maskSensitiveFields(data) {
|
|
@@ -15055,7 +15093,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15055
15093
|
provide: PINO_ROOT_LOGGER,
|
|
15056
15094
|
useFactory: /* @__PURE__ */ __name((config) => {
|
|
15057
15095
|
return createPinoLogger({
|
|
15058
|
-
level:
|
|
15096
|
+
level: config.level,
|
|
15059
15097
|
filePath: `${config.logDir}/app.log`
|
|
15060
15098
|
});
|
|
15061
15099
|
}, "useFactory"),
|
|
@@ -15066,7 +15104,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15066
15104
|
{
|
|
15067
15105
|
provide: TRACE_LOGGER,
|
|
15068
15106
|
useFactory: /* @__PURE__ */ __name((requestContext, config) => new PinoLoggerService(createPinoLogger({
|
|
15069
|
-
level:
|
|
15107
|
+
level: config.level,
|
|
15070
15108
|
filePath: `${config.logDir}/trace.log`
|
|
15071
15109
|
}), requestContext), "useFactory"),
|
|
15072
15110
|
inject: [
|