@lark-apaas/nestjs-logger 0.1.0-alpha.10 → 0.1.0-alpha.12
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 +7 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14831,7 +14831,7 @@ var LoggingInterceptor = class {
|
|
|
14831
14831
|
const path = req.path;
|
|
14832
14832
|
this.requestContext.setContext({
|
|
14833
14833
|
method,
|
|
14834
|
-
path
|
|
14834
|
+
path
|
|
14835
14835
|
});
|
|
14836
14836
|
const startedAt = Date.now();
|
|
14837
14837
|
const baseMeta = {
|
|
@@ -14844,7 +14844,6 @@ var LoggingInterceptor = class {
|
|
|
14844
14844
|
ip: req.ip ?? null,
|
|
14845
14845
|
pid: process.pid
|
|
14846
14846
|
};
|
|
14847
|
-
this.appLogger.logStructured("log", "HTTP request started", baseMeta, "HTTPTraceInterceptor");
|
|
14848
14847
|
const requestMeta = {
|
|
14849
14848
|
...baseMeta
|
|
14850
14849
|
};
|
|
@@ -14854,15 +14853,12 @@ var LoggingInterceptor = class {
|
|
|
14854
14853
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
14855
14854
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
14856
14855
|
}
|
|
14856
|
+
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"]);
|
|
14857
14857
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
14858
14858
|
return next.handle().pipe((0, import_operators.tap)((responseData) => {
|
|
14859
14859
|
const durationMs = Date.now() - startedAt;
|
|
14860
14860
|
const statusCode = res.statusCode;
|
|
14861
|
-
this.appLogger.
|
|
14862
|
-
...baseMeta,
|
|
14863
|
-
status_code: statusCode,
|
|
14864
|
-
duration_ms: durationMs
|
|
14865
|
-
}, "HTTPTraceInterceptor");
|
|
14861
|
+
const appLog = res.statusCode >= 400 ? this.appLogger.error : this.appLogger.log;
|
|
14866
14862
|
const responseMeta = {
|
|
14867
14863
|
...baseMeta,
|
|
14868
14864
|
status_code: statusCode,
|
|
@@ -14872,6 +14868,7 @@ var LoggingInterceptor = class {
|
|
|
14872
14868
|
responseMeta["response_body"] = this.sanitizeAndTruncate(responseData);
|
|
14873
14869
|
}
|
|
14874
14870
|
const traceLevel = res.statusCode >= 400 ? "error" : "verbose";
|
|
14871
|
+
appLog("HTTP request completed\n url=%s status_code=%d \n duration_ms=%d \nresponse_body=%o", req.url, statusCode, durationMs, responseMeta.response_body);
|
|
14875
14872
|
this.traceLogger.logStructured(traceLevel, "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14876
14873
|
}), (0, import_operators.catchError)((error) => {
|
|
14877
14874
|
const durationMs = Date.now() - startedAt;
|
|
@@ -14884,7 +14881,6 @@ var LoggingInterceptor = class {
|
|
|
14884
14881
|
if (error instanceof Error) {
|
|
14885
14882
|
linkMeta["error_message"] = error.message;
|
|
14886
14883
|
}
|
|
14887
|
-
this.appLogger.logStructured("log", "HTTP request failed", linkMeta, "HTTPTraceInterceptor");
|
|
14888
14884
|
const meta = {
|
|
14889
14885
|
...baseMeta,
|
|
14890
14886
|
status_code: statusCode,
|
|
@@ -14898,7 +14894,8 @@ var LoggingInterceptor = class {
|
|
|
14898
14894
|
} else {
|
|
14899
14895
|
meta["error"] = String(error);
|
|
14900
14896
|
}
|
|
14901
|
-
this.
|
|
14897
|
+
this.appLogger.error("HTTP request failed\n url=%s status_code=%d \n duration_ms=%d \nerror=%o", req.url, statusCode, durationMs, meta.error);
|
|
14898
|
+
this.traceLogger.logStructured("error", "HTTP request failed", meta, "HTTPTraceInterceptor");
|
|
14902
14899
|
throw error;
|
|
14903
14900
|
}));
|
|
14904
14901
|
}
|
|
@@ -14977,7 +14974,7 @@ function createPinoLogger(config) {
|
|
|
14977
14974
|
}
|
|
14978
14975
|
__name(createPinoLogger, "createPinoLogger");
|
|
14979
14976
|
function createFileDestination(pathname) {
|
|
14980
|
-
const target = pathname && pathname.length > 0 ? pathname : "logs/
|
|
14977
|
+
const target = pathname && pathname.length > 0 ? pathname : "logs/server.log";
|
|
14981
14978
|
const resolved = isAbsolute(target) ? target : join(process.cwd(), target);
|
|
14982
14979
|
const dir = dirname(resolved);
|
|
14983
14980
|
if (!existsSync(dir)) {
|