@lark-apaas/nestjs-logger 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +59 -87
- package/dist/index.cjs +7 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/LICENSE +0 -13
package/dist/index.js
CHANGED
|
@@ -14781,8 +14781,7 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14781
14781
|
logDir: process.env.LOG_DIR || "logs",
|
|
14782
14782
|
logRequestBody: process.env.LOG_REQUEST_BODY === "true",
|
|
14783
14783
|
logResponseBody: process.env.LOG_RESPONSE_BODY === "true",
|
|
14784
|
-
maxBodyLength
|
|
14785
|
-
sensitiveFields: (process.env.LOG_SENSITIVE_FIELDS || "").split(",").map((f) => f.trim())
|
|
14784
|
+
maxBodyLength
|
|
14786
14785
|
};
|
|
14787
14786
|
});
|
|
14788
14787
|
|
|
@@ -14829,7 +14828,7 @@ var LoggingInterceptor = class {
|
|
|
14829
14828
|
const req = httpContext.getRequest();
|
|
14830
14829
|
const res = httpContext.getResponse();
|
|
14831
14830
|
const method = req.method;
|
|
14832
|
-
const
|
|
14831
|
+
const path = req.path;
|
|
14833
14832
|
this.requestContext.setContext({
|
|
14834
14833
|
method,
|
|
14835
14834
|
path: url
|
|
@@ -14837,7 +14836,7 @@ var LoggingInterceptor = class {
|
|
|
14837
14836
|
const startedAt = Date.now();
|
|
14838
14837
|
const baseMeta = {
|
|
14839
14838
|
method,
|
|
14840
|
-
path
|
|
14839
|
+
path,
|
|
14841
14840
|
trace_id: req.requestId ?? req.id,
|
|
14842
14841
|
user_id: req.userContext?.userId ?? null,
|
|
14843
14842
|
tenant_id: req.userContext?.tenantId ?? null,
|
|
@@ -14903,15 +14902,14 @@ var LoggingInterceptor = class {
|
|
|
14903
14902
|
}));
|
|
14904
14903
|
}
|
|
14905
14904
|
/**
|
|
14906
|
-
*
|
|
14905
|
+
* 对数据进行截断处理
|
|
14907
14906
|
*/
|
|
14908
14907
|
sanitizeAndTruncate(data) {
|
|
14909
14908
|
try {
|
|
14910
|
-
const sanitized = this.maskSensitiveFields(data);
|
|
14911
14909
|
if (this.config.maxBodyLength === null) {
|
|
14912
|
-
return
|
|
14910
|
+
return data;
|
|
14913
14911
|
}
|
|
14914
|
-
const jsonStr = JSON.stringify(
|
|
14912
|
+
const jsonStr = JSON.stringify(data);
|
|
14915
14913
|
if (jsonStr.length > this.config.maxBodyLength) {
|
|
14916
14914
|
return {
|
|
14917
14915
|
_truncated: true,
|
|
@@ -14919,7 +14917,7 @@ var LoggingInterceptor = class {
|
|
|
14919
14917
|
_data: jsonStr.substring(0, this.config.maxBodyLength) + "..."
|
|
14920
14918
|
};
|
|
14921
14919
|
}
|
|
14922
|
-
return
|
|
14920
|
+
return data;
|
|
14923
14921
|
} catch (error) {
|
|
14924
14922
|
return {
|
|
14925
14923
|
_error: "Failed to serialize data",
|
|
@@ -14928,33 +14926,6 @@ var LoggingInterceptor = class {
|
|
|
14928
14926
|
};
|
|
14929
14927
|
}
|
|
14930
14928
|
}
|
|
14931
|
-
/**
|
|
14932
|
-
* 脱敏敏感字段
|
|
14933
|
-
*/
|
|
14934
|
-
maskSensitiveFields(data) {
|
|
14935
|
-
if (data === null || data === void 0) {
|
|
14936
|
-
return data;
|
|
14937
|
-
}
|
|
14938
|
-
if (Array.isArray(data)) {
|
|
14939
|
-
return data.map((item) => this.maskSensitiveFields(item));
|
|
14940
|
-
}
|
|
14941
|
-
if (typeof data === "object") {
|
|
14942
|
-
const result = {};
|
|
14943
|
-
for (const [key, value] of Object.entries(data)) {
|
|
14944
|
-
const lowerKey = key.toLowerCase();
|
|
14945
|
-
const isSensitive = this.config.sensitiveFields.some((field) => lowerKey.includes(field.toLowerCase()));
|
|
14946
|
-
if (isSensitive) {
|
|
14947
|
-
result[key] = "***MASKED***";
|
|
14948
|
-
} else if (typeof value === "object" && value !== null) {
|
|
14949
|
-
result[key] = this.maskSensitiveFields(value);
|
|
14950
|
-
} else {
|
|
14951
|
-
result[key] = value;
|
|
14952
|
-
}
|
|
14953
|
-
}
|
|
14954
|
-
return result;
|
|
14955
|
-
}
|
|
14956
|
-
return data;
|
|
14957
|
-
}
|
|
14958
14929
|
};
|
|
14959
14930
|
LoggingInterceptor = _ts_decorate3([
|
|
14960
14931
|
Injectable3(),
|