@lark-apaas/nestjs-logger 1.0.2-alpha.8 → 1.0.2-alpha.9
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 +28 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -27
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -14383,7 +14383,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
14383
14383
|
|
|
14384
14384
|
// src/service/app-logger.service.ts
|
|
14385
14385
|
var import_common = require("@nestjs/common");
|
|
14386
|
-
var import_util = require("util");
|
|
14387
14386
|
var import_nestjs_observable = require("@lark-apaas/nestjs-observable");
|
|
14388
14387
|
|
|
14389
14388
|
// src/helper/constants.ts
|
|
@@ -14575,6 +14574,26 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14575
14574
|
const { context, stack, extras } = this.extractOptionalParams(optionalParams, treatStack);
|
|
14576
14575
|
const requestState = this.contextStore.getContext();
|
|
14577
14576
|
const traceId = requestState?.requestId ?? null;
|
|
14577
|
+
const flatObject = /* @__PURE__ */ __name((extra) => {
|
|
14578
|
+
let res = {};
|
|
14579
|
+
try {
|
|
14580
|
+
extra.forEach((item) => {
|
|
14581
|
+
if (typeof item === "object" && item !== null) {
|
|
14582
|
+
res = {
|
|
14583
|
+
...res,
|
|
14584
|
+
...item
|
|
14585
|
+
};
|
|
14586
|
+
}
|
|
14587
|
+
});
|
|
14588
|
+
delete res.message;
|
|
14589
|
+
delete res.level;
|
|
14590
|
+
delete res.time;
|
|
14591
|
+
delete res.context;
|
|
14592
|
+
return res;
|
|
14593
|
+
} catch {
|
|
14594
|
+
}
|
|
14595
|
+
}, "flatObject");
|
|
14596
|
+
const processedExtra = flatObject(extras);
|
|
14578
14597
|
const payload = {
|
|
14579
14598
|
trace_id: traceId,
|
|
14580
14599
|
path: requestState?.path,
|
|
@@ -14582,12 +14601,13 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14582
14601
|
user_id: requestState?.userId ?? null,
|
|
14583
14602
|
app_id: requestState?.appId ?? null,
|
|
14584
14603
|
tenant_id: requestState?.tenantId ?? null,
|
|
14585
|
-
pid: process.pid
|
|
14604
|
+
pid: process.pid,
|
|
14605
|
+
...processedExtra
|
|
14586
14606
|
};
|
|
14587
14607
|
if (context) {
|
|
14588
14608
|
payload.context = context;
|
|
14589
14609
|
}
|
|
14590
|
-
const { messageText, stack: computedStack, data } = this.buildMessagePayload(message
|
|
14610
|
+
const { messageText, stack: computedStack, data } = this.buildMessagePayload(message);
|
|
14591
14611
|
if (stack) {
|
|
14592
14612
|
payload.stack = stack;
|
|
14593
14613
|
} else if (computedStack) {
|
|
@@ -14603,7 +14623,7 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14603
14623
|
} else {
|
|
14604
14624
|
this.logger[pinoLevel](sanitizedPayload);
|
|
14605
14625
|
}
|
|
14606
|
-
this.observableService.log(level, messageText ?? "",
|
|
14626
|
+
this.observableService.log(level, messageText ?? "", payload);
|
|
14607
14627
|
}
|
|
14608
14628
|
extractOptionalParams(optionalParams, treatStack) {
|
|
14609
14629
|
const params = [
|
|
@@ -14631,7 +14651,7 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14631
14651
|
extras: params
|
|
14632
14652
|
};
|
|
14633
14653
|
}
|
|
14634
|
-
buildMessagePayload(message
|
|
14654
|
+
buildMessagePayload(message) {
|
|
14635
14655
|
if (message instanceof Error) {
|
|
14636
14656
|
return {
|
|
14637
14657
|
messageText: message.message,
|
|
@@ -14639,17 +14659,8 @@ var BasePinoLogger = class _BasePinoLogger {
|
|
|
14639
14659
|
};
|
|
14640
14660
|
}
|
|
14641
14661
|
if (typeof message === "string") {
|
|
14642
|
-
if (extras.length === 0) {
|
|
14643
|
-
return {
|
|
14644
|
-
messageText: message
|
|
14645
|
-
};
|
|
14646
|
-
}
|
|
14647
|
-
const allMessages = [
|
|
14648
|
-
message,
|
|
14649
|
-
...extras.map((e) => stringifyParam(e))
|
|
14650
|
-
].join(" ");
|
|
14651
14662
|
return {
|
|
14652
|
-
messageText:
|
|
14663
|
+
messageText: message
|
|
14653
14664
|
};
|
|
14654
14665
|
}
|
|
14655
14666
|
if (typeof message === "object" && message !== null) {
|
|
@@ -14709,18 +14720,6 @@ function mapLogLevelToPino(level) {
|
|
|
14709
14720
|
}
|
|
14710
14721
|
}
|
|
14711
14722
|
__name(mapLogLevelToPino, "mapLogLevelToPino");
|
|
14712
|
-
function stringifyParam(param) {
|
|
14713
|
-
if (typeof param === "string") {
|
|
14714
|
-
return param;
|
|
14715
|
-
}
|
|
14716
|
-
const inspectOptions = {
|
|
14717
|
-
depth: 4,
|
|
14718
|
-
colors: false,
|
|
14719
|
-
compact: true
|
|
14720
|
-
};
|
|
14721
|
-
return (0, import_util.inspect)(param, inspectOptions);
|
|
14722
|
-
}
|
|
14723
|
-
__name(stringifyParam, "stringifyParam");
|
|
14724
14723
|
function sanitizeValue(value) {
|
|
14725
14724
|
if (value === null || value === void 0) {
|
|
14726
14725
|
return value;
|
|
@@ -14783,7 +14782,7 @@ var logger_config_default = (0, import_config.registerAs)("logger", () => {
|
|
|
14783
14782
|
var import_common2 = require("@nestjs/common");
|
|
14784
14783
|
var import_config2 = __toESM(require_config2(), 1);
|
|
14785
14784
|
var import_operators = __toESM(require_operators(), 1);
|
|
14786
|
-
var
|
|
14785
|
+
var import_util = require("util");
|
|
14787
14786
|
var import_nestjs_common2 = require("@lark-apaas/nestjs-common");
|
|
14788
14787
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
14789
14788
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -14915,7 +14914,7 @@ duration_ms=${durationMs}`, "HTTPTraceInterceptor");
|
|
|
14915
14914
|
this.traceLogger.logStructured(traceLevel, isError ? "HTTP request failed" : "HTTP request completed", responseMeta, "HTTPTraceInterceptor");
|
|
14916
14915
|
});
|
|
14917
14916
|
return next.handle().pipe((0, import_operators.catchError)((error) => {
|
|
14918
|
-
this.appLogger.error((0,
|
|
14917
|
+
this.appLogger.error((0, import_util.format)("HTTP request exception\nmethod=%s url=%s\nerror=%o", req.method, req.url, error), "HTTPTraceInterceptor");
|
|
14919
14918
|
throw error;
|
|
14920
14919
|
}));
|
|
14921
14920
|
}
|