@lark-apaas/nestjs-logger 0.1.0-alpha.9 → 1.0.0
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 +9 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -14855,7 +14855,6 @@ var LoggingInterceptor = class {
|
|
|
14855
14855
|
ip: req.ip ?? null,
|
|
14856
14856
|
pid: process.pid
|
|
14857
14857
|
};
|
|
14858
|
-
this.appLogger.logStructured("log", "HTTP request started", baseMeta, "HTTPTraceInterceptor");
|
|
14859
14858
|
const requestMeta = {
|
|
14860
14859
|
...baseMeta
|
|
14861
14860
|
};
|
|
@@ -14865,15 +14864,12 @@ var LoggingInterceptor = class {
|
|
|
14865
14864
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
14866
14865
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
14867
14866
|
}
|
|
14867
|
+
this.appLogger.log("HTTP request started \n url=%s \n request_query=%o \n request_body=%o", req.url, requestMeta["query_params"] ?? {}, requestMeta["request_body"] ?? {});
|
|
14868
14868
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
14869
14869
|
return next.handle().pipe((0, import_operators.tap)((responseData) => {
|
|
14870
14870
|
const durationMs = Date.now() - startedAt;
|
|
14871
14871
|
const statusCode = res.statusCode;
|
|
14872
|
-
this.appLogger.
|
|
14873
|
-
...baseMeta,
|
|
14874
|
-
status_code: statusCode,
|
|
14875
|
-
duration_ms: durationMs
|
|
14876
|
-
}, "HTTPTraceInterceptor");
|
|
14872
|
+
const appLog = this.appLogger[res.statusCode >= 400 ? "error" : "log"].bind(this.appLogger);
|
|
14877
14873
|
const responseMeta = {
|
|
14878
14874
|
...baseMeta,
|
|
14879
14875
|
status_code: statusCode,
|
|
@@ -14882,7 +14878,9 @@ var LoggingInterceptor = class {
|
|
|
14882
14878
|
if (this.config.logResponseBody && responseData !== void 0) {
|
|
14883
14879
|
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14884
14880
|
}
|
|
14885
|
-
|
|
14881
|
+
const traceLevel = res.statusCode >= 400 ? "error" : "verbose";
|
|
14882
|
+
appLog("HTTP request completed\n url=%s \n status_code=%d \n duration_ms=%d \n response_body=%o", req.url, statusCode, durationMs, responseMeta.response_body ?? {});
|
|
14883
|
+
this.traceLogger.logStructured(traceLevel, "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14886
14884
|
}), (0, import_operators.catchError)((error) => {
|
|
14887
14885
|
const durationMs = Date.now() - startedAt;
|
|
14888
14886
|
const statusCode = res.statusCode >= 400 ? res.statusCode : 500;
|
|
@@ -14894,7 +14892,6 @@ var LoggingInterceptor = class {
|
|
|
14894
14892
|
if (error instanceof Error) {
|
|
14895
14893
|
linkMeta["error_message"] = error.message;
|
|
14896
14894
|
}
|
|
14897
|
-
this.appLogger.logStructured("log", "HTTP request failed", linkMeta, "HTTPTraceInterceptor");
|
|
14898
14895
|
const meta = {
|
|
14899
14896
|
...baseMeta,
|
|
14900
14897
|
status_code: statusCode,
|
|
@@ -14908,7 +14905,8 @@ var LoggingInterceptor = class {
|
|
|
14908
14905
|
} else {
|
|
14909
14906
|
meta["error"] = String(error);
|
|
14910
14907
|
}
|
|
14911
|
-
this.
|
|
14908
|
+
this.appLogger.error("HTTP request failed\n url=%s \n status_code=%d \n duration_ms=%d \n error=%o", req.url, statusCode, durationMs, meta.error);
|
|
14909
|
+
this.traceLogger.logStructured("error", "HTTP request failed", meta, "HTTPTraceInterceptor");
|
|
14912
14910
|
throw error;
|
|
14913
14911
|
}));
|
|
14914
14912
|
}
|
|
@@ -14987,7 +14985,7 @@ function createPinoLogger(config) {
|
|
|
14987
14985
|
}
|
|
14988
14986
|
__name(createPinoLogger, "createPinoLogger");
|
|
14989
14987
|
function createFileDestination(pathname) {
|
|
14990
|
-
const target = pathname && pathname.length > 0 ? pathname : "logs/
|
|
14988
|
+
const target = pathname && pathname.length > 0 ? pathname : "logs/server.log";
|
|
14991
14989
|
const resolved = (0, import_path.isAbsolute)(target) ? target : (0, import_path.join)(process.cwd(), target);
|
|
14992
14990
|
const dir = (0, import_path.dirname)(resolved);
|
|
14993
14991
|
if (!(0, import_fs.existsSync)(dir)) {
|
|
@@ -15076,7 +15074,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15076
15074
|
useFactory: /* @__PURE__ */ __name((config) => {
|
|
15077
15075
|
return createPinoLogger({
|
|
15078
15076
|
level: config.level,
|
|
15079
|
-
filePath: `${config.logDir}/
|
|
15077
|
+
filePath: `${config.logDir}/server.log`
|
|
15080
15078
|
});
|
|
15081
15079
|
}, "useFactory"),
|
|
15082
15080
|
inject: [
|