@lark-apaas/nestjs-logger 0.1.0-alpha.9 → 1.0.1-alpha.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/README.md +24 -0
- package/dist/index.cjs +34 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10567,7 +10567,7 @@ var require_tap = __commonJS({
|
|
|
10567
10567
|
var lift_1 = require_lift();
|
|
10568
10568
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
10569
10569
|
var identity_1 = require_identity();
|
|
10570
|
-
function
|
|
10570
|
+
function tap(observerOrNext, error, complete) {
|
|
10571
10571
|
var tapObserver = isFunction_1.isFunction(observerOrNext) || error || complete ? {
|
|
10572
10572
|
next: observerOrNext,
|
|
10573
10573
|
error,
|
|
@@ -10600,8 +10600,8 @@ var require_tap = __commonJS({
|
|
|
10600
10600
|
}));
|
|
10601
10601
|
}) : identity_1.identity;
|
|
10602
10602
|
}
|
|
10603
|
-
__name(
|
|
10604
|
-
exports.tap =
|
|
10603
|
+
__name(tap, "tap");
|
|
10604
|
+
exports.tap = tap;
|
|
10605
10605
|
}
|
|
10606
10606
|
});
|
|
10607
10607
|
|
|
@@ -14844,7 +14844,16 @@ var LoggingInterceptor = class {
|
|
|
14844
14844
|
ip: req.ip ?? null,
|
|
14845
14845
|
pid: process.pid
|
|
14846
14846
|
};
|
|
14847
|
-
|
|
14847
|
+
const originalJson = res.json.bind(res);
|
|
14848
|
+
const originalSend = res.send.bind(res);
|
|
14849
|
+
res.json = function(body) {
|
|
14850
|
+
res.__finalResponseBody = body;
|
|
14851
|
+
return originalJson(body);
|
|
14852
|
+
};
|
|
14853
|
+
res.send = function(body) {
|
|
14854
|
+
res.__finalResponseBody = body;
|
|
14855
|
+
return originalSend(body);
|
|
14856
|
+
};
|
|
14848
14857
|
const requestMeta = {
|
|
14849
14858
|
...baseMeta
|
|
14850
14859
|
};
|
|
@@ -14854,50 +14863,36 @@ var LoggingInterceptor = class {
|
|
|
14854
14863
|
if (this.config.logRequestBody && Object.keys(req.query || {}).length > 0) {
|
|
14855
14864
|
requestMeta["query_params"] = this.sanitizeAndTruncate(req.query);
|
|
14856
14865
|
}
|
|
14866
|
+
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
14867
|
this.traceLogger.logStructured("verbose", "HTTP request started", requestMeta, "HTTPTraceInterceptor");
|
|
14858
|
-
|
|
14868
|
+
let logged = false;
|
|
14869
|
+
res.on("finish", () => {
|
|
14870
|
+
if (logged) {
|
|
14871
|
+
return;
|
|
14872
|
+
}
|
|
14873
|
+
logged = true;
|
|
14859
14874
|
const durationMs = Date.now() - startedAt;
|
|
14860
14875
|
const statusCode = res.statusCode;
|
|
14861
|
-
this.appLogger.logStructured("log", "HTTP request completed", {
|
|
14862
|
-
...baseMeta,
|
|
14863
|
-
status_code: statusCode,
|
|
14864
|
-
duration_ms: durationMs
|
|
14865
|
-
}, "HTTPTraceInterceptor");
|
|
14866
14876
|
const responseMeta = {
|
|
14867
14877
|
...baseMeta,
|
|
14868
14878
|
status_code: statusCode,
|
|
14869
14879
|
duration_ms: durationMs
|
|
14870
14880
|
};
|
|
14871
|
-
|
|
14872
|
-
|
|
14881
|
+
const finalResponseBody = res.__finalResponseBody;
|
|
14882
|
+
if (this.config.logResponseBody && finalResponseBody !== void 0) {
|
|
14883
|
+
responseMeta["response_body"] = this.sanitizeAndTruncate(finalResponseBody);
|
|
14873
14884
|
}
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
const
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
...baseMeta,
|
|
14880
|
-
status_code: statusCode,
|
|
14881
|
-
duration_ms: durationMs
|
|
14882
|
-
};
|
|
14883
|
-
if (error instanceof Error) {
|
|
14884
|
-
linkMeta["error_message"] = error.message;
|
|
14885
|
-
}
|
|
14886
|
-
this.appLogger.logStructured("log", "HTTP request failed", linkMeta, "HTTPTraceInterceptor");
|
|
14887
|
-
const meta = {
|
|
14888
|
-
...baseMeta,
|
|
14889
|
-
status_code: statusCode,
|
|
14890
|
-
duration_ms: durationMs
|
|
14891
|
-
};
|
|
14892
|
-
if (error instanceof Error) {
|
|
14893
|
-
meta["error"] = {
|
|
14894
|
-
message: error.message,
|
|
14895
|
-
stack: error.stack
|
|
14896
|
-
};
|
|
14885
|
+
const isError = statusCode >= 400;
|
|
14886
|
+
const appLog = this.appLogger[isError ? "error" : "log"].bind(this.appLogger);
|
|
14887
|
+
const traceLevel = isError ? "error" : "verbose";
|
|
14888
|
+
if (isError) {
|
|
14889
|
+
appLog("HTTP request failed\n url=%s \n status_code=%d \n duration_ms=%d \n response_body=%o", req.url, statusCode, durationMs, finalResponseBody ?? {});
|
|
14897
14890
|
} else {
|
|
14898
|
-
|
|
14891
|
+
appLog("HTTP request completed\n url=%s \n status_code=%d \n duration_ms=%d \n response_body=%o", req.url, statusCode, durationMs, finalResponseBody ?? {});
|
|
14899
14892
|
}
|
|
14900
|
-
this.traceLogger.logStructured(
|
|
14893
|
+
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14894
|
+
});
|
|
14895
|
+
return next.handle().pipe((0, import_operators.catchError)((error) => {
|
|
14901
14896
|
throw error;
|
|
14902
14897
|
}));
|
|
14903
14898
|
}
|
|
@@ -14976,7 +14971,7 @@ function createPinoLogger(config) {
|
|
|
14976
14971
|
}
|
|
14977
14972
|
__name(createPinoLogger, "createPinoLogger");
|
|
14978
14973
|
function createFileDestination(pathname) {
|
|
14979
|
-
const target = pathname && pathname.length > 0 ? pathname : "logs/
|
|
14974
|
+
const target = pathname && pathname.length > 0 ? pathname : "logs/server.log";
|
|
14980
14975
|
const resolved = isAbsolute(target) ? target : join(process.cwd(), target);
|
|
14981
14976
|
const dir = dirname(resolved);
|
|
14982
14977
|
if (!existsSync(dir)) {
|
|
@@ -15065,7 +15060,7 @@ LoggerModule = _ts_decorate5([
|
|
|
15065
15060
|
useFactory: /* @__PURE__ */ __name((config) => {
|
|
15066
15061
|
return createPinoLogger({
|
|
15067
15062
|
level: config.level,
|
|
15068
|
-
filePath: `${config.logDir}/
|
|
15063
|
+
filePath: `${config.logDir}/server.log`
|
|
15069
15064
|
});
|
|
15070
15065
|
}, "useFactory"),
|
|
15071
15066
|
inject: [
|