logixia 2.0.0 → 2.0.6
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 +172 -2597
- package/dist/async-context-2mbUKhcl.mjs +132 -0
- package/dist/async-context-2mbUKhcl.mjs.map +1 -0
- package/dist/async-context-DUFMDYAr.js +148 -0
- package/dist/async-context-DUFMDYAr.js.map +1 -0
- package/dist/{azure-monitor.transport-CrvfHd9C.js → azure-monitor.transport-Bu4S2I2q.js} +32 -20
- package/dist/azure-monitor.transport-Bu4S2I2q.js.map +1 -0
- package/dist/{azure-monitor.transport-Cn_3Usvu.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts} +3 -6
- package/dist/azure-monitor.transport-Bvf7Xegt.d.ts.map +1 -0
- package/dist/{azure-monitor.transport-CHnjVRF-.mjs → azure-monitor.transport-C1RWAumT.mjs} +27 -15
- package/dist/azure-monitor.transport-C1RWAumT.mjs.map +1 -0
- package/dist/{azure-monitor.transport-D7Da4RAb.d.mts → azure-monitor.transport-CbSHOnNX.d.mts} +3 -6
- package/dist/azure-monitor.transport-CbSHOnNX.d.mts.map +1 -0
- package/dist/azure.d.mts +1 -2
- package/dist/azure.d.ts +1 -2
- package/dist/azure.js +3 -6
- package/dist/azure.mjs +1 -6
- package/dist/{batch-buffer-PGvSgbmd.mjs → batch-buffer-BvXLDPlV.mjs} +21 -7
- package/dist/batch-buffer-BvXLDPlV.mjs.map +1 -0
- package/dist/{batch-buffer-BY-mRWIK.js → batch-buffer-C7Am4Mw-.js} +53 -40
- package/dist/batch-buffer-C7Am4Mw-.js.map +1 -0
- package/dist/browser.d.mts +47 -27
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +47 -27
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +464 -62
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +465 -65
- package/dist/browser.mjs.map +1 -1
- package/dist/{builder-0gEzRopq.mjs → builder-DhNhvOkt.mjs} +307 -246
- package/dist/builder-DhNhvOkt.mjs.map +1 -0
- package/dist/{builder-D44QktIo.js → builder-yFvJrz7o.js} +435 -399
- package/dist/builder-yFvJrz7o.js.map +1 -0
- package/dist/cli/index.js +216 -125
- package/dist/cloudwatch.d.mts +1 -2
- package/dist/cloudwatch.d.ts +1 -2
- package/dist/cloudwatch.js +3 -7
- package/dist/cloudwatch.mjs +1 -7
- package/dist/{cloudwatch.transport-DsEq633o.d.ts → cloudwatch.transport-CQyT6U91.d.ts} +2 -6
- package/dist/cloudwatch.transport-CQyT6U91.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-BO1ahxw-.js → cloudwatch.transport-Ch1Uae-0.js} +61 -36
- package/dist/cloudwatch.transport-Ch1Uae-0.js.map +1 -0
- package/dist/{cloudwatch.transport-UlyZFWMn.d.mts → cloudwatch.transport-CjVrI6S4.d.mts} +2 -6
- package/dist/cloudwatch.transport-CjVrI6S4.d.mts.map +1 -0
- package/dist/{cloudwatch.transport-DZ6ies7g.mjs → cloudwatch.transport-DZqF2xZO.mjs} +54 -28
- package/dist/cloudwatch.transport-DZqF2xZO.mjs.map +1 -0
- package/dist/{coerce.utils-Cu6IUTgX.mjs → coerce.utils-B_rEudCn.mjs} +3 -4
- package/dist/{coerce.utils-Cu6IUTgX.mjs.map → coerce.utils-B_rEudCn.mjs.map} +1 -1
- package/dist/{coerce.utils-B-LilukN.js → coerce.utils-C1C5sIX0.js} +8 -10
- package/dist/{coerce.utils-B-LilukN.js.map → coerce.utils-C1C5sIX0.js.map} +1 -1
- package/dist/correlation.d.mts +15 -69
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +15 -69
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +69 -20
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +67 -17
- package/dist/correlation.mjs.map +1 -1
- package/dist/{entry-fields-BvOLFlJ4.js → entry-fields-BSLkzw18.js} +16 -13
- package/dist/entry-fields-BSLkzw18.js.map +1 -0
- package/dist/{entry-fields-BJkuPnIg.mjs → entry-fields-J1OBi24o.mjs} +11 -7
- package/dist/entry-fields-J1OBi24o.mjs.map +1 -0
- package/dist/gcp.d.mts +1 -2
- package/dist/gcp.d.ts +1 -2
- package/dist/gcp.js +3 -7
- package/dist/gcp.mjs +1 -7
- package/dist/{gcp.transport-B7oc97sG.d.ts → gcp.transport-BCIvdFV-.d.ts} +5 -8
- package/dist/gcp.transport-BCIvdFV-.d.ts.map +1 -0
- package/dist/{gcp.transport-GrJurKo8.d.mts → gcp.transport-D9SdLPwP.d.mts} +5 -8
- package/dist/gcp.transport-D9SdLPwP.d.mts.map +1 -0
- package/dist/{gcp.transport-DBX5TPIy.mjs → gcp.transport-DVCmnA3b.mjs} +59 -16
- package/dist/gcp.transport-DVCmnA3b.mjs.map +1 -0
- package/dist/{gcp.transport-CHV8MGgz.js → gcp.transport-Dy2Lf8FI.js} +64 -22
- package/dist/gcp.transport-Dy2Lf8FI.js.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.mts +32 -0
- package/dist/http-shapes-BnBkJcid.d.mts.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.ts +32 -0
- package/dist/http-shapes-BnBkJcid.d.ts.map +1 -0
- package/dist/{index-3mw5gaCw.d.mts → index-BSTtFcQ6.d.mts} +142 -13
- package/dist/index-BSTtFcQ6.d.mts.map +1 -0
- package/dist/{index-DhIoploR.d.ts → index-CFDGkI8n.d.ts} +142 -13
- package/dist/index-CFDGkI8n.d.ts.map +1 -0
- package/dist/index.d.mts +114 -217
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +113 -216
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +182 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -256
- package/dist/index.mjs.map +1 -1
- package/dist/internal-log-Bg4V1cPg.mjs +170 -0
- package/dist/internal-log-Bg4V1cPg.mjs.map +1 -0
- package/dist/internal-log-By4Govmu.js +223 -0
- package/dist/internal-log-By4Govmu.js.map +1 -0
- package/dist/{logitron-logger-UVeN-mQm.d.ts → logitron-logger-D22Yb61K.d.mts} +121 -100
- package/dist/logitron-logger-D22Yb61K.d.mts.map +1 -0
- package/dist/{logitron-logger-BFDSO8Io.d.mts → logitron-logger-D_MYYrQt.d.ts} +121 -100
- package/dist/logitron-logger-D_MYYrQt.d.ts.map +1 -0
- package/dist/middleware.d.mts +13 -28
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +13 -28
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +20 -81
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +17 -79
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +37 -48
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +37 -48
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +124 -135
- package/dist/nest.js.map +1 -1
- package/dist/nest.mjs +69 -78
- package/dist/nest.mjs.map +1 -1
- package/dist/{transport.manager-BiuCAJd2.mjs → otel-Dt5riXuE.mjs} +275 -117
- package/dist/otel-Dt5riXuE.mjs.map +1 -0
- package/dist/{transport.manager-CXbKKdVE.js → otel-DyeH6DVR.js} +373 -178
- package/dist/otel-DyeH6DVR.js.map +1 -0
- package/dist/own-property-BWkibepN.js +40 -0
- package/dist/own-property-BWkibepN.js.map +1 -0
- package/dist/own-property-CjFw9qwZ.mjs +29 -0
- package/dist/own-property-CjFw9qwZ.mjs.map +1 -0
- package/dist/{trace.utils-CvXgaiQT.mjs → request-trace-BgNykH9M.mjs} +40 -9
- package/dist/request-trace-BgNykH9M.mjs.map +1 -0
- package/dist/{trace.utils-DpBOLDtq.js → request-trace-ByujsUZk.js} +117 -77
- package/dist/request-trace-ByujsUZk.js.map +1 -0
- package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
- package/dist/{safe-stringify-DJ66tW5I.mjs → safe-stringify-B5p5ktFe.mjs} +39 -15
- package/dist/safe-stringify-B5p5ktFe.mjs.map +1 -0
- package/dist/{safe-stringify-DWo3aZp_.js → safe-stringify-J3sh-7YM.js} +59 -36
- package/dist/safe-stringify-J3sh-7YM.js.map +1 -0
- package/dist/{search-C4V0OMEn.js → search-CRjhHxe9.js} +319 -92
- package/dist/search-CRjhHxe9.js.map +1 -0
- package/dist/{search-CNh9uVwR.d.ts → search-DA3ft3X5.d.mts} +5 -22
- package/dist/search-DA3ft3X5.d.mts.map +1 -0
- package/dist/{search-BFbu_oVn.mjs → search-DAXKE-P9.mjs} +289 -62
- package/dist/search-DAXKE-P9.mjs.map +1 -0
- package/dist/{search-DXANsQ2n.d.mts → search-DEl3Pe47.d.ts} +5 -22
- package/dist/search-DEl3Pe47.d.ts.map +1 -0
- package/dist/search.d.mts +2 -4
- package/dist/search.d.ts +2 -4
- package/dist/search.js +3 -4
- package/dist/search.mjs +1 -4
- package/dist/secret-config-CmK2wVkr.js +272 -0
- package/dist/secret-config-CmK2wVkr.js.map +1 -0
- package/dist/secret-config-Dhb6pqTU.mjs +210 -0
- package/dist/secret-config-Dhb6pqTU.mjs.map +1 -0
- package/dist/{slack.transport-CXjQYOes.d.ts → slack.transport-BDyENuR0.d.mts} +56 -9
- package/dist/slack.transport-BDyENuR0.d.mts.map +1 -0
- package/dist/{slack.transport-Bzw7sucI.mjs → slack.transport-BTEwsREY.mjs} +263 -31
- package/dist/slack.transport-BTEwsREY.mjs.map +1 -0
- package/dist/{slack.transport-BZzoXDPn.d.mts → slack.transport-C6E0l4kw.d.ts} +56 -9
- package/dist/slack.transport-C6E0l4kw.d.ts.map +1 -0
- package/dist/{slack.transport-BfJRouB2.js → slack.transport-UbYvOdKx.js} +286 -42
- package/dist/slack.transport-UbYvOdKx.js.map +1 -0
- package/dist/testing.d.mts +13 -11
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.d.ts +13 -11
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +41 -7
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +40 -6
- package/dist/testing.mjs.map +1 -1
- package/dist/{transport.types-CGoHpWQR.d.ts → transport.types-CzJq4IrF.d.mts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.mts.map +1 -0
- package/dist/{transport.types-BMnurPcc.d.mts → transport.types-CzJq4IrF.d.ts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.ts.map +1 -0
- package/dist/transports.d.mts +39 -41
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +39 -41
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +19 -22
- package/dist/transports.mjs +7 -13
- package/dist/worker-entry.js +438 -107
- package/dist/worker.d.mts +1 -2
- package/dist/worker.d.ts +1 -2
- package/dist/worker.js +3 -4
- package/dist/worker.mjs +1 -4
- package/dist/{worker.transport-JvGPog3C.d.mts → worker.transport-B9mCQSM1.d.ts} +7 -6
- package/dist/worker.transport-B9mCQSM1.d.ts.map +1 -0
- package/dist/{worker.transport-CdzSZJmw.d.ts → worker.transport-Bl8lFRck.d.mts} +7 -6
- package/dist/worker.transport-Bl8lFRck.d.mts.map +1 -0
- package/dist/{worker.transport-lPxO2MVL.mjs → worker.transport-BmmOKb1-.mjs} +43 -10
- package/dist/worker.transport-BmmOKb1-.mjs.map +1 -0
- package/dist/{worker.transport-BdPxu3PN.js → worker.transport-DxxbqQCG.js} +48 -15
- package/dist/worker.transport-DxxbqQCG.js.map +1 -0
- package/package.json +51 -75
- package/dist/async-context-BzJrbfQs.mjs +0 -72
- package/dist/async-context-BzJrbfQs.mjs.map +0 -1
- package/dist/async-context-DyQQYq3I.js +0 -92
- package/dist/async-context-DyQQYq3I.js.map +0 -1
- package/dist/azure-monitor.transport-CHnjVRF-.mjs.map +0 -1
- package/dist/azure-monitor.transport-Cn_3Usvu.d.ts.map +0 -1
- package/dist/azure-monitor.transport-CrvfHd9C.js.map +0 -1
- package/dist/azure-monitor.transport-D7Da4RAb.d.mts.map +0 -1
- package/dist/batch-buffer-BY-mRWIK.js.map +0 -1
- package/dist/batch-buffer-PGvSgbmd.mjs.map +0 -1
- package/dist/builder-0gEzRopq.mjs.map +0 -1
- package/dist/builder-D44QktIo.js.map +0 -1
- package/dist/chunk-DLSkYcPk.mjs +0 -7
- package/dist/chunk-nOFOJqeH.js +0 -30
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +0 -1
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +0 -1
- package/dist/cloudwatch.transport-DsEq633o.d.ts.map +0 -1
- package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +0 -1
- package/dist/entry-fields-BJkuPnIg.mjs.map +0 -1
- package/dist/entry-fields-BvOLFlJ4.js.map +0 -1
- package/dist/gcp.transport-B7oc97sG.d.ts.map +0 -1
- package/dist/gcp.transport-CHV8MGgz.js.map +0 -1
- package/dist/gcp.transport-DBX5TPIy.mjs.map +0 -1
- package/dist/gcp.transport-GrJurKo8.d.mts.map +0 -1
- package/dist/index-3mw5gaCw.d.mts.map +0 -1
- package/dist/index-DhIoploR.d.ts.map +0 -1
- package/dist/internal-log-BUJYMZbE.js +0 -70
- package/dist/internal-log-BUJYMZbE.js.map +0 -1
- package/dist/internal-log-Cm8SOWSV.mjs +0 -52
- package/dist/internal-log-Cm8SOWSV.mjs.map +0 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +0 -1
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +0 -1
- package/dist/safe-stringify-DJ66tW5I.mjs.map +0 -1
- package/dist/safe-stringify-DWo3aZp_.js.map +0 -1
- package/dist/search-BFbu_oVn.mjs.map +0 -1
- package/dist/search-C4V0OMEn.js.map +0 -1
- package/dist/search-CNh9uVwR.d.ts.map +0 -1
- package/dist/search-DXANsQ2n.d.mts.map +0 -1
- package/dist/slack.transport-BZzoXDPn.d.mts.map +0 -1
- package/dist/slack.transport-BfJRouB2.js.map +0 -1
- package/dist/slack.transport-Bzw7sucI.mjs.map +0 -1
- package/dist/slack.transport-CXjQYOes.d.ts.map +0 -1
- package/dist/trace.utils-CvXgaiQT.mjs.map +0 -1
- package/dist/trace.utils-DpBOLDtq.js.map +0 -1
- package/dist/transport.manager-BiuCAJd2.mjs.map +0 -1
- package/dist/transport.manager-CXbKKdVE.js.map +0 -1
- package/dist/transport.types-BMnurPcc.d.mts.map +0 -1
- package/dist/transport.types-CGoHpWQR.d.ts.map +0 -1
- package/dist/worker.transport-BdPxu3PN.js.map +0 -1
- package/dist/worker.transport-CdzSZJmw.d.ts.map +0 -1
- package/dist/worker.transport-JvGPog3C.d.mts.map +0 -1
- package/dist/worker.transport-lPxO2MVL.mjs.map +0 -1
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const require_coerce_utils = require(
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
node_os = require_chunk.__toESM(node_os);
|
|
1
|
+
const require_secret_config = require("./secret-config-CmK2wVkr.js");
|
|
2
|
+
const require_own_property = require("./own-property-BWkibepN.js");
|
|
3
|
+
const require_request_trace = require("./request-trace-ByujsUZk.js");
|
|
4
|
+
const require_async_context = require("./async-context-DUFMDYAr.js");
|
|
5
|
+
const require_internal_log = require("./internal-log-By4Govmu.js");
|
|
6
|
+
const require_coerce_utils = require("./coerce.utils-C1C5sIX0.js");
|
|
7
|
+
const require_safe_stringify = require("./safe-stringify-J3sh-7YM.js");
|
|
8
|
+
const require_otel = require("./otel-DyeH6DVR.js");
|
|
10
9
|
let fast_json_stringify = require("fast-json-stringify");
|
|
11
|
-
fast_json_stringify =
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
fast_json_stringify = require_secret_config.__toESM(fast_json_stringify);
|
|
11
|
+
let node_os = require("node:os");
|
|
12
|
+
// src/types/index.ts
|
|
14
13
|
const LogLevel = {
|
|
15
14
|
ERROR: "error",
|
|
16
15
|
WARN: "warn",
|
|
@@ -35,9 +34,7 @@ const DEFAULT_LOG_COLORS = {
|
|
|
35
34
|
trace: "magenta",
|
|
36
35
|
verbose: "cyan"
|
|
37
36
|
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/core/default-config.ts
|
|
37
|
+
// src/core/default-config.ts
|
|
41
38
|
/**
|
|
42
39
|
* Default configuration for Logixia logger
|
|
43
40
|
*/
|
|
@@ -81,9 +78,7 @@ const DEFAULT_CONFIG = {
|
|
|
81
78
|
},
|
|
82
79
|
outputs: ["console"]
|
|
83
80
|
};
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/plugin.ts
|
|
81
|
+
// src/plugin.ts
|
|
87
82
|
/**
|
|
88
83
|
* Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
|
|
89
84
|
* events to them. One registry is created per logger instance; a global
|
|
@@ -188,9 +183,7 @@ const globalPluginRegistry = new PluginRegistry();
|
|
|
188
183
|
function usePlugin(plugin) {
|
|
189
184
|
globalPluginRegistry.register(plugin);
|
|
190
185
|
}
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region src/utils/error.utils.ts
|
|
186
|
+
// src/utils/error.utils.ts
|
|
194
187
|
const EXTRA_FIELDS = [
|
|
195
188
|
"code",
|
|
196
189
|
"statusCode",
|
|
@@ -232,13 +225,15 @@ function _serializeError(error, includeStack, maxDepth, excludeFields, depth, se
|
|
|
232
225
|
};
|
|
233
226
|
if (includeStack && error.stack) serialized.stack = error.stack;
|
|
234
227
|
const errorWithCause = error;
|
|
235
|
-
if (errorWithCause.cause !== void 0)
|
|
236
|
-
|
|
228
|
+
if (errorWithCause.cause !== void 0) {
|
|
229
|
+
if (errorWithCause.cause instanceof Error) serialized.cause = _serializeError(errorWithCause.cause, includeStack, maxDepth, excludeFields, depth + 1, seen);
|
|
230
|
+
else serialized.cause = serializeValue(errorWithCause.cause, maxDepth - depth - 1, seen);
|
|
231
|
+
}
|
|
237
232
|
const aggregateError = error;
|
|
238
233
|
if (Array.isArray(aggregateError.errors)) serialized.errors = aggregateError.errors.map((e) => e instanceof Error ? _serializeError(e, includeStack, maxDepth, excludeFields, depth + 1, seen) : serializeValue(e, maxDepth - depth - 1, seen));
|
|
239
234
|
const errorRecord = error;
|
|
240
235
|
for (const field of EXTRA_FIELDS) if (!excludeFields.includes(field) && field in error && errorRecord[field] !== void 0) serialized[field] = errorRecord[field];
|
|
241
|
-
const skip = new Set([
|
|
236
|
+
const skip = /* @__PURE__ */ new Set([
|
|
242
237
|
"name",
|
|
243
238
|
"message",
|
|
244
239
|
"stack",
|
|
@@ -249,11 +244,10 @@ function _serializeError(error, includeStack, maxDepth, excludeFields, depth, se
|
|
|
249
244
|
]);
|
|
250
245
|
for (const key of Object.getOwnPropertyNames(error)) {
|
|
251
246
|
if (skip.has(key)) continue;
|
|
252
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
253
247
|
try {
|
|
254
|
-
serialized
|
|
248
|
+
require_own_property.assignOwn(serialized, key, serializeValue(errorRecord[key], maxDepth - depth - 1, seen));
|
|
255
249
|
} catch {
|
|
256
|
-
serialized
|
|
250
|
+
require_own_property.assignOwn(serialized, key, "[Unserializable]");
|
|
257
251
|
}
|
|
258
252
|
}
|
|
259
253
|
return serialized;
|
|
@@ -288,13 +282,10 @@ function serializeValue(value, remainingDepth, seen) {
|
|
|
288
282
|
if (seen.has(value)) return "[Circular]";
|
|
289
283
|
seen.add(value);
|
|
290
284
|
const out = {};
|
|
291
|
-
for (const [k, v] of Object.entries(value)) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
} catch {
|
|
296
|
-
out[k] = "[Unserializable]";
|
|
297
|
-
}
|
|
285
|
+
for (const [k, v] of Object.entries(value)) try {
|
|
286
|
+
require_own_property.assignOwn(out, k, serializeValue(v, remainingDepth - 1, seen));
|
|
287
|
+
} catch {
|
|
288
|
+
require_own_property.assignOwn(out, k, "[Unserializable]");
|
|
298
289
|
}
|
|
299
290
|
return out;
|
|
300
291
|
}
|
|
@@ -320,116 +311,7 @@ function normalizeError(error) {
|
|
|
320
311
|
}
|
|
321
312
|
return new Error(String(error));
|
|
322
313
|
}
|
|
323
|
-
|
|
324
|
-
//#endregion
|
|
325
|
-
//#region src/utils/otel.ts
|
|
326
|
-
let _otelApi;
|
|
327
|
-
function tryLoadOtelApi() {
|
|
328
|
-
if (_otelApi !== void 0) return _otelApi;
|
|
329
|
-
try {
|
|
330
|
-
_otelApi = require("@opentelemetry/api");
|
|
331
|
-
return _otelApi;
|
|
332
|
-
} catch {
|
|
333
|
-
_otelApi = null;
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Read the currently active OTel span context (if any) and return its fields
|
|
339
|
-
* in a plain object suitable for spreading into a log entry.
|
|
340
|
-
*
|
|
341
|
-
* Returns `undefined` when:
|
|
342
|
-
* - `@opentelemetry/api` is not installed
|
|
343
|
-
* - No active span exists (root context)
|
|
344
|
-
* - The span context is invalid (all-zeros)
|
|
345
|
-
*/
|
|
346
|
-
function getActiveOtelContext(opts = {}) {
|
|
347
|
-
const api = tryLoadOtelApi();
|
|
348
|
-
if (!api) return void 0;
|
|
349
|
-
try {
|
|
350
|
-
const ctx = api.context.active();
|
|
351
|
-
const sc = api.trace.getSpanContext(ctx);
|
|
352
|
-
if (!sc || !api.trace.isSpanContextValid(sc)) return void 0;
|
|
353
|
-
const isSampled = (sc.traceFlags & api.trace.TraceFlags.SAMPLED) === api.trace.TraceFlags.SAMPLED;
|
|
354
|
-
if (opts.sampledOnly && !isSampled) return void 0;
|
|
355
|
-
return {
|
|
356
|
-
traceId: sc.traceId,
|
|
357
|
-
spanId: sc.spanId,
|
|
358
|
-
traceFlags: sc.traceFlags,
|
|
359
|
-
isSampled
|
|
360
|
-
};
|
|
361
|
-
} catch {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns a metadata object with OTel context fields ready to merge into a log call,
|
|
367
|
-
* using the configured field names.
|
|
368
|
-
*
|
|
369
|
-
* Returns `{}` when no active span exists (safe to spread unconditionally).
|
|
370
|
-
*
|
|
371
|
-
* @example
|
|
372
|
-
* ```ts
|
|
373
|
-
* await logger.info('Payment processed', {
|
|
374
|
-
* ...getOtelMetaFields(),
|
|
375
|
-
* orderId: 'ord_123',
|
|
376
|
-
* });
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
function getOtelMetaFields(opts = {}) {
|
|
380
|
-
const { traceIdField = "traceId", spanIdField = "spanId", traceFlagsField = "traceFlags" } = opts;
|
|
381
|
-
const ctx = getActiveOtelContext(opts);
|
|
382
|
-
if (!ctx) return {};
|
|
383
|
-
return {
|
|
384
|
-
[traceIdField]: ctx.traceId,
|
|
385
|
-
[spanIdField]: ctx.spanId,
|
|
386
|
-
[traceFlagsField]: ctx.traceFlags
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
let _bridgeOptions = null;
|
|
390
|
-
/**
|
|
391
|
-
* Initialise the global OTel bridge.
|
|
392
|
-
*
|
|
393
|
-
* Once called, logixia's internal log pipeline checks for an active OTel span
|
|
394
|
-
* on **every** log call and automatically merges the span context into the
|
|
395
|
-
* entry's metadata — no per-call wiring needed.
|
|
396
|
-
*
|
|
397
|
-
* Call once at app startup, **after** the OTel SDK has been initialised:
|
|
398
|
-
* ```ts
|
|
399
|
-
* import { initOtelBridge } from 'logixia';
|
|
400
|
-
* initOtelBridge();
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
403
|
-
function initOtelBridge(opts = {}) {
|
|
404
|
-
_bridgeOptions = opts;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* @internal
|
|
408
|
-
* True when initOtelBridge() has been called. Lets the logger hot path skip the
|
|
409
|
-
* `_getOtelPayloadIfEnabled()` call (and its `{}` allocation + Object.keys) on
|
|
410
|
-
* every log when the bridge is off — the overwhelmingly common case.
|
|
411
|
-
*/
|
|
412
|
-
function _isOtelBridgeEnabled() {
|
|
413
|
-
return _bridgeOptions !== null;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* @internal
|
|
417
|
-
* Used by the core logger to inject OTel context when the bridge is active.
|
|
418
|
-
* Returns `{}` when the bridge is not initialised or no active span exists.
|
|
419
|
-
*/
|
|
420
|
-
function _getOtelPayloadIfEnabled() {
|
|
421
|
-
if (!_bridgeOptions) return {};
|
|
422
|
-
return getOtelMetaFields(_bridgeOptions);
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Disable the OTel bridge (useful for tests).
|
|
426
|
-
*/
|
|
427
|
-
function disableOtelBridge() {
|
|
428
|
-
_bridgeOptions = null;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region src/utils/redact.utils.ts
|
|
314
|
+
// src/utils/redact.utils.ts
|
|
433
315
|
const DEFAULT_CENSOR = "[REDACTED]";
|
|
434
316
|
/** Maximum nesting depth walked; deeper values are replaced with a marker. */
|
|
435
317
|
const MAX_DEPTH = 32;
|
|
@@ -458,34 +340,7 @@ const PII_CONSERVATIVE_PATTERNS = [
|
|
|
458
340
|
/**
|
|
459
341
|
* Conservative field-name paths auto-redacted by name regardless of value.
|
|
460
342
|
*/
|
|
461
|
-
const PII_CONSERVATIVE_PATHS =
|
|
462
|
-
"**.password",
|
|
463
|
-
"**.passwd",
|
|
464
|
-
"**.secret",
|
|
465
|
-
"**.token",
|
|
466
|
-
"**.apiKey",
|
|
467
|
-
"**.api_key",
|
|
468
|
-
"**.accessToken",
|
|
469
|
-
"**.access_token",
|
|
470
|
-
"**.refreshToken",
|
|
471
|
-
"**.refresh_token",
|
|
472
|
-
"**.authorization",
|
|
473
|
-
"**.credentials",
|
|
474
|
-
"**.privateKey",
|
|
475
|
-
"**.private_key",
|
|
476
|
-
"**.clientSecret",
|
|
477
|
-
"**.client_secret",
|
|
478
|
-
"**.cookie",
|
|
479
|
-
"**.set-cookie",
|
|
480
|
-
"**.x-api-key",
|
|
481
|
-
"**.session",
|
|
482
|
-
"**.proxy-authorization",
|
|
483
|
-
"**.x-auth-token",
|
|
484
|
-
"**.x-access-token",
|
|
485
|
-
"**.aws_secret_access_key",
|
|
486
|
-
"**.awsSecretAccessKey",
|
|
487
|
-
"**.secretAccessKey"
|
|
488
|
-
];
|
|
343
|
+
const PII_CONSERVATIVE_PATHS = require_internal_log.SENSITIVE_KEY_NAMES.map((name) => `**.${name}`);
|
|
489
344
|
/**
|
|
490
345
|
* Aggressive patterns: also catch personal data that could identify a person.
|
|
491
346
|
* Applied when `autoDetect: 'aggressive'`.
|
|
@@ -657,10 +512,9 @@ function walkRecord(obj, state, fullPath, bare, depth) {
|
|
|
657
512
|
let result;
|
|
658
513
|
const entries = Object.entries(obj);
|
|
659
514
|
for (const [index, [key, value]] of entries.entries()) {
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
if (
|
|
663
|
-
if (result && !forbidden) result[key] = next;
|
|
515
|
+
const next = walkValue(value, state, joinPath(fullPath, key), joinPath(bare, key), depth);
|
|
516
|
+
if (next !== value && !result) result = Object.fromEntries(entries.slice(0, index));
|
|
517
|
+
if (result) require_own_property.assignOwn(result, key, next);
|
|
664
518
|
}
|
|
665
519
|
return result ?? obj;
|
|
666
520
|
}
|
|
@@ -697,7 +551,7 @@ function walkToJSON(obj, state, fullPath, bare, depth) {
|
|
|
697
551
|
function redactObject(obj, config, _currentPath = "") {
|
|
698
552
|
const result = walkRecord(obj, {
|
|
699
553
|
config,
|
|
700
|
-
ancestors: new Set([obj]),
|
|
554
|
+
ancestors: /* @__PURE__ */ new Set([obj]),
|
|
701
555
|
nodes: 0
|
|
702
556
|
}, _currentPath, _currentPath, 0);
|
|
703
557
|
return result === obj ? { ...obj } : result;
|
|
@@ -746,10 +600,8 @@ function isPlainObject(value) {
|
|
|
746
600
|
if (ArrayBuffer.isView(value)) return false;
|
|
747
601
|
return !OPAQUE_BUILTINS.some((ctor) => value instanceof ctor);
|
|
748
602
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
//#region src/utils/sampling.utils.ts
|
|
752
|
-
const ALWAYS_EMIT_LEVELS = new Set([
|
|
603
|
+
// src/utils/sampling.utils.ts
|
|
604
|
+
const ALWAYS_EMIT_LEVELS = /* @__PURE__ */ new Set([
|
|
753
605
|
"error",
|
|
754
606
|
"warn",
|
|
755
607
|
"fatal"
|
|
@@ -767,8 +619,8 @@ var Sampler = class {
|
|
|
767
619
|
constructor(config, onStats) {
|
|
768
620
|
this.traceDecisions = /* @__PURE__ */ new Map();
|
|
769
621
|
this.maxTrackedTraces = 1e5;
|
|
770
|
-
this.traceTtlMs =
|
|
771
|
-
this.traceMaxLifetimeMs =
|
|
622
|
+
this.traceTtlMs = 3e5;
|
|
623
|
+
this.traceMaxLifetimeMs = 36e5;
|
|
772
624
|
this._tokenBucket = 0;
|
|
773
625
|
this._lastRefillMs = Date.now();
|
|
774
626
|
this._adaptiveWindow = [];
|
|
@@ -947,9 +799,14 @@ var Sampler = class {
|
|
|
947
799
|
this._stats.dropped++;
|
|
948
800
|
}
|
|
949
801
|
};
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
802
|
+
// src/utils/shutdown.utils.ts
|
|
803
|
+
/**
|
|
804
|
+
* Graceful shutdown utilities for Logixia
|
|
805
|
+
*
|
|
806
|
+
* Ensures all in-flight logs are flushed to every transport before the process
|
|
807
|
+
* exits on SIGTERM / SIGINT — solving the "last N seconds of logs are lost on
|
|
808
|
+
* deployment" problem reported in Pino issue #2002 and LogDNA issue #15.
|
|
809
|
+
*/
|
|
953
810
|
const MAX_BEFORE_EXIT_FLUSHES = 5;
|
|
954
811
|
/** Module-level registry of all logger instances that have opted into graceful shutdown */
|
|
955
812
|
const registry = /* @__PURE__ */ new Set();
|
|
@@ -1069,9 +926,59 @@ function resetShutdownHandlers() {
|
|
|
1069
926
|
shutdownHandlerRegistered = false;
|
|
1070
927
|
shutdownInProgress = false;
|
|
1071
928
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
929
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
930
|
+
"logLevel",
|
|
931
|
+
"time",
|
|
932
|
+
"timeEnd",
|
|
933
|
+
"timeAsync",
|
|
934
|
+
"setLevel",
|
|
935
|
+
"getLevel",
|
|
936
|
+
"setNamespaceLevels",
|
|
937
|
+
"patchNamespaceLevels",
|
|
938
|
+
"getNamespaceLevels",
|
|
939
|
+
"setContext",
|
|
940
|
+
"getContext",
|
|
941
|
+
"enableField",
|
|
942
|
+
"disableField",
|
|
943
|
+
"isFieldEnabled",
|
|
944
|
+
"getFieldState",
|
|
945
|
+
"resetFieldState",
|
|
946
|
+
"enableTransportLevelPrompting",
|
|
947
|
+
"disableTransportLevelPrompting",
|
|
948
|
+
"setTransportLevels",
|
|
949
|
+
"getTransportLevels",
|
|
950
|
+
"clearTransportLevelPreferences",
|
|
951
|
+
"getAvailableTransports",
|
|
952
|
+
"child",
|
|
953
|
+
"flush",
|
|
954
|
+
"healthCheck",
|
|
955
|
+
"close",
|
|
956
|
+
"use",
|
|
957
|
+
"unuse"
|
|
958
|
+
]);
|
|
959
|
+
/**
|
|
960
|
+
* Warn when `levels` defines a level named like a logger method (e.g. `flush`, `child`).
|
|
961
|
+
* The method keeps its normal behaviour and no level shortcut is installed for that
|
|
962
|
+
* name; log at it with `logger.logLevel(name, ...)` or pick a different level name.
|
|
963
|
+
* Returns the clashing names.
|
|
964
|
+
*/
|
|
965
|
+
function warnOnReservedLevelNames(levels) {
|
|
966
|
+
if (!levels) return [];
|
|
967
|
+
const clashes = Object.keys(levels).filter((name) => RESERVED.has(name));
|
|
968
|
+
if (clashes.length > 0) require_internal_log.internalWarn(`levelOptions.levels uses reserved logger method name(s): ${clashes.join(", ")}. No level shortcut is created for them; use logger.logLevel(name, ...) or rename the level.`);
|
|
969
|
+
return clashes;
|
|
970
|
+
}
|
|
971
|
+
// src/core/logitron-logger.ts
|
|
972
|
+
/**
|
|
973
|
+
* Core Logixia Logger implementation
|
|
974
|
+
*
|
|
975
|
+
* v1.1 additions:
|
|
976
|
+
* - Feature 1: Graceful shutdown / flushOnExit (auto-registered via config)
|
|
977
|
+
* - Feature 2: Built-in log redaction (path-based + regex)
|
|
978
|
+
* - Feature 3: Per-namespace log levels + LOGIXIA_LEVEL* ENV overrides
|
|
979
|
+
* - Feature 4: Cause-chain error serialization (handled in error.utils)
|
|
980
|
+
* - Feature 5: Adaptive log level based on NODE_ENV / CI detection
|
|
981
|
+
*/
|
|
1075
982
|
const _fastStringifyEntry = (0, fast_json_stringify.default)({
|
|
1076
983
|
type: "object",
|
|
1077
984
|
properties: {
|
|
@@ -1101,7 +1008,7 @@ function nowIso() {
|
|
|
1101
1008
|
}
|
|
1102
1009
|
function namespacePatternToRegex(pattern) {
|
|
1103
1010
|
const escaped = pattern.split(".").map((s) => s === "*" ? "[^.]+" : s.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")).join("\\.");
|
|
1104
|
-
return
|
|
1011
|
+
return new RegExp(`^${escaped}$`);
|
|
1105
1012
|
}
|
|
1106
1013
|
/** Max compiled patterns to keep in memory. Oldest entry is evicted when full. */
|
|
1107
1014
|
const _NS_CACHE_MAX = 1e3;
|
|
@@ -1143,7 +1050,7 @@ function canonicalLevel(level, known) {
|
|
|
1143
1050
|
function resolveInitialLevel(config) {
|
|
1144
1051
|
var _config$levelOptions, _config$levelOptions2;
|
|
1145
1052
|
const envLevel = process.env["LOGIXIA_LEVEL"];
|
|
1146
|
-
const knownLevels = new Set([...Object.values(LogLevel), ...Object.keys(((_config$levelOptions = config.levelOptions) === null || _config$levelOptions === void 0 ? void 0 : _config$levelOptions.levels) ?? {})]);
|
|
1053
|
+
const knownLevels = /* @__PURE__ */ new Set([...Object.values(LogLevel), ...Object.keys(((_config$levelOptions = config.levelOptions) === null || _config$levelOptions === void 0 ? void 0 : _config$levelOptions.levels) ?? {})]);
|
|
1147
1054
|
if (envLevel && canonicalLevel(envLevel, knownLevels)) return envLevel;
|
|
1148
1055
|
if ((_config$levelOptions2 = config.levelOptions) === null || _config$levelOptions2 === void 0 ? void 0 : _config$levelOptions2.level) return config.levelOptions.level;
|
|
1149
1056
|
const nodeEnv = process.env["NODE_ENV"];
|
|
@@ -1153,12 +1060,25 @@ function resolveInitialLevel(config) {
|
|
|
1153
1060
|
if (process.env["CI"]) return LogLevel.INFO;
|
|
1154
1061
|
return LogLevel.INFO;
|
|
1155
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The logixia logger. Create instances with {@link createLogger} so that custom
|
|
1065
|
+
* levels from `levelOptions.levels` also become methods.
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* const logger = createLogger({ appName: 'api', environment: 'production' });
|
|
1070
|
+
* await logger.info('Server started', { port: 3000 });
|
|
1071
|
+
* const req = logger.child('RequestHandler', { requestId: 'r-1' });
|
|
1072
|
+
* await req.error(new Error('boom'));
|
|
1073
|
+
* await logger.close(); // flush buffered transports before exit
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1156
1076
|
var LogixiaLogger = class LogixiaLogger {
|
|
1157
1077
|
constructor(config, context, parent) {
|
|
1158
1078
|
this.timers = /* @__PURE__ */ new Map();
|
|
1159
1079
|
this.contextData = {};
|
|
1160
1080
|
this.fieldState = /* @__PURE__ */ new Map();
|
|
1161
|
-
this.fallbackTraceId =
|
|
1081
|
+
this.fallbackTraceId = require_request_trace.TraceContext.instance.generate();
|
|
1162
1082
|
this._levelValues = /* @__PURE__ */ new Map();
|
|
1163
1083
|
this._minLevelValue = 2;
|
|
1164
1084
|
this._warnedInvalidLevels = /* @__PURE__ */ new Set();
|
|
@@ -1168,9 +1088,15 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1168
1088
|
this._formattedLevels = /* @__PURE__ */ new Map();
|
|
1169
1089
|
this._formattedAppName = "";
|
|
1170
1090
|
this._hasRedact = false;
|
|
1091
|
+
this._nsSeenVersion = 0;
|
|
1171
1092
|
this._parent = parent;
|
|
1093
|
+
this._nsStore = parent ? parent._nsStore : {
|
|
1094
|
+
levels: { ...config.namespaceLevels },
|
|
1095
|
+
version: 0
|
|
1096
|
+
};
|
|
1097
|
+
this._nsSeenVersion = this._nsStore.version;
|
|
1172
1098
|
this._pluginRegistry = parent ? parent._pluginRegistry : new PluginRegistry();
|
|
1173
|
-
|
|
1099
|
+
const defaultConfig = {
|
|
1174
1100
|
appName: "App",
|
|
1175
1101
|
environment: "development",
|
|
1176
1102
|
traceId: true,
|
|
@@ -1198,7 +1124,10 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1198
1124
|
[LogLevel.TRACE]: "gray",
|
|
1199
1125
|
[LogLevel.VERBOSE]: "cyan"
|
|
1200
1126
|
}
|
|
1201
|
-
}
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
this.config = {
|
|
1130
|
+
...defaultConfig,
|
|
1202
1131
|
...config
|
|
1203
1132
|
};
|
|
1204
1133
|
const resolvedLevel = resolveInitialLevel(this.config);
|
|
@@ -1216,18 +1145,19 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1216
1145
|
timeTaken: "[time_taken_MS]"
|
|
1217
1146
|
};
|
|
1218
1147
|
this.context = context ?? "";
|
|
1148
|
+
require_secret_config.protectSecrets(this, ["config"]);
|
|
1219
1149
|
if (parent) {
|
|
1220
1150
|
this.transportManager = parent.transportManager;
|
|
1221
1151
|
this._sampler = parent._sampler;
|
|
1222
1152
|
} else if (this.config.transports) {
|
|
1223
|
-
var _this$config$levelOpt;
|
|
1153
|
+
var _this$config$levelOpt, _this$config$levelOpt2;
|
|
1224
1154
|
const transportsWithColors = { ...this.config.transports };
|
|
1225
1155
|
const userColors = (_this$config$levelOpt = this.config.levelOptions) === null || _this$config$levelOpt === void 0 ? void 0 : _this$config$levelOpt.colors;
|
|
1226
1156
|
if (userColors && transportsWithColors.console) transportsWithColors.console = {
|
|
1227
1157
|
...typeof transportsWithColors.console === "object" ? transportsWithColors.console : {},
|
|
1228
1158
|
levelColors: userColors
|
|
1229
1159
|
};
|
|
1230
|
-
this.transportManager = new
|
|
1160
|
+
this.transportManager = new require_otel.TransportManager(transportsWithColors, (_this$config$levelOpt2 = this.config.levelOptions) === null || _this$config$levelOpt2 === void 0 ? void 0 : _this$config$levelOpt2.levels);
|
|
1231
1161
|
}
|
|
1232
1162
|
if (!parent && this.config.sampling) this._sampler = new Sampler(this.config.sampling, (stats) => {
|
|
1233
1163
|
process.stdout.write(JSON.stringify({
|
|
@@ -1254,8 +1184,9 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1254
1184
|
});
|
|
1255
1185
|
}
|
|
1256
1186
|
createCustomLevelMethods() {
|
|
1257
|
-
var _this$config$
|
|
1258
|
-
|
|
1187
|
+
var _this$config$levelOpt3, _this$config$levelOpt4;
|
|
1188
|
+
warnOnReservedLevelNames((_this$config$levelOpt3 = this.config.levelOptions) === null || _this$config$levelOpt3 === void 0 ? void 0 : _this$config$levelOpt3.levels);
|
|
1189
|
+
if ((_this$config$levelOpt4 = this.config.levelOptions) === null || _this$config$levelOpt4 === void 0 ? void 0 : _this$config$levelOpt4.levels) {
|
|
1259
1190
|
for (const levelName of Object.keys(this.config.levelOptions.levels)) if (!this[levelName.toLowerCase()]) this[levelName.toLowerCase()] = async (message, data) => {
|
|
1260
1191
|
await this.logLevel(levelName.toLowerCase(), message, data);
|
|
1261
1192
|
};
|
|
@@ -1266,8 +1197,8 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1266
1197
|
* Keeps the actual log() call free of allocations in the common case.
|
|
1267
1198
|
*/
|
|
1268
1199
|
_buildPerfCaches() {
|
|
1269
|
-
var _this$config$
|
|
1270
|
-
const customLevelEntries = Object.entries(((_this$config$
|
|
1200
|
+
var _this$config$levelOpt5, _this$config$format, _this$config$redact$p, _this$config$redact$p2;
|
|
1201
|
+
const customLevelEntries = Object.entries(((_this$config$levelOpt5 = this.config.levelOptions) === null || _this$config$levelOpt5 === void 0 ? void 0 : _this$config$levelOpt5.levels) ?? {});
|
|
1271
1202
|
this._levelValues = new Map([
|
|
1272
1203
|
[LogLevel.ERROR, 0],
|
|
1273
1204
|
[LogLevel.WARN, 1],
|
|
@@ -1281,7 +1212,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1281
1212
|
this.config.levelOptions.level = this._validLevel(this.config.levelOptions.level, "levelOptions.level") ?? LogLevel.INFO;
|
|
1282
1213
|
const effectiveLevel = this.resolveEffectiveLevel();
|
|
1283
1214
|
this._minLevelValue = this._levelValues.get(effectiveLevel) ?? 2;
|
|
1284
|
-
this._colorMap = new Map([
|
|
1215
|
+
this._colorMap = /* @__PURE__ */ new Map([
|
|
1285
1216
|
["black", "\x1B[30m"],
|
|
1286
1217
|
["red", "\x1B[31m"],
|
|
1287
1218
|
["green", "\x1B[32m"],
|
|
@@ -1324,7 +1255,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1324
1255
|
"green",
|
|
1325
1256
|
"blue"
|
|
1326
1257
|
];
|
|
1327
|
-
const _BUILTIN_LEVELS = new Set([
|
|
1258
|
+
const _BUILTIN_LEVELS = /* @__PURE__ */ new Set([
|
|
1328
1259
|
"error",
|
|
1329
1260
|
"warn",
|
|
1330
1261
|
"info",
|
|
@@ -1336,12 +1267,14 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1336
1267
|
for (const [lvl] of this._levelValues) {
|
|
1337
1268
|
const upper = lvl.toUpperCase();
|
|
1338
1269
|
if (colorize && this._fieldCache.get("level") !== false) {
|
|
1339
|
-
var _this$config$
|
|
1340
|
-
let colorName = (_this$config$
|
|
1341
|
-
if (!colorName)
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1270
|
+
var _this$config$levelOpt6;
|
|
1271
|
+
let colorName = (_this$config$levelOpt6 = this.config.levelOptions) === null || _this$config$levelOpt6 === void 0 || (_this$config$levelOpt6 = _this$config$levelOpt6.colors) === null || _this$config$levelOpt6 === void 0 ? void 0 : _this$config$levelOpt6[lvl];
|
|
1272
|
+
if (!colorName) {
|
|
1273
|
+
if (_BUILTIN_LEVELS.has(lvl)) colorName = "white";
|
|
1274
|
+
else {
|
|
1275
|
+
colorName = _AUTO_PALETTE[_paletteIdx % _AUTO_PALETTE.length];
|
|
1276
|
+
_paletteIdx++;
|
|
1277
|
+
}
|
|
1345
1278
|
}
|
|
1346
1279
|
const code = this._colorMap.get(colorName.toLowerCase()) ?? this._colorMap.get("white");
|
|
1347
1280
|
const reset = this._colorMap.get("reset");
|
|
@@ -1353,6 +1286,11 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1353
1286
|
else this._formattedAppName = colorize ? `${this._colorMap.get("gray")}${appNameRaw}${this._colorMap.get("reset")} ` : `${appNameRaw} `;
|
|
1354
1287
|
this._hasRedact = !!(this.config.redact && ((((_this$config$redact$p = this.config.redact.paths) === null || _this$config$redact$p === void 0 ? void 0 : _this$config$redact$p.length) ?? 0) > 0 || (((_this$config$redact$p2 = this.config.redact.patterns) === null || _this$config$redact$p2 === void 0 ? void 0 : _this$config$redact$p2.length) ?? 0) > 0 || !!this.config.redact.autoDetect));
|
|
1355
1288
|
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Log at `error` level. An `Error` is logged with its message and serialized
|
|
1291
|
+
* (name, message, stack) under `data.error`; a string is logged as-is.
|
|
1292
|
+
* `data` is merged into the entry payload.
|
|
1293
|
+
*/
|
|
1356
1294
|
async error(messageOrError, data) {
|
|
1357
1295
|
if (isError(messageOrError)) await this.log("error", messageOrError.message, {
|
|
1358
1296
|
...data,
|
|
@@ -1360,30 +1298,53 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1360
1298
|
});
|
|
1361
1299
|
else await this.log("error", messageOrError, data);
|
|
1362
1300
|
}
|
|
1301
|
+
/** Log `message` at `warn` level; `data` is merged into the entry payload. */
|
|
1363
1302
|
async warn(message, data) {
|
|
1364
1303
|
await this.log("warn", message, data);
|
|
1365
1304
|
}
|
|
1305
|
+
/** Log `message` at `info` level; `data` is merged into the entry payload. */
|
|
1366
1306
|
async info(message, data) {
|
|
1367
1307
|
await this.log("info", message, data);
|
|
1368
1308
|
}
|
|
1309
|
+
/** Log `message` at `debug` level; `data` is merged into the entry payload. */
|
|
1369
1310
|
async debug(message, data) {
|
|
1370
1311
|
await this.log("debug", message, data);
|
|
1371
1312
|
}
|
|
1313
|
+
/** Log `message` at `trace` level; `data` is merged into the entry payload. */
|
|
1372
1314
|
async trace(message, data) {
|
|
1373
1315
|
await this.log("trace", message, data);
|
|
1374
1316
|
}
|
|
1317
|
+
/** Log `message` at `verbose` level; `data` is merged into the entry payload. */
|
|
1375
1318
|
async verbose(message, data) {
|
|
1376
1319
|
await this.log("verbose", message, data);
|
|
1377
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Log at an arbitrary level name, including custom levels. Levels below the
|
|
1323
|
+
* active threshold are dropped, as are level names that are not registered
|
|
1324
|
+
* in `levelOptions.levels` (and are not built-in).
|
|
1325
|
+
*/
|
|
1378
1326
|
async logLevel(level, message, data) {
|
|
1379
1327
|
await this.log(level, message, data);
|
|
1380
1328
|
}
|
|
1329
|
+
/** Start a named timer; finish it with {@link timeEnd}. Reusing a label restarts it. */
|
|
1381
1330
|
time(label) {
|
|
1382
1331
|
this.timers.set(label, {
|
|
1383
1332
|
label,
|
|
1384
1333
|
startTime: Date.now()
|
|
1385
1334
|
});
|
|
1386
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Stop the timer `label`, log its duration at `info` level, and return the
|
|
1338
|
+
* elapsed milliseconds. Logs a `warn` and returns `undefined` if the timer
|
|
1339
|
+
* does not exist.
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```ts
|
|
1343
|
+
* logger.time('db');
|
|
1344
|
+
* await query();
|
|
1345
|
+
* const ms = await logger.timeEnd('db');
|
|
1346
|
+
* ```
|
|
1347
|
+
*/
|
|
1387
1348
|
async timeEnd(label) {
|
|
1388
1349
|
const timer = this.timers.get(label);
|
|
1389
1350
|
if (!timer) {
|
|
@@ -1413,6 +1374,17 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1413
1374
|
throw error;
|
|
1414
1375
|
}
|
|
1415
1376
|
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Change the minimum log level at runtime. The override outranks
|
|
1379
|
+
* `LOGIXIA_LEVEL`, `LOGIXIA_LEVEL_<NS>` and `namespaceLevels`, and survives
|
|
1380
|
+
* later changes to fields or namespace levels. Unknown level names are
|
|
1381
|
+
* ignored with a warning and the current level is kept.
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```ts
|
|
1385
|
+
* logger.setLevel('debug');
|
|
1386
|
+
* ```
|
|
1387
|
+
*/
|
|
1416
1388
|
setLevel(level) {
|
|
1417
1389
|
const canonical = canonicalLevel(level, this._levelValues);
|
|
1418
1390
|
if (canonical === void 0) {
|
|
@@ -1421,12 +1393,17 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1421
1393
|
}
|
|
1422
1394
|
this.config.levelOptions = this.config.levelOptions ?? {};
|
|
1423
1395
|
this.config.levelOptions.level = canonical;
|
|
1424
|
-
this.
|
|
1396
|
+
this._runtimeLevel = canonical;
|
|
1425
1397
|
this._buildPerfCaches();
|
|
1426
1398
|
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Return the configured minimum log level, not the per-namespace effective
|
|
1401
|
+
* one. Without `setLevel()` it is `LOGIXIA_LEVEL`, else `levelOptions.level`,
|
|
1402
|
+
* else a `NODE_ENV` default (`debug` in development, `warn` in test), else `info`.
|
|
1403
|
+
*/
|
|
1427
1404
|
getLevel() {
|
|
1428
|
-
var _this$config$
|
|
1429
|
-
return ((_this$config$
|
|
1405
|
+
var _this$config$levelOpt7;
|
|
1406
|
+
return ((_this$config$levelOpt7 = this.config.levelOptions) === null || _this$config$levelOpt7 === void 0 ? void 0 : _this$config$levelOpt7.level) ?? LogLevel.INFO;
|
|
1430
1407
|
}
|
|
1431
1408
|
_validLevelList() {
|
|
1432
1409
|
return [...this._levelValues.keys()].join(", ");
|
|
@@ -1455,6 +1432,10 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1455
1432
|
* (flip a module's verbosity live to chase a bug without raising global
|
|
1456
1433
|
* volume). The new map fully replaces the previous one.
|
|
1457
1434
|
*
|
|
1435
|
+
* The map is shared by a logger and all its `child()` loggers: calling this on
|
|
1436
|
+
* a child changes the whole family, and existing children pick the change up on
|
|
1437
|
+
* their next log call.
|
|
1438
|
+
*
|
|
1458
1439
|
* @example
|
|
1459
1440
|
* ```ts
|
|
1460
1441
|
* // Turn on debug for the DB layer only, live:
|
|
@@ -1462,45 +1443,57 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1462
1443
|
* ```
|
|
1463
1444
|
*/
|
|
1464
1445
|
setNamespaceLevels(levels) {
|
|
1465
|
-
this.
|
|
1466
|
-
this.
|
|
1446
|
+
this._nsStore.levels = { ...levels };
|
|
1447
|
+
this._nsStore.version++;
|
|
1448
|
+
this._syncNamespaceLevels();
|
|
1467
1449
|
}
|
|
1468
1450
|
/** Merge entries into the existing per-namespace level map at runtime. */
|
|
1469
1451
|
patchNamespaceLevels(levels) {
|
|
1470
|
-
this.
|
|
1471
|
-
...this.
|
|
1452
|
+
this._nsStore.levels = {
|
|
1453
|
+
...this._nsStore.levels,
|
|
1472
1454
|
...levels
|
|
1473
1455
|
};
|
|
1474
|
-
this.
|
|
1456
|
+
this._nsStore.version++;
|
|
1457
|
+
this._syncNamespaceLevels();
|
|
1475
1458
|
}
|
|
1476
1459
|
/** Return a copy of the current per-namespace level map. */
|
|
1477
1460
|
getNamespaceLevels() {
|
|
1478
|
-
return { ...this.
|
|
1461
|
+
return { ...this._nsStore.levels };
|
|
1462
|
+
}
|
|
1463
|
+
_syncNamespaceLevels() {
|
|
1464
|
+
this._nsSeenVersion = this._nsStore.version;
|
|
1465
|
+
this._minLevelValue = this._levelValues.get(this.resolveEffectiveLevel()) ?? 2;
|
|
1479
1466
|
}
|
|
1467
|
+
/** Set the context label (e.g. a class or module name) attached to every subsequent entry. */
|
|
1480
1468
|
setContext(context) {
|
|
1481
1469
|
this.context = typeof context === "string" ? context : require_coerce_utils.safeToString(context);
|
|
1482
1470
|
}
|
|
1471
|
+
/** Return the current context label, or `undefined` if none is set. */
|
|
1483
1472
|
getContext() {
|
|
1484
1473
|
return this.context;
|
|
1485
1474
|
}
|
|
1475
|
+
/** Show `fieldName` in log output, overriding the config for this logger instance. */
|
|
1486
1476
|
enableField(fieldName) {
|
|
1487
1477
|
this.fieldState.set(fieldName, true);
|
|
1488
1478
|
this._fieldCache.set(fieldName, true);
|
|
1489
1479
|
if (fieldName === "level" || fieldName === "appName") this._buildPerfCaches();
|
|
1490
1480
|
require_internal_log.internalLog(`Field '${fieldName}' enabled`);
|
|
1491
1481
|
}
|
|
1482
|
+
/** Hide `fieldName` from log output, overriding the config for this logger instance. */
|
|
1492
1483
|
disableField(fieldName) {
|
|
1493
1484
|
this.fieldState.set(fieldName, false);
|
|
1494
1485
|
this._fieldCache.set(fieldName, false);
|
|
1495
1486
|
if (fieldName === "level" || fieldName === "appName") this._buildPerfCaches();
|
|
1496
1487
|
require_internal_log.internalLog(`Field '${fieldName}' disabled`);
|
|
1497
1488
|
}
|
|
1489
|
+
/** Whether `fieldName` is currently shown: runtime override first, then config, default `true`. */
|
|
1498
1490
|
isFieldEnabled(fieldName) {
|
|
1499
1491
|
var _this$config$fields2;
|
|
1500
1492
|
if (this.fieldState.has(fieldName)) return this.fieldState.get(fieldName);
|
|
1501
1493
|
if (((_this$config$fields2 = this.config.fields) === null || _this$config$fields2 === void 0 ? void 0 : _this$config$fields2[fieldName]) !== void 0) return this.config.fields[fieldName] !== false;
|
|
1502
1494
|
return true;
|
|
1503
1495
|
}
|
|
1496
|
+
/** Return the visibility (`true` = shown) of every standard log field. */
|
|
1504
1497
|
getFieldState() {
|
|
1505
1498
|
return Object.fromEntries([
|
|
1506
1499
|
"timestamp",
|
|
@@ -1517,6 +1510,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1517
1510
|
"environment"
|
|
1518
1511
|
].map((f) => [f, this.isFieldEnabled(f)]));
|
|
1519
1512
|
}
|
|
1513
|
+
/** Drop all runtime enable/disable overrides so field visibility follows the config again. */
|
|
1520
1514
|
resetFieldState() {
|
|
1521
1515
|
this.fieldState.clear();
|
|
1522
1516
|
require_internal_log.internalLog("Field state reset to configuration defaults");
|
|
@@ -1531,10 +1525,12 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1531
1525
|
if (this.transportManager) this.transportManager.disableLevelPrompting();
|
|
1532
1526
|
else require_internal_log.internalWarn("Transport manager not initialized");
|
|
1533
1527
|
}
|
|
1528
|
+
/** Restrict `transportId` to only the given `levels`. Warns if no transports are configured. */
|
|
1534
1529
|
setTransportLevels(transportId, levels) {
|
|
1535
1530
|
if (this.transportManager) this.transportManager.setTransportLevels(transportId, levels);
|
|
1536
1531
|
else require_internal_log.internalWarn("Transport manager not initialized");
|
|
1537
1532
|
}
|
|
1533
|
+
/** Return the levels `transportId` is restricted to, or `undefined` if it has none. */
|
|
1538
1534
|
getTransportLevels(transportId) {
|
|
1539
1535
|
if (this.transportManager) return this.transportManager.getTransportLevels(transportId);
|
|
1540
1536
|
require_internal_log.internalWarn("Transport manager not initialized");
|
|
@@ -1543,10 +1539,23 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1543
1539
|
if (this.transportManager) this.transportManager.clearTransportLevelPreferences();
|
|
1544
1540
|
else require_internal_log.internalWarn("Transport manager not initialized");
|
|
1545
1541
|
}
|
|
1542
|
+
/** Return the identifiers of the configured transports (empty if none). */
|
|
1546
1543
|
getAvailableTransports() {
|
|
1547
1544
|
var _this$transportManage;
|
|
1548
1545
|
return ((_this$transportManage = this.transportManager) === null || _this$transportManage === void 0 ? void 0 : _this$transportManage.getTransports()) ?? [];
|
|
1549
1546
|
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Create a child logger with its own `context` that shares this logger's
|
|
1549
|
+
* configuration and transports. `data` is merged into the bound fields
|
|
1550
|
+
* inherited from this logger and added to every entry the child writes.
|
|
1551
|
+
* Closing a child does not close the shared transports.
|
|
1552
|
+
*
|
|
1553
|
+
* @example
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* const req = logger.child('Checkout', { requestId: 'r-42' });
|
|
1556
|
+
* await req.info('started'); // entry includes requestId
|
|
1557
|
+
* ```
|
|
1558
|
+
*/
|
|
1550
1559
|
child(context, data) {
|
|
1551
1560
|
const childLogger = new LogixiaLogger(this.config, context, this);
|
|
1552
1561
|
const mergedContextData = {
|
|
@@ -1582,9 +1591,11 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1582
1591
|
this._pluginRegistry.unregister(pluginName);
|
|
1583
1592
|
return this;
|
|
1584
1593
|
}
|
|
1594
|
+
/** Flush buffered entries in all transports without closing them. */
|
|
1585
1595
|
async flush() {
|
|
1586
1596
|
if (this.transportManager) await this.transportManager.flush();
|
|
1587
1597
|
}
|
|
1598
|
+
/** Report whether the transports are healthy; `healthy: false` if no transport manager exists. */
|
|
1588
1599
|
async healthCheck() {
|
|
1589
1600
|
if (!this.transportManager) return {
|
|
1590
1601
|
healthy: false,
|
|
@@ -1592,6 +1603,20 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1592
1603
|
};
|
|
1593
1604
|
return this.transportManager.healthCheck();
|
|
1594
1605
|
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Warn about timers that were never ended, then flush and close all transports,
|
|
1608
|
+
* stop the sampler and run plugin shutdown hooks. On a child logger only the
|
|
1609
|
+
* timer warnings run; the shared transports stay open.
|
|
1610
|
+
*
|
|
1611
|
+
* To flush on SIGTERM/SIGINT, set the `gracefulShutdown` config option rather
|
|
1612
|
+
* than writing your own signal handler; do not combine it with a manual
|
|
1613
|
+
* handler that calls `process.exit`, which can cut the flush short.
|
|
1614
|
+
*
|
|
1615
|
+
* @example
|
|
1616
|
+
* ```ts
|
|
1617
|
+
* await logger.close(); // e.g. at the end of a script or a test
|
|
1618
|
+
* ```
|
|
1619
|
+
*/
|
|
1595
1620
|
async close() {
|
|
1596
1621
|
var _this$_sampler;
|
|
1597
1622
|
for (const [label, timer] of this.timers) await this.warn(`Timer '${label}' was not ended properly`, {
|
|
@@ -1608,21 +1633,27 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1608
1633
|
async log(level, message, data) {
|
|
1609
1634
|
if (this.config.silent) return;
|
|
1610
1635
|
if (!this.shouldLog(level)) return;
|
|
1611
|
-
if (this._sampler) {
|
|
1612
|
-
const traceId$1 = this.config.traceId ? require_trace_utils.TraceContext.instance.getCurrentTraceId() : void 0;
|
|
1613
|
-
if (!this._sampler.shouldEmit(level, traceId$1)) return;
|
|
1614
|
-
}
|
|
1615
1636
|
const alsContext = require_async_context.LogixiaContext.get();
|
|
1637
|
+
let activeTraceId;
|
|
1638
|
+
if (this.config.traceId) {
|
|
1639
|
+
const ctxTraceId = alsContext === null || alsContext === void 0 ? void 0 : alsContext.traceId;
|
|
1640
|
+
activeTraceId = require_request_trace.TraceContext.instance.getCurrentTraceId() ?? (typeof ctxTraceId === "string" ? ctxTraceId : void 0);
|
|
1641
|
+
}
|
|
1642
|
+
if (this._sampler && !this._sampler.shouldEmit(level, activeTraceId)) return;
|
|
1616
1643
|
const hasAls = alsContext !== void 0 && Object.keys(alsContext).length > 0;
|
|
1617
|
-
const otelFields = _isOtelBridgeEnabled() ? _getOtelPayloadIfEnabled() : void 0;
|
|
1644
|
+
const otelFields = require_otel._isOtelBridgeEnabled() ? require_otel._getOtelPayloadIfEnabled() : void 0;
|
|
1618
1645
|
const hasOtel = otelFields !== void 0 && Object.keys(otelFields).length > 0;
|
|
1646
|
+
const traceId = this.config.traceId ? activeTraceId ?? this.fallbackTraceId : void 0;
|
|
1619
1647
|
let mergedData;
|
|
1620
|
-
if (hasAls)
|
|
1621
|
-
...alsContext
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1648
|
+
if (hasAls) {
|
|
1649
|
+
const als = { ...alsContext };
|
|
1650
|
+
if (traceId !== void 0 && als["traceId"] === traceId) delete als["traceId"];
|
|
1651
|
+
mergedData = {
|
|
1652
|
+
...als,
|
|
1653
|
+
...hasOtel ? otelFields : {},
|
|
1654
|
+
...data
|
|
1655
|
+
};
|
|
1656
|
+
} else if (hasOtel) mergedData = {
|
|
1626
1657
|
...otelFields,
|
|
1627
1658
|
...data
|
|
1628
1659
|
};
|
|
@@ -1632,14 +1663,15 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1632
1663
|
...mergedData
|
|
1633
1664
|
} : mergedData;
|
|
1634
1665
|
let payload;
|
|
1635
|
-
if (rawPayload !== void 0 && rawPayload !== null)
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1666
|
+
if (rawPayload !== void 0 && rawPayload !== null) {
|
|
1667
|
+
if (this._hasRedact) try {
|
|
1668
|
+
payload = applyRedaction(rawPayload, this.config.redact) ?? rawPayload;
|
|
1669
|
+
} catch (error) {
|
|
1670
|
+
require_internal_log.internalError("Redaction failed", error);
|
|
1671
|
+
payload = { redaction: REDACTION_FAILED };
|
|
1672
|
+
}
|
|
1673
|
+
else payload = rawPayload;
|
|
1640
1674
|
}
|
|
1641
|
-
else payload = rawPayload;
|
|
1642
|
-
const traceId = this.config.traceId ? require_trace_utils.TraceContext.instance.getCurrentTraceId() ?? this.fallbackTraceId : void 0;
|
|
1643
1675
|
let safeMessage = message;
|
|
1644
1676
|
if (this._hasRedact) try {
|
|
1645
1677
|
safeMessage = applyRedactionToString(message, this.config.redact);
|
|
@@ -1670,6 +1702,7 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1670
1702
|
* The level map and threshold are pre-built in _buildPerfCaches().
|
|
1671
1703
|
*/
|
|
1672
1704
|
shouldLog(level) {
|
|
1705
|
+
if (this._nsSeenVersion !== this._nsStore.version) this._syncNamespaceLevels();
|
|
1673
1706
|
const v = this._levelValues.get(level);
|
|
1674
1707
|
return v !== void 0 && v <= this._minLevelValue;
|
|
1675
1708
|
}
|
|
@@ -1677,19 +1710,21 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1677
1710
|
* Feature 3: Resolve the effective log level for this logger instance.
|
|
1678
1711
|
*
|
|
1679
1712
|
* Priority:
|
|
1713
|
+
* 0. A level set at runtime with `setLevel()` (explicit programmatic call, wins over all below)
|
|
1680
1714
|
* 1. ENV `LOGIXIA_LEVEL_<NS_UPPER>` (e.g. LOGIXIA_LEVEL_DB for ns "db" or "db.queries")
|
|
1681
1715
|
* 2. Matching `namespaceLevels` config entry (longer pattern = more specific, wins)
|
|
1682
1716
|
* 3. Global `LOGIXIA_LEVEL` ENV override
|
|
1683
1717
|
* 4. `levelOptions.level` (resolved via Feature 5 in constructor)
|
|
1684
1718
|
*/
|
|
1685
1719
|
resolveEffectiveLevel() {
|
|
1720
|
+
if (this._runtimeLevel) return this._runtimeLevel;
|
|
1686
1721
|
const ns = this.context;
|
|
1687
1722
|
if (ns) {
|
|
1688
1723
|
const nsKey = ns.split(".")[0].toUpperCase();
|
|
1689
1724
|
const envNsLevel = this._validLevel(process.env[`LOGIXIA_LEVEL_${nsKey}`], `LOGIXIA_LEVEL_${nsKey}`);
|
|
1690
1725
|
if (envNsLevel) return envNsLevel;
|
|
1691
|
-
const namespaceLevels = this.
|
|
1692
|
-
if (namespaceLevels) {
|
|
1726
|
+
const namespaceLevels = this._nsStore.levels;
|
|
1727
|
+
if (Object.keys(namespaceLevels).length > 0) {
|
|
1693
1728
|
const sortedPatterns = Object.keys(namespaceLevels).sort((a, b) => b.length - a.length);
|
|
1694
1729
|
for (const pattern of sortedPatterns) if (matchesNamespacePattern(ns, pattern)) {
|
|
1695
1730
|
const nsLevel = this._validLevel(namespaceLevels[pattern], `namespaceLevels['${pattern}']`);
|
|
@@ -1717,9 +1752,9 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1717
1752
|
if (((_this$config$format4 = this.config.format) === null || _this$config$format4 === void 0 ? void 0 : _this$config$format4.timestamp) !== false && this._fieldCache.get("timestamp") !== false) formatted += `${gray}[${entry.timestamp}]${reset} `;
|
|
1718
1753
|
if (this._fieldCache.get("level") !== false) formatted += this._formattedLevels.get(entry.level) ?? `[${entry.level.toUpperCase()}] `;
|
|
1719
1754
|
formatted += this._formattedAppName;
|
|
1720
|
-
if (entry.traceId && this._fieldCache.get("traceId") !== false) formatted += `${cyan}[${
|
|
1721
|
-
if (entry.context && this._fieldCache.get("context") !== false) formatted += `${yellow}[${
|
|
1722
|
-
if (this._fieldCache.get("message") !== false) formatted +=
|
|
1755
|
+
if (entry.traceId && this._fieldCache.get("traceId") !== false) formatted += `${cyan}[${require_otel.stripControlChars(String(entry.traceId))}]${reset} `;
|
|
1756
|
+
if (entry.context && this._fieldCache.get("context") !== false) formatted += `${yellow}[${require_otel.stripControlChars(String(entry.context))}]${reset} `;
|
|
1757
|
+
if (this._fieldCache.get("message") !== false) formatted += require_otel.stripControlChars(require_coerce_utils.safeToString(entry.message));
|
|
1723
1758
|
if (entry.payload !== void 0 && this._fieldCache.get("payload") !== false) formatted += ` ${require_safe_stringify.stringifyForLog(entry.payload)}`;
|
|
1724
1759
|
return formatted;
|
|
1725
1760
|
}
|
|
@@ -1756,6 +1791,22 @@ var LogixiaLogger = class LogixiaLogger {
|
|
|
1756
1791
|
(level === LogLevel.ERROR ? process.stderr : process.stdout).write(this.formatLog(entry) + "\n");
|
|
1757
1792
|
}
|
|
1758
1793
|
};
|
|
1794
|
+
/**
|
|
1795
|
+
* Create a logger from `config`, with an optional default `context` label.
|
|
1796
|
+
*
|
|
1797
|
+
* Every key of `levelOptions.levels` that is not already a method becomes an
|
|
1798
|
+
* async method on the returned logger, typed through the config, and routes to
|
|
1799
|
+
* {@link LogixiaLogger.logLevel}.
|
|
1800
|
+
*
|
|
1801
|
+
* @example
|
|
1802
|
+
* ```ts
|
|
1803
|
+
* const logger = createLogger({
|
|
1804
|
+
* appName: 'api',
|
|
1805
|
+
* levelOptions: { level: 'info', levels: { error: 0, warn: 1, info: 2, audit: 2 } },
|
|
1806
|
+
* });
|
|
1807
|
+
* await logger.audit('user exported data', { userId: 'u1' });
|
|
1808
|
+
* ```
|
|
1809
|
+
*/
|
|
1759
1810
|
function createLogger(config, context) {
|
|
1760
1811
|
var _config$levelOptions3;
|
|
1761
1812
|
const logger = new LogixiaLogger(config, context);
|
|
@@ -1767,9 +1818,7 @@ function createLogger(config, context) {
|
|
|
1767
1818
|
}
|
|
1768
1819
|
return logger;
|
|
1769
1820
|
}
|
|
1770
|
-
|
|
1771
|
-
//#endregion
|
|
1772
|
-
//#region src/exceptions/exception.ts
|
|
1821
|
+
// src/exceptions/exception.ts
|
|
1773
1822
|
var LogixiaException = class extends Error {
|
|
1774
1823
|
constructor(options) {
|
|
1775
1824
|
super(options.message, { cause: options.cause });
|
|
@@ -1800,9 +1849,21 @@ var LogixiaException = class extends Error {
|
|
|
1800
1849
|
function isLogixiaException(value) {
|
|
1801
1850
|
return value instanceof LogixiaException;
|
|
1802
1851
|
}
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1852
|
+
// src/exceptions/builder.ts
|
|
1853
|
+
/**
|
|
1854
|
+
* ErrorResponseBuilder — turns any exception into a `LogixiaErrorResponse`.
|
|
1855
|
+
*
|
|
1856
|
+
* Priority order:
|
|
1857
|
+
* 1. `LogixiaException` — typed fields used directly
|
|
1858
|
+
* 2. NestJS `HttpException` — duck-typed; status + message extracted
|
|
1859
|
+
* 3. Plain `Error` / unknown — falls back to 500 `server_error`
|
|
1860
|
+
*
|
|
1861
|
+
* The builder **always** populates `debug` when possible.
|
|
1862
|
+
* Your exception filter is responsible for stripping it in production:
|
|
1863
|
+
* ```ts
|
|
1864
|
+
* if (process.env.NODE_ENV === 'production') delete response.debug;
|
|
1865
|
+
* ```
|
|
1866
|
+
*/
|
|
1806
1867
|
/**
|
|
1807
1868
|
* Generates a trace ID via the shared {@link TraceContext} generator.
|
|
1808
1869
|
*
|
|
@@ -1813,7 +1874,7 @@ function isLogixiaException(value) {
|
|
|
1813
1874
|
* @example `'550e8400-e29b-41d4-a716-446655440000'`
|
|
1814
1875
|
*/
|
|
1815
1876
|
function generateTraceId() {
|
|
1816
|
-
return
|
|
1877
|
+
return require_request_trace.TraceContext.instance.generate();
|
|
1817
1878
|
}
|
|
1818
1879
|
/** @deprecated Use `generateTraceId` instead. */
|
|
1819
1880
|
const generateRequestId = generateTraceId;
|
|
@@ -1900,11 +1961,11 @@ var ErrorResponseBuilder = class {
|
|
|
1900
1961
|
debug: exposeDebug,
|
|
1901
1962
|
cause: exposeCause
|
|
1902
1963
|
};
|
|
1903
|
-
const traceId =
|
|
1964
|
+
const traceId = require_request_trace.TraceContext.instance.getCurrentTraceId() ?? rawTraceId;
|
|
1904
1965
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1905
1966
|
const durationMs = startTime !== void 0 ? Date.now() - startTime : void 0;
|
|
1906
1967
|
if (isLogixiaException(exception)) {
|
|
1907
|
-
const debug
|
|
1968
|
+
const debug = buildDebug(exception, service, durationMs, expose);
|
|
1908
1969
|
const errorBlock = {
|
|
1909
1970
|
type: exception.errorType,
|
|
1910
1971
|
code: exception.errorCode,
|
|
@@ -1923,7 +1984,7 @@ var ErrorResponseBuilder = class {
|
|
|
1923
1984
|
path,
|
|
1924
1985
|
status: exception.httpStatus
|
|
1925
1986
|
},
|
|
1926
|
-
...debug
|
|
1987
|
+
...debug !== void 0 ? { debug } : {}
|
|
1927
1988
|
},
|
|
1928
1989
|
httpStatus: exception.httpStatus
|
|
1929
1990
|
};
|
|
@@ -1939,7 +2000,7 @@ var ErrorResponseBuilder = class {
|
|
|
1939
2000
|
} else message = exception.message;
|
|
1940
2001
|
const type = httpStatusToType(status);
|
|
1941
2002
|
const code = `HTTP_${status}`;
|
|
1942
|
-
const debug
|
|
2003
|
+
const debug = buildDebug(exception, service, durationMs, expose);
|
|
1943
2004
|
return {
|
|
1944
2005
|
response: {
|
|
1945
2006
|
success: false,
|
|
@@ -1954,7 +2015,7 @@ var ErrorResponseBuilder = class {
|
|
|
1954
2015
|
path,
|
|
1955
2016
|
status
|
|
1956
2017
|
},
|
|
1957
|
-
...debug
|
|
2018
|
+
...debug !== void 0 ? { debug } : {}
|
|
1958
2019
|
},
|
|
1959
2020
|
httpStatus: status
|
|
1960
2021
|
};
|
|
@@ -1980,174 +2041,149 @@ var ErrorResponseBuilder = class {
|
|
|
1980
2041
|
};
|
|
1981
2042
|
}
|
|
1982
2043
|
};
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
return DEFAULT_CONFIG;
|
|
1989
|
-
}
|
|
1990
|
-
});
|
|
1991
|
-
Object.defineProperty(exports, 'DEFAULT_LOG_COLORS', {
|
|
1992
|
-
enumerable: true,
|
|
1993
|
-
get: function () {
|
|
1994
|
-
return DEFAULT_LOG_COLORS;
|
|
1995
|
-
}
|
|
1996
|
-
});
|
|
1997
|
-
Object.defineProperty(exports, 'DEFAULT_LOG_LEVELS', {
|
|
1998
|
-
enumerable: true,
|
|
1999
|
-
get: function () {
|
|
2000
|
-
return DEFAULT_LOG_LEVELS;
|
|
2001
|
-
}
|
|
2002
|
-
});
|
|
2003
|
-
Object.defineProperty(exports, 'ErrorResponseBuilder', {
|
|
2004
|
-
enumerable: true,
|
|
2005
|
-
get: function () {
|
|
2006
|
-
return ErrorResponseBuilder;
|
|
2007
|
-
}
|
|
2008
|
-
});
|
|
2009
|
-
Object.defineProperty(exports, 'LogLevel', {
|
|
2010
|
-
enumerable: true,
|
|
2011
|
-
get: function () {
|
|
2012
|
-
return LogLevel;
|
|
2013
|
-
}
|
|
2044
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", {
|
|
2045
|
+
enumerable: true,
|
|
2046
|
+
get: function() {
|
|
2047
|
+
return DEFAULT_CONFIG;
|
|
2048
|
+
}
|
|
2014
2049
|
});
|
|
2015
|
-
Object.defineProperty(exports,
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2050
|
+
Object.defineProperty(exports, "DEFAULT_LOG_COLORS", {
|
|
2051
|
+
enumerable: true,
|
|
2052
|
+
get: function() {
|
|
2053
|
+
return DEFAULT_LOG_COLORS;
|
|
2054
|
+
}
|
|
2020
2055
|
});
|
|
2021
|
-
Object.defineProperty(exports,
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2056
|
+
Object.defineProperty(exports, "DEFAULT_LOG_LEVELS", {
|
|
2057
|
+
enumerable: true,
|
|
2058
|
+
get: function() {
|
|
2059
|
+
return DEFAULT_LOG_LEVELS;
|
|
2060
|
+
}
|
|
2026
2061
|
});
|
|
2027
|
-
Object.defineProperty(exports,
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2062
|
+
Object.defineProperty(exports, "ErrorResponseBuilder", {
|
|
2063
|
+
enumerable: true,
|
|
2064
|
+
get: function() {
|
|
2065
|
+
return ErrorResponseBuilder;
|
|
2066
|
+
}
|
|
2032
2067
|
});
|
|
2033
|
-
Object.defineProperty(exports,
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2068
|
+
Object.defineProperty(exports, "LogLevel", {
|
|
2069
|
+
enumerable: true,
|
|
2070
|
+
get: function() {
|
|
2071
|
+
return LogLevel;
|
|
2072
|
+
}
|
|
2038
2073
|
});
|
|
2039
|
-
Object.defineProperty(exports,
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2074
|
+
Object.defineProperty(exports, "LogixiaException", {
|
|
2075
|
+
enumerable: true,
|
|
2076
|
+
get: function() {
|
|
2077
|
+
return LogixiaException;
|
|
2078
|
+
}
|
|
2044
2079
|
});
|
|
2045
|
-
Object.defineProperty(exports,
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2080
|
+
Object.defineProperty(exports, "LogixiaLogger", {
|
|
2081
|
+
enumerable: true,
|
|
2082
|
+
get: function() {
|
|
2083
|
+
return LogixiaLogger;
|
|
2084
|
+
}
|
|
2050
2085
|
});
|
|
2051
|
-
Object.defineProperty(exports,
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2086
|
+
Object.defineProperty(exports, "PluginRegistry", {
|
|
2087
|
+
enumerable: true,
|
|
2088
|
+
get: function() {
|
|
2089
|
+
return PluginRegistry;
|
|
2090
|
+
}
|
|
2056
2091
|
});
|
|
2057
|
-
Object.defineProperty(exports,
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2092
|
+
Object.defineProperty(exports, "_shutdownRegistrySize", {
|
|
2093
|
+
enumerable: true,
|
|
2094
|
+
get: function() {
|
|
2095
|
+
return _shutdownRegistrySize;
|
|
2096
|
+
}
|
|
2062
2097
|
});
|
|
2063
|
-
Object.defineProperty(exports,
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2098
|
+
Object.defineProperty(exports, "applyRedaction", {
|
|
2099
|
+
enumerable: true,
|
|
2100
|
+
get: function() {
|
|
2101
|
+
return applyRedaction;
|
|
2102
|
+
}
|
|
2068
2103
|
});
|
|
2069
|
-
Object.defineProperty(exports,
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2104
|
+
Object.defineProperty(exports, "createLogger", {
|
|
2105
|
+
enumerable: true,
|
|
2106
|
+
get: function() {
|
|
2107
|
+
return createLogger;
|
|
2108
|
+
}
|
|
2074
2109
|
});
|
|
2075
|
-
Object.defineProperty(exports,
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2110
|
+
Object.defineProperty(exports, "deregisterFromShutdown", {
|
|
2111
|
+
enumerable: true,
|
|
2112
|
+
get: function() {
|
|
2113
|
+
return deregisterFromShutdown;
|
|
2114
|
+
}
|
|
2080
2115
|
});
|
|
2081
|
-
Object.defineProperty(exports,
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2116
|
+
Object.defineProperty(exports, "flushOnExit", {
|
|
2117
|
+
enumerable: true,
|
|
2118
|
+
get: function() {
|
|
2119
|
+
return flushOnExit;
|
|
2120
|
+
}
|
|
2086
2121
|
});
|
|
2087
|
-
Object.defineProperty(exports,
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2122
|
+
Object.defineProperty(exports, "generateRequestId", {
|
|
2123
|
+
enumerable: true,
|
|
2124
|
+
get: function() {
|
|
2125
|
+
return generateRequestId;
|
|
2126
|
+
}
|
|
2092
2127
|
});
|
|
2093
|
-
Object.defineProperty(exports,
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2128
|
+
Object.defineProperty(exports, "generateTraceId", {
|
|
2129
|
+
enumerable: true,
|
|
2130
|
+
get: function() {
|
|
2131
|
+
return generateTraceId;
|
|
2132
|
+
}
|
|
2098
2133
|
});
|
|
2099
|
-
Object.defineProperty(exports,
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2134
|
+
Object.defineProperty(exports, "globalPluginRegistry", {
|
|
2135
|
+
enumerable: true,
|
|
2136
|
+
get: function() {
|
|
2137
|
+
return globalPluginRegistry;
|
|
2138
|
+
}
|
|
2104
2139
|
});
|
|
2105
|
-
Object.defineProperty(exports,
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2140
|
+
Object.defineProperty(exports, "isError", {
|
|
2141
|
+
enumerable: true,
|
|
2142
|
+
get: function() {
|
|
2143
|
+
return isError;
|
|
2144
|
+
}
|
|
2110
2145
|
});
|
|
2111
|
-
Object.defineProperty(exports,
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2146
|
+
Object.defineProperty(exports, "isLogixiaException", {
|
|
2147
|
+
enumerable: true,
|
|
2148
|
+
get: function() {
|
|
2149
|
+
return isLogixiaException;
|
|
2150
|
+
}
|
|
2116
2151
|
});
|
|
2117
|
-
Object.defineProperty(exports,
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2152
|
+
Object.defineProperty(exports, "normalizeError", {
|
|
2153
|
+
enumerable: true,
|
|
2154
|
+
get: function() {
|
|
2155
|
+
return normalizeError;
|
|
2156
|
+
}
|
|
2122
2157
|
});
|
|
2123
|
-
Object.defineProperty(exports,
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2158
|
+
Object.defineProperty(exports, "redactObject", {
|
|
2159
|
+
enumerable: true,
|
|
2160
|
+
get: function() {
|
|
2161
|
+
return redactObject;
|
|
2162
|
+
}
|
|
2128
2163
|
});
|
|
2129
|
-
Object.defineProperty(exports,
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2164
|
+
Object.defineProperty(exports, "registerForShutdown", {
|
|
2165
|
+
enumerable: true,
|
|
2166
|
+
get: function() {
|
|
2167
|
+
return registerForShutdown;
|
|
2168
|
+
}
|
|
2134
2169
|
});
|
|
2135
|
-
Object.defineProperty(exports,
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2170
|
+
Object.defineProperty(exports, "resetShutdownHandlers", {
|
|
2171
|
+
enumerable: true,
|
|
2172
|
+
get: function() {
|
|
2173
|
+
return resetShutdownHandlers;
|
|
2174
|
+
}
|
|
2140
2175
|
});
|
|
2141
|
-
Object.defineProperty(exports,
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2176
|
+
Object.defineProperty(exports, "serializeError", {
|
|
2177
|
+
enumerable: true,
|
|
2178
|
+
get: function() {
|
|
2179
|
+
return serializeError;
|
|
2180
|
+
}
|
|
2146
2181
|
});
|
|
2147
|
-
Object.defineProperty(exports,
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2182
|
+
Object.defineProperty(exports, "usePlugin", {
|
|
2183
|
+
enumerable: true,
|
|
2184
|
+
get: function() {
|
|
2185
|
+
return usePlugin;
|
|
2186
|
+
}
|
|
2152
2187
|
});
|
|
2153
|
-
|
|
2188
|
+
|
|
2189
|
+
//# sourceMappingURL=builder-yFvJrz7o.js.map
|