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
package/dist/worker.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./transport
|
|
2
|
-
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-JvGPog3C.mjs";
|
|
1
|
+
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-Bl8lFRck.mjs";
|
|
3
2
|
export { WorkerTransport, WorkerTransportConfig };
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./transport
|
|
2
|
-
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-CdzSZJmw.js";
|
|
1
|
+
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-B9mCQSM1.js";
|
|
3
2
|
export { WorkerTransport, WorkerTransportConfig };
|
package/dist/worker.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
const require_worker_transport = require(
|
|
3
|
-
|
|
4
|
-
exports.WorkerTransport = require_worker_transport.WorkerTransport;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_worker_transport = require("./worker.transport-DxxbqQCG.js");
|
|
3
|
+
exports.WorkerTransport = require_worker_transport.WorkerTransport;
|
package/dist/worker.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/transports/worker.transport.d.ts
|
|
4
|
-
|
|
1
|
+
import { _ as TransportLogEntry, d as ITransport } from "./transport.types-CzJq4IrF.js";
|
|
5
2
|
interface WorkerTransportConfig {
|
|
6
3
|
/**
|
|
7
4
|
* Which built-in logixia transport to run inside the worker thread.
|
|
@@ -21,6 +18,11 @@ interface WorkerTransportConfig {
|
|
|
21
18
|
* @default 3
|
|
22
19
|
*/
|
|
23
20
|
maxRestarts?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Custom level severities (`levelOptions.levels`) the wrapped transport's own
|
|
23
|
+
* `level` is compared against inside the worker. Built-in levels need no entry.
|
|
24
|
+
*/
|
|
25
|
+
levels?: Record<string, number>;
|
|
24
26
|
/**
|
|
25
27
|
* Log level filter — only entries at or above this level are forwarded.
|
|
26
28
|
* Useful for routing only errors to an expensive transport in a worker.
|
|
@@ -71,6 +73,5 @@ declare class WorkerTransport implements ITransport {
|
|
|
71
73
|
shutdown(): Promise<void>;
|
|
72
74
|
private drainBufferTo;
|
|
73
75
|
}
|
|
74
|
-
//#endregion
|
|
75
76
|
export { WorkerTransportConfig as n, WorkerTransport as t };
|
|
76
|
-
//# sourceMappingURL=worker.transport-
|
|
77
|
+
//# sourceMappingURL=worker.transport-B9mCQSM1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.transport-B9mCQSM1.d.ts","names":[],"sources":["../src/transports/worker.transport.ts"],"mappings":";UA0CiB;;;;;EAKf;;EAEA,iBAAiB;;;;;;EAMjB;;;;;EAKA;;;;;EAKA,SAAS;;;;;EAKT;;;;;;cAOW,2BAA2B;WACtB;WACA;WACA;WACA;UAER;UACA;mBACS;mBACA;UACT;mBACS;mBACA;;UAET;;UAEA;;mBAES;;mBAEA;EAEL,YAAA,QAAQ;UASZ;;YAsCE;UAIF;UAuBA;EASR,MAAM,OAAO;EAYP,SAAS;;;;;;;;EAiCT,SAAS;;EAkCT,YAAY;UAIV"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/transports/worker.transport.d.ts
|
|
4
|
-
|
|
1
|
+
import { _ as TransportLogEntry, d as ITransport } from "./transport.types-CzJq4IrF.mjs";
|
|
5
2
|
interface WorkerTransportConfig {
|
|
6
3
|
/**
|
|
7
4
|
* Which built-in logixia transport to run inside the worker thread.
|
|
@@ -21,6 +18,11 @@ interface WorkerTransportConfig {
|
|
|
21
18
|
* @default 3
|
|
22
19
|
*/
|
|
23
20
|
maxRestarts?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Custom level severities (`levelOptions.levels`) the wrapped transport's own
|
|
23
|
+
* `level` is compared against inside the worker. Built-in levels need no entry.
|
|
24
|
+
*/
|
|
25
|
+
levels?: Record<string, number>;
|
|
24
26
|
/**
|
|
25
27
|
* Log level filter — only entries at or above this level are forwarded.
|
|
26
28
|
* Useful for routing only errors to an expensive transport in a worker.
|
|
@@ -71,6 +73,5 @@ declare class WorkerTransport implements ITransport {
|
|
|
71
73
|
shutdown(): Promise<void>;
|
|
72
74
|
private drainBufferTo;
|
|
73
75
|
}
|
|
74
|
-
//#endregion
|
|
75
76
|
export { WorkerTransportConfig as n, WorkerTransport as t };
|
|
76
|
-
//# sourceMappingURL=worker.transport-
|
|
77
|
+
//# sourceMappingURL=worker.transport-Bl8lFRck.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.transport-Bl8lFRck.d.mts","names":[],"sources":["../src/transports/worker.transport.ts"],"mappings":";UA0CiB;;;;;EAKf;;EAEA,iBAAiB;;;;;;EAMjB;;;;;EAKA;;;;;EAKA,SAAS;;;;;EAKT;;;;;;cAOW,2BAA2B;WACtB;WACA;WACA;WACA;UAER;UACA;mBACS;mBACA;UACT;mBACS;mBACA;;UAET;;UAEA;;mBAES;;mBAEA;EAEL,YAAA,QAAQ;UASZ;;YAsCE;UAIF;UAuBA;EASR,MAAM,OAAO;EAYP,SAAS;;;;;;;;EAiCT,SAAS;;EAkCT,YAAY;UAIV"}
|
|
@@ -1,15 +1,47 @@
|
|
|
1
|
-
import { r as internalWarn, t as internalError } from "./internal-log-
|
|
1
|
+
import { r as internalWarn, t as internalError } from "./internal-log-Bg4V1cPg.mjs";
|
|
2
|
+
import { n as protectSecrets } from "./secret-config-Dhb6pqTU.mjs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { Worker } from "node:worker_threads";
|
|
5
|
-
|
|
6
|
-
//#region node_modules/tsdown/esm-shims.js
|
|
6
|
+
// node_modules/tsdown/esm-shims.js
|
|
7
7
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
8
8
|
const getDirname = () => path.dirname(getFilename());
|
|
9
9
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// src/transports/worker.transport.ts
|
|
11
|
+
/**
|
|
12
|
+
* logixia — Worker Thread Transport
|
|
13
|
+
*
|
|
14
|
+
* Offloads JSON serialization and all I/O to a Node.js worker thread,
|
|
15
|
+
* completely eliminating any event-loop impact from logging. The main thread
|
|
16
|
+
* only posts a raw message to the worker — it never calls JSON.stringify or
|
|
17
|
+
* any I/O syscalls on the hot path.
|
|
18
|
+
*
|
|
19
|
+
* Architecture:
|
|
20
|
+
* Main thread → MessageChannel → Worker thread → Wrapped transport
|
|
21
|
+
*
|
|
22
|
+
* The worker runs an ordinary logixia transport (file, database, console…)
|
|
23
|
+
* inside its own event loop. If the worker crashes it is restarted automatically
|
|
24
|
+
* (up to `maxRestarts` times) and buffered messages are replayed.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { WorkerTransport } from 'logixia/worker';
|
|
29
|
+
*
|
|
30
|
+
* const logger = createLogger({
|
|
31
|
+
* transports: {
|
|
32
|
+
* // Run file transport inside a worker thread — zero event-loop impact
|
|
33
|
+
* custom: [
|
|
34
|
+
* new WorkerTransport({
|
|
35
|
+
* transportType: 'file',
|
|
36
|
+
* transportConfig: { filename: 'app.log', dirname: './logs' },
|
|
37
|
+
* bufferSize: 500,
|
|
38
|
+
* maxRestarts: 3,
|
|
39
|
+
* }),
|
|
40
|
+
* ],
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
13
45
|
/**
|
|
14
46
|
* Transport that runs a wrapped transport inside a dedicated Node.js worker
|
|
15
47
|
* thread, completely removing JSON serialization and I/O from the main event loop.
|
|
@@ -31,13 +63,15 @@ var WorkerTransport = class {
|
|
|
31
63
|
this.bufferSize = config.bufferSize ?? 1e3;
|
|
32
64
|
this.maxRestarts = config.maxRestarts ?? 3;
|
|
33
65
|
this.level = config.level;
|
|
66
|
+
protectSecrets(this, ["config"]);
|
|
34
67
|
this.startWorker();
|
|
35
68
|
}
|
|
36
69
|
startWorker() {
|
|
37
70
|
try {
|
|
38
71
|
this.worker = new Worker(this.workerFile(), { workerData: {
|
|
39
72
|
transportType: this.config.transportType,
|
|
40
|
-
transportConfig: this.config.transportConfig
|
|
73
|
+
transportConfig: this.config.transportConfig,
|
|
74
|
+
levels: this.config.levels
|
|
41
75
|
} });
|
|
42
76
|
this.worker.on("message", (msg) => {
|
|
43
77
|
if (msg.type === "ready") {
|
|
@@ -161,7 +195,6 @@ var WorkerTransport = class {
|
|
|
161
195
|
}
|
|
162
196
|
}
|
|
163
197
|
};
|
|
164
|
-
|
|
165
|
-
//#endregion
|
|
166
198
|
export { WorkerTransport as t };
|
|
167
|
-
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=worker.transport-BmmOKb1-.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.transport-BmmOKb1-.mjs","names":[],"sources":["../node_modules/tsdown/esm-shims.js","../src/transports/worker.transport.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","/**\n * logixia — Worker Thread Transport\n *\n * Offloads JSON serialization and all I/O to a Node.js worker thread,\n * completely eliminating any event-loop impact from logging. The main thread\n * only posts a raw message to the worker — it never calls JSON.stringify or\n * any I/O syscalls on the hot path.\n *\n * Architecture:\n * Main thread → MessageChannel → Worker thread → Wrapped transport\n *\n * The worker runs an ordinary logixia transport (file, database, console…)\n * inside its own event loop. If the worker crashes it is restarted automatically\n * (up to `maxRestarts` times) and buffered messages are replayed.\n *\n * @example\n * ```ts\n * import { WorkerTransport } from 'logixia/worker';\n *\n * const logger = createLogger({\n * transports: {\n * // Run file transport inside a worker thread — zero event-loop impact\n * custom: [\n * new WorkerTransport({\n * transportType: 'file',\n * transportConfig: { filename: 'app.log', dirname: './logs' },\n * bufferSize: 500,\n * maxRestarts: 3,\n * }),\n * ],\n * },\n * });\n * ```\n */\n\nimport path from 'node:path';\nimport { Worker } from 'node:worker_threads';\n\nimport type { ITransport, TransportLogEntry } from '../types/transport.types';\nimport { internalError, internalWarn } from '../utils/internal-log';\nimport { protectSecrets } from './secret-config';\n\nexport interface WorkerTransportConfig {\n /**\n * Which built-in logixia transport to run inside the worker thread.\n * The worker resolves the correct module automatically.\n */\n transportType: 'file' | 'database' | 'console';\n /** Config forwarded verbatim to the wrapped transport constructor. */\n transportConfig: Record<string, unknown>;\n /**\n * Max log entries to buffer in the main thread while the worker is starting\n * or restarting. Entries beyond this limit are dropped with a warning.\n * @default 1000\n */\n bufferSize?: number;\n /**\n * How many times to restart the worker if it crashes unexpectedly.\n * @default 3\n */\n maxRestarts?: number;\n /**\n * Custom level severities (`levelOptions.levels`) the wrapped transport's own\n * `level` is compared against inside the worker. Built-in levels need no entry.\n */\n levels?: Record<string, number>;\n /**\n * Log level filter — only entries at or above this level are forwarded.\n * Useful for routing only errors to an expensive transport in a worker.\n */\n level?: string;\n}\n\n/**\n * Transport that runs a wrapped transport inside a dedicated Node.js worker\n * thread, completely removing JSON serialization and I/O from the main event loop.\n */\nexport class WorkerTransport implements ITransport {\n public readonly name = 'worker';\n public readonly level: string | undefined;\n public readonly batchSize = 1;\n public readonly flushInterval = 0;\n\n private worker: Worker | null = null;\n private ready = false;\n private readonly buffer: TransportLogEntry[] = [];\n private readonly bufferSize: number;\n private restarts = 0;\n private readonly maxRestarts: number;\n private readonly config: WorkerTransportConfig;\n /** Pending restart-backoff timer, so close() can cancel a queued restart. */\n private restartTimer: NodeJS.Timeout | null = null;\n /** Set once close() begins, so a worker 'exit' no longer triggers a restart. */\n private closing = false;\n /** Max time to wait for the worker's 'flushed' ack before giving up. */\n private readonly FLUSH_TIMEOUT_MS = 5000;\n /** Max time to wait for a graceful worker exit before force-terminating. */\n private readonly SHUTDOWN_TIMEOUT_MS = 5000;\n\n constructor(config: WorkerTransportConfig) {\n this.config = config;\n this.bufferSize = config.bufferSize ?? 1000;\n this.maxRestarts = config.maxRestarts ?? 3;\n this.level = config.level;\n protectSecrets(this, ['config']);\n this.startWorker();\n }\n\n private startWorker(): void {\n try {\n this.worker = new Worker(this.workerFile(), {\n workerData: {\n transportType: this.config.transportType,\n transportConfig: this.config.transportConfig,\n levels: this.config.levels,\n },\n });\n\n this.worker.on('message', (msg: { type: string; error?: string }) => {\n if (msg.type === 'ready') {\n this.ready = true;\n this.drainBuffer();\n } else if (msg.type === 'error' || msg.type === 'write-error') {\n internalError(\n `WorkerTransport [${this.config.transportType}]: ${msg.error ?? 'unknown'}`\n );\n }\n });\n\n this.worker.on('error', (err) => {\n internalError('WorkerTransport worker error', err);\n this.handleWorkerExit();\n });\n\n this.worker.on('exit', (code) => {\n if (code !== 0) {\n internalWarn(`WorkerTransport worker exited with code ${code}`);\n this.handleWorkerExit();\n }\n });\n } catch (err) {\n internalError('WorkerTransport failed to start', err);\n }\n }\n\n /** The worker entry is always built as CommonJS, next to this module's output. */\n protected workerFile(): string {\n return path.join(__dirname, 'worker-entry.js');\n }\n\n private handleWorkerExit(): void {\n this.ready = false;\n // Don't resurrect a worker we're intentionally shutting down — close() sets\n // `closing` and nulls the worker, so a late 'exit'/'error' event must not\n // queue a restart (which would spawn a fresh leaked thread post-shutdown).\n if (this.closing) return;\n if (this.restarts < this.maxRestarts) {\n this.restarts++;\n internalWarn(`WorkerTransport restarting (attempt ${this.restarts}/${this.maxRestarts})`);\n // Small backoff before restart. unref() so a perpetually-failing worker's\n // pending restart never keeps the process alive on its own.\n this.restartTimer = setTimeout(() => {\n this.restartTimer = null;\n this.startWorker();\n }, 500 * this.restarts);\n if (this.restartTimer.unref) this.restartTimer.unref();\n } else {\n internalError(\n `WorkerTransport exhausted ${this.maxRestarts} restart attempts — transport disabled`\n );\n }\n }\n\n private drainBuffer(): void {\n while (this.buffer.length > 0 && this.ready && this.worker) {\n const entry = this.buffer.shift();\n if (entry) {\n this.worker.postMessage({ type: 'write', entry });\n }\n }\n }\n\n write(entry: TransportLogEntry): void {\n if (this.ready && this.worker) {\n this.worker.postMessage({ type: 'write', entry });\n } else {\n if (this.buffer.length >= this.bufferSize) {\n internalWarn('WorkerTransport buffer full — dropping oldest entry');\n this.buffer.shift();\n }\n this.buffer.push(entry);\n }\n }\n\n async flush(): Promise<void> {\n if (!this.ready || !this.worker) return;\n const worker = this.worker;\n return new Promise<void>((resolve) => {\n // Time-box the flush: if the worker dies or restarts before answering,\n // the 'flushed' message would never arrive and this promise would hang\n // forever, blocking shutdown until the force-exit timer kills the process\n // (losing everything). Resolve on timeout so close() can still terminate.\n const timer = setTimeout(() => {\n worker.off('message', handler);\n resolve();\n }, this.FLUSH_TIMEOUT_MS);\n if (timer.unref) timer.unref();\n\n const handler = (msg: { type: string }) => {\n if (msg.type === 'flushed') {\n clearTimeout(timer);\n worker.off('message', handler);\n resolve();\n }\n };\n worker.on('message', handler);\n worker.postMessage({ type: 'flush' });\n });\n }\n\n /**\n * Flush the worker's buffer and terminate the thread on shutdown.\n *\n * This MUST be named close() — TransportManager.close() invokes\n * transport.close(), so a method named only shutdown() was never called on\n * graceful exit, leaking the worker thread and dropping its buffered logs.\n */\n async close(): Promise<void> {\n // Stop the restart loop first: cancel any queued backoff restart and flag\n // that further worker exits are expected (so handleWorkerExit no-ops).\n this.closing = true;\n if (this.restartTimer) {\n clearTimeout(this.restartTimer);\n this.restartTimer = null;\n }\n\n if (!this.worker) return;\n const worker = this.worker;\n this.worker = null;\n\n // Push any locally-buffered (pre-ready) entries first: the worker's port\n // queues them until its listener attaches, so they are handled before the\n // shutdown message, which flushes the wrapped transport and exits.\n this.drainBufferTo(worker);\n worker.postMessage({ type: 'shutdown' });\n\n await new Promise<void>((resolve) => {\n // Don't wait forever for a wedged worker — terminate() it after a timeout.\n const timer = setTimeout(() => {\n worker.terminate().finally(() => resolve());\n }, this.SHUTDOWN_TIMEOUT_MS);\n if (timer.unref) timer.unref();\n\n worker.once('exit', () => {\n clearTimeout(timer);\n resolve();\n });\n });\n }\n\n /** Back-compat alias — prefer close(). */\n async shutdown(): Promise<void> {\n await this.close();\n }\n\n private drainBufferTo(worker: Worker): void {\n while (this.buffer.length > 0) {\n const entry = this.buffer.shift();\n if (entry) worker.postMessage({ type: 'write', entry });\n }\n }\n}\n"],"ignoreList":[0],"mappings":";;;;;;AAIA,MAAM,oBAAoB,cAAc,YAAY,GAAG;AACvD,MAAM,mBAAmB,KAAK,QAAQ,YAAY,CAAC;AAEnD,MAAa,YAA4B,2BAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACsEpD,IAAa,kBAAb,MAAmD;CAsBjD,YAAY,QAA+B;EArBpB,KAAA,OAAA;EAEK,KAAA,YAAA;EACI,KAAA,gBAAA;EAEA,KAAA,SAAA;EAChB,KAAA,QAAA;EAC+B,KAAA,SAAA,CAAC;EAE7B,KAAA,WAAA;EAI2B,KAAA,eAAA;EAE5B,KAAA,UAAA;EAEkB,KAAA,mBAAA;EAEG,KAAA,sBAAA;EAGrC,KA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MAAM,QAAQ,iBAAiB;IAC7B,OAAO,UAAU,CAAC,CAAC,cAAc,QAAQ,CAAC;GAC5C,GAAG,KAAK,mBAAmB;GAC3B,IAAI,MAAM,OAAO,MAAM,MAAM;GAE7B,OAAO,KAAK,cAAc;IACxB,aAAa,KAAK;IAClB,QAAQ;GACV,CAAC;EACH,CAAC;CACH;;CAGA,MAAM,WAA0B;EAC9B,MAAM,KAAK,MAAM;CACnB;CAEA,cAAsB,QAAsB;EAC1C,OAAO,KAAK,OAAO,SAAS,GAAG;GAC7B,MAAM,QAAQ,KAAK,OAAO,MAAM;GAChC,IAAI,OAAO,OAAO,YAAY;IAAE,MAAM;IAAS;GAAM,CAAC;EACxD;CACF;AACF"}
|
|
@@ -1,11 +1,43 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_internal_log = require(
|
|
1
|
+
const require_secret_config = require("./secret-config-CmK2wVkr.js");
|
|
2
|
+
const require_internal_log = require("./internal-log-By4Govmu.js");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
|
-
node_path =
|
|
4
|
+
node_path = require_secret_config.__toESM(node_path);
|
|
5
5
|
let node_worker_threads = require("node:worker_threads");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// src/transports/worker.transport.ts
|
|
7
|
+
/**
|
|
8
|
+
* logixia — Worker Thread Transport
|
|
9
|
+
*
|
|
10
|
+
* Offloads JSON serialization and all I/O to a Node.js worker thread,
|
|
11
|
+
* completely eliminating any event-loop impact from logging. The main thread
|
|
12
|
+
* only posts a raw message to the worker — it never calls JSON.stringify or
|
|
13
|
+
* any I/O syscalls on the hot path.
|
|
14
|
+
*
|
|
15
|
+
* Architecture:
|
|
16
|
+
* Main thread → MessageChannel → Worker thread → Wrapped transport
|
|
17
|
+
*
|
|
18
|
+
* The worker runs an ordinary logixia transport (file, database, console…)
|
|
19
|
+
* inside its own event loop. If the worker crashes it is restarted automatically
|
|
20
|
+
* (up to `maxRestarts` times) and buffered messages are replayed.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { WorkerTransport } from 'logixia/worker';
|
|
25
|
+
*
|
|
26
|
+
* const logger = createLogger({
|
|
27
|
+
* transports: {
|
|
28
|
+
* // Run file transport inside a worker thread — zero event-loop impact
|
|
29
|
+
* custom: [
|
|
30
|
+
* new WorkerTransport({
|
|
31
|
+
* transportType: 'file',
|
|
32
|
+
* transportConfig: { filename: 'app.log', dirname: './logs' },
|
|
33
|
+
* bufferSize: 500,
|
|
34
|
+
* maxRestarts: 3,
|
|
35
|
+
* }),
|
|
36
|
+
* ],
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
9
41
|
/**
|
|
10
42
|
* Transport that runs a wrapped transport inside a dedicated Node.js worker
|
|
11
43
|
* thread, completely removing JSON serialization and I/O from the main event loop.
|
|
@@ -27,13 +59,15 @@ var WorkerTransport = class {
|
|
|
27
59
|
this.bufferSize = config.bufferSize ?? 1e3;
|
|
28
60
|
this.maxRestarts = config.maxRestarts ?? 3;
|
|
29
61
|
this.level = config.level;
|
|
62
|
+
require_secret_config.protectSecrets(this, ["config"]);
|
|
30
63
|
this.startWorker();
|
|
31
64
|
}
|
|
32
65
|
startWorker() {
|
|
33
66
|
try {
|
|
34
67
|
this.worker = new node_worker_threads.Worker(this.workerFile(), { workerData: {
|
|
35
68
|
transportType: this.config.transportType,
|
|
36
|
-
transportConfig: this.config.transportConfig
|
|
69
|
+
transportConfig: this.config.transportConfig,
|
|
70
|
+
levels: this.config.levels
|
|
37
71
|
} });
|
|
38
72
|
this.worker.on("message", (msg) => {
|
|
39
73
|
if (msg.type === "ready") {
|
|
@@ -157,12 +191,11 @@ var WorkerTransport = class {
|
|
|
157
191
|
}
|
|
158
192
|
}
|
|
159
193
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return WorkerTransport;
|
|
166
|
-
}
|
|
194
|
+
Object.defineProperty(exports, "WorkerTransport", {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function() {
|
|
197
|
+
return WorkerTransport;
|
|
198
|
+
}
|
|
167
199
|
});
|
|
168
|
-
|
|
200
|
+
|
|
201
|
+
//# sourceMappingURL=worker.transport-DxxbqQCG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.transport-DxxbqQCG.js","names":["Worker","path"],"sources":["../src/transports/worker.transport.ts"],"sourcesContent":["/**\n * logixia — Worker Thread Transport\n *\n * Offloads JSON serialization and all I/O to a Node.js worker thread,\n * completely eliminating any event-loop impact from logging. The main thread\n * only posts a raw message to the worker — it never calls JSON.stringify or\n * any I/O syscalls on the hot path.\n *\n * Architecture:\n * Main thread → MessageChannel → Worker thread → Wrapped transport\n *\n * The worker runs an ordinary logixia transport (file, database, console…)\n * inside its own event loop. If the worker crashes it is restarted automatically\n * (up to `maxRestarts` times) and buffered messages are replayed.\n *\n * @example\n * ```ts\n * import { WorkerTransport } from 'logixia/worker';\n *\n * const logger = createLogger({\n * transports: {\n * // Run file transport inside a worker thread — zero event-loop impact\n * custom: [\n * new WorkerTransport({\n * transportType: 'file',\n * transportConfig: { filename: 'app.log', dirname: './logs' },\n * bufferSize: 500,\n * maxRestarts: 3,\n * }),\n * ],\n * },\n * });\n * ```\n */\n\nimport path from 'node:path';\nimport { Worker } from 'node:worker_threads';\n\nimport type { ITransport, TransportLogEntry } from '../types/transport.types';\nimport { internalError, internalWarn } from '../utils/internal-log';\nimport { protectSecrets } from './secret-config';\n\nexport interface WorkerTransportConfig {\n /**\n * Which built-in logixia transport to run inside the worker thread.\n * The worker resolves the correct module automatically.\n */\n transportType: 'file' | 'database' | 'console';\n /** Config forwarded verbatim to the wrapped transport constructor. */\n transportConfig: Record<string, unknown>;\n /**\n * Max log entries to buffer in the main thread while the worker is starting\n * or restarting. Entries beyond this limit are dropped with a warning.\n * @default 1000\n */\n bufferSize?: number;\n /**\n * How many times to restart the worker if it crashes unexpectedly.\n * @default 3\n */\n maxRestarts?: number;\n /**\n * Custom level severities (`levelOptions.levels`) the wrapped transport's own\n * `level` is compared against inside the worker. Built-in levels need no entry.\n */\n levels?: Record<string, number>;\n /**\n * Log level filter — only entries at or above this level are forwarded.\n * Useful for routing only errors to an expensive transport in a worker.\n */\n level?: string;\n}\n\n/**\n * Transport that runs a wrapped transport inside a dedicated Node.js worker\n * thread, completely removing JSON serialization and I/O from the main event loop.\n */\nexport class WorkerTransport implements ITransport {\n public readonly name = 'worker';\n public readonly level: string | undefined;\n public readonly batchSize = 1;\n public readonly flushInterval = 0;\n\n private worker: Worker | null = null;\n private ready = false;\n private readonly buffer: TransportLogEntry[] = [];\n private readonly bufferSize: number;\n private restarts = 0;\n private readonly maxRestarts: number;\n private readonly config: WorkerTransportConfig;\n /** Pending restart-backoff timer, so close() can cancel a queued restart. */\n private restartTimer: NodeJS.Timeout | null = null;\n /** Set once close() begins, so a worker 'exit' no longer triggers a restart. */\n private closing = false;\n /** Max time to wait for the worker's 'flushed' ack before giving up. */\n private readonly FLUSH_TIMEOUT_MS = 5000;\n /** Max time to wait for a graceful worker exit before force-terminating. */\n private readonly SHUTDOWN_TIMEOUT_MS = 5000;\n\n constructor(config: WorkerTransportConfig) {\n this.config = config;\n this.bufferSize = config.bufferSize ?? 1000;\n this.maxRestarts = config.maxRestarts ?? 3;\n this.level = config.level;\n protectSecrets(this, ['config']);\n this.startWorker();\n }\n\n private startWorker(): void {\n try {\n this.worker = new Worker(this.workerFile(), {\n workerData: {\n transportType: this.config.transportType,\n transportConfig: this.config.transportConfig,\n levels: this.config.levels,\n },\n });\n\n this.worker.on('message', (msg: { type: string; error?: string }) => {\n if (msg.type === 'ready') {\n this.ready = true;\n this.drainBuffer();\n } else if (msg.type === 'error' || msg.type === 'write-error') {\n internalError(\n `WorkerTransport [${this.config.transportType}]: ${msg.error ?? 'unknown'}`\n );\n }\n });\n\n this.worker.on('error', (err) => {\n internalError('WorkerTransport worker error', err);\n this.handleWorkerExit();\n });\n\n this.worker.on('exit', (code) => {\n if (code !== 0) {\n internalWarn(`WorkerTransport worker exited with code ${code}`);\n this.handleWorkerExit();\n }\n });\n } catch (err) {\n internalError('WorkerTransport failed to start', err);\n }\n }\n\n /** The worker entry is always built as CommonJS, next to this module's output. */\n protected workerFile(): string {\n return path.join(__dirname, 'worker-entry.js');\n }\n\n private handleWorkerExit(): void {\n this.ready = false;\n // Don't resurrect a worker we're intentionally shutting down — close() sets\n // `closing` and nulls the worker, so a late 'exit'/'error' event must not\n // queue a restart (which would spawn a fresh leaked thread post-shutdown).\n if (this.closing) return;\n if (this.restarts < this.maxRestarts) {\n this.restarts++;\n internalWarn(`WorkerTransport restarting (attempt ${this.restarts}/${this.maxRestarts})`);\n // Small backoff before restart. unref() so a perpetually-failing worker's\n // pending restart never keeps the process alive on its own.\n this.restartTimer = setTimeout(() => {\n this.restartTimer = null;\n this.startWorker();\n }, 500 * this.restarts);\n if (this.restartTimer.unref) this.restartTimer.unref();\n } else {\n internalError(\n `WorkerTransport exhausted ${this.maxRestarts} restart attempts — transport disabled`\n );\n }\n }\n\n private drainBuffer(): void {\n while (this.buffer.length > 0 && this.ready && this.worker) {\n const entry = this.buffer.shift();\n if (entry) {\n this.worker.postMessage({ type: 'write', entry });\n }\n }\n }\n\n write(entry: TransportLogEntry): void {\n if (this.ready && this.worker) {\n this.worker.postMessage({ type: 'write', entry });\n } else {\n if (this.buffer.length >= this.bufferSize) {\n internalWarn('WorkerTransport buffer full — dropping oldest entry');\n this.buffer.shift();\n }\n this.buffer.push(entry);\n }\n }\n\n async flush(): Promise<void> {\n if (!this.ready || !this.worker) return;\n const worker = this.worker;\n return new Promise<void>((resolve) => {\n // Time-box the flush: if the worker dies or restarts before answering,\n // the 'flushed' message would never arrive and this promise would hang\n // forever, blocking shutdown until the force-exit timer kills the process\n // (losing everything). Resolve on timeout so close() can still terminate.\n const timer = setTimeout(() => {\n worker.off('message', handler);\n resolve();\n }, this.FLUSH_TIMEOUT_MS);\n if (timer.unref) timer.unref();\n\n const handler = (msg: { type: string }) => {\n if (msg.type === 'flushed') {\n clearTimeout(timer);\n worker.off('message', handler);\n resolve();\n }\n };\n worker.on('message', handler);\n worker.postMessage({ type: 'flush' });\n });\n }\n\n /**\n * Flush the worker's buffer and terminate the thread on shutdown.\n *\n * This MUST be named close() — TransportManager.close() invokes\n * transport.close(), so a method named only shutdown() was never called on\n * graceful exit, leaking the worker thread and dropping its buffered logs.\n */\n async close(): Promise<void> {\n // Stop the restart loop first: cancel any queued backoff restart and flag\n // that further worker exits are expected (so handleWorkerExit no-ops).\n this.closing = true;\n if (this.restartTimer) {\n clearTimeout(this.restartTimer);\n this.restartTimer = null;\n }\n\n if (!this.worker) return;\n const worker = this.worker;\n this.worker = null;\n\n // Push any locally-buffered (pre-ready) entries first: the worker's port\n // queues them until its listener attaches, so they are handled before the\n // shutdown message, which flushes the wrapped transport and exits.\n this.drainBufferTo(worker);\n worker.postMessage({ type: 'shutdown' });\n\n await new Promise<void>((resolve) => {\n // Don't wait forever for a wedged worker — terminate() it after a timeout.\n const timer = setTimeout(() => {\n worker.terminate().finally(() => resolve());\n }, this.SHUTDOWN_TIMEOUT_MS);\n if (timer.unref) timer.unref();\n\n worker.once('exit', () => {\n clearTimeout(timer);\n resolve();\n });\n });\n }\n\n /** Back-compat alias — prefer close(). */\n async shutdown(): Promise<void> {\n await this.close();\n }\n\n private drainBufferTo(worker: Worker): void {\n while (this.buffer.length > 0) {\n const entry = this.buffer.shift();\n if (entry) worker.postMessage({ type: 'write', entry });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAa,kBAAb,MAAmD;CAsBjD,YAAY,QAA+B;EArBpB,KAAA,OAAA;EAEK,KAAA,YAAA;EACI,KAAA,gBAAA;EAEA,KAAA,SAAA;EAChB,KAAA,QAAA;EAC+B,KAAA,SAAA,CAAC;EAE7B,KAA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IAAI,CAAC,KAAK,QAAQ;EAClB,MAAM,SAAS,KAAK;EACpB,KAAK,SAAS;EAKd,KAAK,cAAc,MAAM;EACzB,OAAO,YAAY,EAAE,MAAM,WAAW,CAAC;EAEvC,MAAM,IAAI,SAAe,YAAY;GAEnC,MAAM,QAAQ,iBAAiB;IAC7B,OAAO,UAAU,CAAC,CAAC,cAAc,QAAQ,CAAC;GAC5C,GAAG,KAAK,mBAAmB;GAC3B,IAAI,MAAM,OAAO,MAAM,MAAM;GAE7B,OAAO,KAAK,cAAc;IACxB,aAAa,KAAK;IAClB,QAAQ;GACV,CAAC;EACH,CAAC;CACH;;CAGA,MAAM,WAA0B;EAC9B,MAAM,KAAK,MAAM;CACnB;CAEA,cAAsB,QAAsB;EAC1C,OAAO,KAAK,OAAO,SAAS,GAAG;GAC7B,MAAM,QAAQ,KAAK,OAAO,MAAM;GAChC,IAAI,OAAO,OAAO,YAAY;IAAE,MAAM;IAAS;GAAM,CAAC;EACxD;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "logixia",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "Async-first TypeScript logger
|
|
3
|
+
"version": "2.0.6",
|
|
4
|
+
"description": "Async-first TypeScript logger for Node, NestJS and the edge: request tracing, redaction, OpenTelemetry/OTLP export, file/database/cloud transports, sampling and log search. Winston/Pino alternative.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -151,6 +151,8 @@
|
|
|
151
151
|
"format:check": "prettier --check .",
|
|
152
152
|
"typecheck": "tsc --noEmit",
|
|
153
153
|
"typecheck:examples": "tsc -p tsconfig.examples.json && tsc -p examples/cloudflare-worker/tsconfig.json",
|
|
154
|
+
"typecheck:consumer": "npm run build && tsc -p tests/consumer/tsconfig.json",
|
|
155
|
+
"typecheck:express4": "node scripts/typecheck-express4.mjs",
|
|
154
156
|
"check": "npm run typecheck && npm run lint:check",
|
|
155
157
|
"ci": "npm run typecheck && npm run lint:check && npm run test:ci",
|
|
156
158
|
"validate": "npm run clean && npm run build && npm run typecheck && npm run lint:check && npm run test:coverage",
|
|
@@ -165,8 +167,10 @@
|
|
|
165
167
|
"dev:performance": "ts-node -P tsconfig.examples.json --transpile-only -r ./examples/register.js examples/performance-monitoring.ts",
|
|
166
168
|
"dev:fields": "ts-node -P tsconfig.examples.json --transpile-only -r ./examples/register.js examples/field-configuration.ts",
|
|
167
169
|
"dev:search": "ts-node -P tsconfig.examples.json --transpile-only -r ./examples/register.js examples/search-quickstart.ts",
|
|
170
|
+
"dev:search-readme": "ts-node -P tsconfig.examples.json --transpile-only -r ./examples/register.js examples/search-readme.ts",
|
|
168
171
|
"dev:intelligent-search": "ts-node -P tsconfig.examples.json --transpile-only -r ./examples/register.js examples/intelligent-search.ts",
|
|
169
172
|
"benchmark": "npm run build && node benchmarks/run.mjs",
|
|
173
|
+
"check:browser": "node --experimental-vm-modules --no-warnings scripts/check-browser-entry.mjs",
|
|
170
174
|
"check:exports": "node scripts/check-exports.mjs",
|
|
171
175
|
"check:optional-peers": "node scripts/check-optional-peers.mjs",
|
|
172
176
|
"size": "size-limit",
|
|
@@ -178,81 +182,41 @@
|
|
|
178
182
|
"logging",
|
|
179
183
|
"typescript",
|
|
180
184
|
"typescript-logger",
|
|
185
|
+
"structured-logging",
|
|
186
|
+
"json-logging",
|
|
181
187
|
"nestjs",
|
|
182
188
|
"nestjs-logger",
|
|
183
|
-
"nestjs-logging",
|
|
184
|
-
"nestjs-module",
|
|
185
189
|
"winston-alternative",
|
|
186
190
|
"pino-alternative",
|
|
187
|
-
"
|
|
188
|
-
"json-logging",
|
|
189
|
-
"custom-log-levels",
|
|
190
|
-
"log-levels",
|
|
191
|
-
"request-tracing",
|
|
191
|
+
"request-id",
|
|
192
192
|
"trace-id",
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
"multi-transport",
|
|
196
|
-
"console-transport",
|
|
197
|
-
"file-transport",
|
|
198
|
-
"log-rotation",
|
|
199
|
-
"database-logging",
|
|
200
|
-
"mongodb-logger",
|
|
201
|
-
"postgresql-logger",
|
|
202
|
-
"analytics-logging",
|
|
203
|
-
"datadog",
|
|
204
|
-
"mixpanel",
|
|
205
|
-
"segment",
|
|
206
|
-
"log-search",
|
|
207
|
-
"log-analysis",
|
|
208
|
-
"log-aggregation",
|
|
209
|
-
"nodejs",
|
|
210
|
-
"bun",
|
|
211
|
-
"express",
|
|
212
|
-
"microservices",
|
|
193
|
+
"request-tracing",
|
|
194
|
+
"correlation-id",
|
|
213
195
|
"distributed-tracing",
|
|
214
|
-
"
|
|
215
|
-
"developer-tools",
|
|
216
|
-
"enterprise-logging",
|
|
217
|
-
"wide-events",
|
|
218
|
-
"canonical-log-lines",
|
|
219
|
-
"observability-2.0",
|
|
196
|
+
"opentelemetry",
|
|
220
197
|
"otlp",
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
"otel-logs",
|
|
224
|
-
"log-correlation",
|
|
225
|
-
"trace-log-correlation",
|
|
226
|
-
"log-redaction",
|
|
198
|
+
"w3c-trace-context",
|
|
199
|
+
"redaction",
|
|
227
200
|
"pii-redaction",
|
|
228
|
-
"secret-redaction",
|
|
229
201
|
"log-sampling",
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
"
|
|
233
|
-
"
|
|
234
|
-
"
|
|
235
|
-
"
|
|
236
|
-
"
|
|
237
|
-
"
|
|
202
|
+
"log-levels",
|
|
203
|
+
"wide-events",
|
|
204
|
+
"express",
|
|
205
|
+
"fastify",
|
|
206
|
+
"cloudflare-workers",
|
|
207
|
+
"edge",
|
|
208
|
+
"browser-logger",
|
|
209
|
+
"datadog",
|
|
238
210
|
"cloudwatch",
|
|
239
211
|
"gcp-logging",
|
|
240
212
|
"azure-monitor",
|
|
241
|
-
"
|
|
242
|
-
"
|
|
243
|
-
"
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"non-blocking-logger",
|
|
249
|
-
"fast-logger",
|
|
250
|
-
"high-performance-logging",
|
|
251
|
-
"log-management",
|
|
252
|
-
"structured-logs",
|
|
253
|
-
"json-logger",
|
|
254
|
-
"typescript-logging",
|
|
255
|
-
"bunyan-alternative"
|
|
213
|
+
"slack",
|
|
214
|
+
"discord",
|
|
215
|
+
"database-logging",
|
|
216
|
+
"log-rotation",
|
|
217
|
+
"log-search",
|
|
218
|
+
"prometheus",
|
|
219
|
+
"observability"
|
|
256
220
|
],
|
|
257
221
|
"author": {
|
|
258
222
|
"name": "Sanjeev Sharma",
|
|
@@ -281,6 +245,7 @@
|
|
|
281
245
|
],
|
|
282
246
|
"peerDependencies": {
|
|
283
247
|
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
248
|
+
"@opentelemetry/api": "^1.0.0",
|
|
284
249
|
"express": "^4.0.0 || ^5.0.0",
|
|
285
250
|
"reflect-metadata": "^0.1.13 || ^0.2.0"
|
|
286
251
|
},
|
|
@@ -288,6 +253,9 @@
|
|
|
288
253
|
"@nestjs/common": {
|
|
289
254
|
"optional": true
|
|
290
255
|
},
|
|
256
|
+
"@opentelemetry/api": {
|
|
257
|
+
"optional": true
|
|
258
|
+
},
|
|
291
259
|
"express": {
|
|
292
260
|
"optional": true
|
|
293
261
|
},
|
|
@@ -307,22 +275,24 @@
|
|
|
307
275
|
"@nestjs/platform-express": "^11.1.17",
|
|
308
276
|
"@nestjs/platform-socket.io": "^11.1.17",
|
|
309
277
|
"@nestjs/websockets": "^11.1.17",
|
|
278
|
+
"@opentelemetry/api": "1.9.1",
|
|
279
|
+
"@opentelemetry/context-async-hooks": "3.0.0",
|
|
280
|
+
"@opentelemetry/sdk-trace-base": "2.12.0",
|
|
310
281
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
311
282
|
"@semantic-release/github": "12.0.10",
|
|
312
283
|
"@semantic-release/npm": "13.2.0",
|
|
313
284
|
"@semantic-release/release-notes-generator": "14.1.1",
|
|
314
|
-
"@size-limit/file": "^
|
|
315
|
-
"@types/express": "^
|
|
285
|
+
"@size-limit/file": "^14.3.0",
|
|
286
|
+
"@types/express": "^5.0.6",
|
|
316
287
|
"@types/jest": "^30.0.0",
|
|
317
|
-
"@types/node": "^20.
|
|
288
|
+
"@types/node": "^20.19.43",
|
|
318
289
|
"@types/pg": "^8.15.5",
|
|
319
|
-
"@types/pino": "^7.0.4",
|
|
320
290
|
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
321
291
|
"eslint": "^10.0.3",
|
|
322
292
|
"eslint-config-prettier": "^10.1.8",
|
|
323
|
-
"eslint-plugin-simple-import-sort": "^
|
|
324
|
-
"eslint-plugin-sonarjs": "4.2.
|
|
325
|
-
"eslint-plugin-unicorn": "^
|
|
293
|
+
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
294
|
+
"eslint-plugin-sonarjs": "^4.2.2",
|
|
295
|
+
"eslint-plugin-unicorn": "^78.0.0",
|
|
326
296
|
"express": "^5.2.1",
|
|
327
297
|
"fastify": "^5.12.7",
|
|
328
298
|
"globals": "^17.4.0",
|
|
@@ -338,20 +308,26 @@
|
|
|
338
308
|
"prettier": "^3.8.1",
|
|
339
309
|
"reflect-metadata": "^0.2.2",
|
|
340
310
|
"semantic-release": "25.0.9",
|
|
341
|
-
"size-limit": "^
|
|
311
|
+
"size-limit": "^14.3.0",
|
|
342
312
|
"socket.io": "^4.8.3",
|
|
343
313
|
"tinybench": "^6.0.0",
|
|
344
314
|
"ts-jest": "^29.0.0",
|
|
345
315
|
"ts-node": "^10.9.2",
|
|
346
|
-
"tsdown": "^0.
|
|
316
|
+
"tsdown": "^0.23.1",
|
|
347
317
|
"typescript": "^5.0.0",
|
|
348
318
|
"typescript-eslint": "^8.57.0",
|
|
349
|
-
"uuid": "^11.1.1",
|
|
350
319
|
"winston": "^3.19.0"
|
|
351
320
|
},
|
|
352
321
|
"engines": {
|
|
353
322
|
"node": ">=16.0.0"
|
|
354
323
|
},
|
|
324
|
+
"devEngines": {
|
|
325
|
+
"runtime": {
|
|
326
|
+
"name": "node",
|
|
327
|
+
"version": "^22.19.0 || ^24.11.0 || >=26.0.0",
|
|
328
|
+
"onFail": "warn"
|
|
329
|
+
}
|
|
330
|
+
},
|
|
355
331
|
"bin": {
|
|
356
332
|
"logixia": "./dist/cli/index.js"
|
|
357
333
|
},
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { d as sanitizeIncomingId } from "./trace.utils-CvXgaiQT.mjs";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
|
|
5
|
-
//#region src/context/async-context.ts
|
|
6
|
-
/** Generates an 8-character random ID using Node's crypto module. */
|
|
7
|
-
function randomShortId() {
|
|
8
|
-
return randomUUID().slice(0, 8);
|
|
9
|
-
}
|
|
10
|
-
const _storage = new AsyncLocalStorage();
|
|
11
|
-
const LogixiaContext = {
|
|
12
|
-
run(store, callback) {
|
|
13
|
-
const parent = _storage.getStore() ?? {};
|
|
14
|
-
return _storage.run({
|
|
15
|
-
...parent,
|
|
16
|
-
...store
|
|
17
|
-
}, callback);
|
|
18
|
-
},
|
|
19
|
-
get() {
|
|
20
|
-
return _storage.getStore();
|
|
21
|
-
},
|
|
22
|
-
set(fields) {
|
|
23
|
-
const store = _storage.getStore();
|
|
24
|
-
if (!store) return;
|
|
25
|
-
for (const key of Object.keys(fields)) {
|
|
26
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
27
|
-
store[key] = fields[key];
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
getStorage() {
|
|
31
|
-
return _storage;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Create an Express/Connect-compatible middleware that wraps each request in
|
|
36
|
-
* a `LogixiaContext.run()` scope populated with common request fields.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { createExpressContextMiddleware } from 'logixia';
|
|
41
|
-
* app.use(createExpressContextMiddleware());
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
function createExpressContextMiddleware(options = {}) {
|
|
45
|
-
const { enrich, traceIdHeader = "x-trace-id" } = options;
|
|
46
|
-
return function logixiaContextMiddleware(req, _res, next) {
|
|
47
|
-
const base = { traceId: sanitizeIncomingId((req["headers"] ?? {})[traceIdHeader.toLowerCase()]) ?? randomShortId() };
|
|
48
|
-
LogixiaContext.run({
|
|
49
|
-
...base,
|
|
50
|
-
...enrich ? enrich(req) : {}
|
|
51
|
-
}, next);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create a Fastify lifecycle hook that wraps each request in a context scope.
|
|
56
|
-
*
|
|
57
|
-
* Register with `fastify.addHook('onRequest', createFastifyContextHook())`.
|
|
58
|
-
*/
|
|
59
|
-
function createFastifyContextHook(options = {}) {
|
|
60
|
-
const { enrich, traceIdHeader = "x-trace-id" } = options;
|
|
61
|
-
return function logixiaFastifyHook(request, _reply, done) {
|
|
62
|
-
const base = { traceId: sanitizeIncomingId((request["headers"] ?? {})[traceIdHeader.toLowerCase()]) ?? sanitizeIncomingId(request["id"]) ?? randomShortId() };
|
|
63
|
-
LogixiaContext.run({
|
|
64
|
-
...base,
|
|
65
|
-
...enrich ? enrich(request) : {}
|
|
66
|
-
}, done);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
|
-
export { createExpressContextMiddleware as n, createFastifyContextHook as r, LogixiaContext as t };
|
|
72
|
-
//# sourceMappingURL=async-context-BzJrbfQs.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-context-BzJrbfQs.mjs","names":["base: LogContext"],"sources":["../src/context/async-context.ts"],"sourcesContent":["/**\n * LogixiaContext — Zero-boilerplate AsyncLocalStorage context propagation.\n *\n * Lets every `logger.info()` call inside a context automatically pick up stored\n * fields (requestId, userId, tenantId, …) without passing them through every function.\n *\n * Works across `Promise.all`, `setTimeout`, and event emitters — anything that\n * inherits the async execution context.\n *\n * @example\n * ```ts\n * import { LogixiaContext } from 'logixia';\n *\n * // Wrap a request handler:\n * app.use((req, res, next) => {\n * LogixiaContext.run({ requestId: req.id, userId: req.user?.id }, next);\n * });\n *\n * // Anywhere deeper in the call tree:\n * async function processOrder(orderId: string) {\n * const ctx = LogixiaContext.get(); // { requestId, userId, orderId }\n * logger.info('Processing order', { orderId, ...ctx });\n * }\n * ```\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { randomUUID } from 'node:crypto';\n\nimport { sanitizeIncomingId } from '../utils/trace.utils';\n\n/** Generates an 8-character random ID using Node's crypto module. */\nfunction randomShortId(): string {\n return randomUUID().slice(0, 8);\n}\n\nexport interface LogContext {\n traceId?: string;\n spanId?: string;\n userId?: string;\n tenantId?: string;\n sessionId?: string;\n [key: string]: unknown;\n}\n\n// Module-level singleton so all loggers share the same ALS store.\nconst _storage = new AsyncLocalStorage<LogContext>();\n\nexport const LogixiaContext = {\n /**\n * Run `callback` inside an async context that carries `store` fields.\n * All loggers queried within `callback` (and its async descendants) will\n * automatically see these fields.\n *\n * @example\n * ```ts\n * LogixiaContext.run({ requestId: 'abc', userId: '42' }, async () => {\n * await processOrder(); // sees requestId + userId in every log\n * });\n * ```\n */\n run<T>(store: LogContext, callback: () => T): T {\n const parent = _storage.getStore() ?? {};\n return _storage.run({ ...parent, ...store }, callback);\n },\n\n /**\n * Return the context fields active in the current async scope.\n * Returns `undefined` when called outside any `LogixiaContext.run()`.\n */\n get(): LogContext | undefined {\n return _storage.getStore();\n },\n\n /**\n * Merge `fields` into the **existing** context for the current scope.\n * If called outside a `run()` context this is a no-op (logs a dev warning).\n */\n set(fields: Partial<LogContext>): void {\n const store = _storage.getStore();\n if (!store) {\n // Silently ignore — avoids crashing in code that may call setContext\n // before a request context is established (e.g. background jobs).\n return;\n }\n for (const key of Object.keys(fields)) {\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n store[key] = fields[key];\n }\n },\n\n /**\n * Retrieve the underlying `AsyncLocalStorage` instance.\n * Useful for advanced use-cases like custom middleware.\n */\n getStorage(): AsyncLocalStorage<LogContext> {\n return _storage;\n },\n};\n\n/**\n * Create an Express/Connect-compatible middleware that wraps each request in\n * a `LogixiaContext.run()` scope populated with common request fields.\n *\n * @example\n * ```ts\n * import { createExpressContextMiddleware } from 'logixia';\n * app.use(createExpressContextMiddleware());\n * ```\n */\nexport function createExpressContextMiddleware(\n options: {\n /** Extract additional fields from the request. */\n enrich?: (req: Record<string, unknown>) => Partial<LogContext>;\n /** Header to read the traceId from. Default: 'x-trace-id'. */\n traceIdHeader?: string;\n } = {}\n) {\n const { enrich, traceIdHeader = 'x-trace-id' } = options;\n\n return function logixiaContextMiddleware(\n req: Record<string, unknown>,\n _res: unknown,\n next: () => void\n ): void {\n const headers = (req['headers'] ?? {}) as Record<string, string | undefined>;\n const traceId = sanitizeIncomingId(headers[traceIdHeader.toLowerCase()]) ?? randomShortId();\n const base: LogContext = { traceId };\n LogixiaContext.run({ ...base, ...(enrich ? enrich(req) : {}) }, next);\n };\n}\n\n/**\n * Create a Fastify lifecycle hook that wraps each request in a context scope.\n *\n * Register with `fastify.addHook('onRequest', createFastifyContextHook())`.\n */\nexport function createFastifyContextHook(\n options: {\n enrich?: (request: Record<string, unknown>) => Partial<LogContext>;\n traceIdHeader?: string;\n } = {}\n) {\n const { enrich, traceIdHeader = 'x-trace-id' } = options;\n\n return function logixiaFastifyHook(\n request: Record<string, unknown>,\n _reply: unknown,\n done: () => void\n ): void {\n const headers = (request['headers'] ?? {}) as Record<string, string | undefined>;\n const traceId =\n sanitizeIncomingId(headers[traceIdHeader.toLowerCase()]) ??\n sanitizeIncomingId(request['id']) ??\n randomShortId();\n const base: LogContext = { traceId };\n LogixiaContext.run({ ...base, ...(enrich ?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