logixia 2.0.4 → 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 -2614
- package/dist/{async-context-B05ArHgM.mjs → async-context-2mbUKhcl.mjs} +4 -6
- package/dist/async-context-2mbUKhcl.mjs.map +1 -0
- package/dist/{async-context-DTQgi8f7.js → async-context-DUFMDYAr.js} +4 -6
- package/dist/async-context-DUFMDYAr.js.map +1 -0
- package/dist/{azure-monitor.transport-CwbOLZHB.js → azure-monitor.transport-Bu4S2I2q.js} +5 -5
- package/dist/azure-monitor.transport-Bu4S2I2q.js.map +1 -0
- package/dist/{azure-monitor.transport-DV03Z5P4.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts} +2 -2
- package/dist/{azure-monitor.transport-DV03Z5P4.d.ts.map → azure-monitor.transport-Bvf7Xegt.d.ts.map} +1 -1
- package/dist/{azure-monitor.transport-BPbgjATu.mjs → azure-monitor.transport-C1RWAumT.mjs} +5 -5
- package/dist/azure-monitor.transport-C1RWAumT.mjs.map +1 -0
- package/dist/{azure-monitor.transport-C7kYyZUW.d.mts → azure-monitor.transport-CbSHOnNX.d.mts} +2 -2
- package/dist/{azure-monitor.transport-C7kYyZUW.d.mts.map → azure-monitor.transport-CbSHOnNX.d.mts.map} +1 -1
- package/dist/azure.d.mts +1 -1
- package/dist/azure.d.ts +1 -1
- package/dist/azure.js +1 -1
- package/dist/azure.mjs +1 -1
- package/dist/{batch-buffer-0fgLmIPn.mjs → batch-buffer-BvXLDPlV.mjs} +3 -3
- package/dist/{batch-buffer-0fgLmIPn.mjs.map → batch-buffer-BvXLDPlV.mjs.map} +1 -1
- package/dist/{batch-buffer-DT4gdXmf.js → batch-buffer-C7Am4Mw-.js} +3 -3
- package/dist/{batch-buffer-DT4gdXmf.js.map → batch-buffer-C7Am4Mw-.js.map} +1 -1
- package/dist/browser.d.mts +5 -5
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +5 -5
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +47 -12
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +47 -12
- package/dist/browser.mjs.map +1 -1
- package/dist/{builder-D70z6kjj.mjs → builder-DhNhvOkt.mjs} +106 -153
- package/dist/builder-DhNhvOkt.mjs.map +1 -0
- package/dist/{builder-M7NoaugM.js → builder-yFvJrz7o.js} +109 -179
- package/dist/builder-yFvJrz7o.js.map +1 -0
- package/dist/cli/index.js +157 -66
- package/dist/cloudwatch.d.mts +1 -1
- package/dist/cloudwatch.d.ts +1 -1
- package/dist/cloudwatch.js +1 -1
- package/dist/cloudwatch.mjs +1 -1
- package/dist/{cloudwatch.transport-Bf7L4I59.d.ts → cloudwatch.transport-CQyT6U91.d.ts} +2 -2
- package/dist/{cloudwatch.transport-Bf7L4I59.d.ts.map → cloudwatch.transport-CQyT6U91.d.ts.map} +1 -1
- package/dist/{cloudwatch.transport-B2wKQFF7.js → cloudwatch.transport-Ch1Uae-0.js} +6 -6
- package/dist/cloudwatch.transport-Ch1Uae-0.js.map +1 -0
- package/dist/{cloudwatch.transport-Rj4yTpRn.d.mts → cloudwatch.transport-CjVrI6S4.d.mts} +2 -2
- package/dist/{cloudwatch.transport-Rj4yTpRn.d.mts.map → cloudwatch.transport-CjVrI6S4.d.mts.map} +1 -1
- package/dist/{cloudwatch.transport-BTvYfLs9.mjs → cloudwatch.transport-DZqF2xZO.mjs} +6 -6
- package/dist/cloudwatch.transport-DZqF2xZO.mjs.map +1 -0
- package/dist/correlation.d.mts +4 -55
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +4 -55
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +13 -13
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +13 -13
- package/dist/correlation.mjs.map +1 -1
- package/dist/{entry-fields-RLd1jCoR.js → entry-fields-BSLkzw18.js} +8 -3
- package/dist/entry-fields-BSLkzw18.js.map +1 -0
- package/dist/{entry-fields-CGuvT2R0.mjs → entry-fields-J1OBi24o.mjs} +8 -3
- package/dist/entry-fields-J1OBi24o.mjs.map +1 -0
- package/dist/gcp.d.mts +1 -1
- package/dist/gcp.d.ts +1 -1
- package/dist/gcp.js +1 -1
- package/dist/gcp.mjs +1 -1
- package/dist/{gcp.transport-CFQfdAOK.d.ts → gcp.transport-BCIvdFV-.d.ts} +4 -4
- package/dist/{gcp.transport-CFQfdAOK.d.ts.map → gcp.transport-BCIvdFV-.d.ts.map} +1 -1
- package/dist/{gcp.transport-C5D72b1g.d.mts → gcp.transport-D9SdLPwP.d.mts} +4 -4
- package/dist/{gcp.transport-C5D72b1g.d.mts.map → gcp.transport-D9SdLPwP.d.mts.map} +1 -1
- package/dist/{gcp.transport-CGKopAhQ.mjs → gcp.transport-DVCmnA3b.mjs} +20 -16
- package/dist/gcp.transport-DVCmnA3b.mjs.map +1 -0
- package/dist/{gcp.transport-KZe9hCAR.js → gcp.transport-Dy2Lf8FI.js} +20 -16
- 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-xqaJtAZn.d.mts → index-BSTtFcQ6.d.mts} +142 -8
- package/dist/index-BSTtFcQ6.d.mts.map +1 -0
- package/dist/{index-DwozbmB4.d.ts → index-CFDGkI8n.d.ts} +142 -8
- package/dist/index-CFDGkI8n.d.ts.map +1 -0
- package/dist/index.d.mts +21 -65
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +21 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -21
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-log-uCSd1PMc.mjs → internal-log-Bg4V1cPg.mjs} +30 -2
- package/dist/internal-log-Bg4V1cPg.mjs.map +1 -0
- package/dist/{internal-log-b0Vp4qrB.js → internal-log-By4Govmu.js} +41 -1
- package/dist/internal-log-By4Govmu.js.map +1 -0
- package/dist/{logitron-logger-D2B75Oc7.d.ts → logitron-logger-D22Yb61K.d.mts} +13 -100
- package/dist/logitron-logger-D22Yb61K.d.mts.map +1 -0
- package/dist/{logitron-logger-oEd6wNhf.d.mts → logitron-logger-D_MYYrQt.d.ts} +13 -100
- package/dist/logitron-logger-D_MYYrQt.d.ts.map +1 -0
- package/dist/middleware.d.mts +4 -17
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +4 -17
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +9 -39
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +7 -37
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +14 -7
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +14 -7
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +15 -10
- package/dist/nest.js.map +1 -1
- package/dist/nest.mjs +15 -10
- package/dist/nest.mjs.map +1 -1
- package/dist/{transport.manager-eZ_EeC00.mjs → otel-Dt5riXuE.mjs} +173 -24
- package/dist/otel-Dt5riXuE.mjs.map +1 -0
- package/dist/{transport.manager-DkcEOlqV.js → otel-DyeH6DVR.js} +214 -23
- 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/{request-trace-C_fvIDv4.mjs → request-trace-BgNykH9M.mjs} +1 -5
- package/dist/{request-trace-C_fvIDv4.mjs.map → request-trace-BgNykH9M.mjs.map} +1 -1
- package/dist/{request-trace-wTJdKp6-.js → request-trace-ByujsUZk.js} +1 -5
- package/dist/{request-trace-wTJdKp6-.js.map → request-trace-ByujsUZk.js.map} +1 -1
- package/dist/{safe-stringify-BMRl3EX3.mjs → safe-stringify-B5p5ktFe.mjs} +37 -12
- package/dist/safe-stringify-B5p5ktFe.mjs.map +1 -0
- package/dist/{safe-stringify-DLz1Kz3o.js → safe-stringify-J3sh-7YM.js} +37 -12
- package/dist/safe-stringify-J3sh-7YM.js.map +1 -0
- package/dist/{search-DUfWuzFP.js → search-CRjhHxe9.js} +269 -25
- package/dist/search-CRjhHxe9.js.map +1 -0
- package/dist/{search-CazwyX5Z.d.ts → search-DA3ft3X5.d.mts} +5 -2
- package/dist/search-DA3ft3X5.d.mts.map +1 -0
- package/dist/{search-CWMVYC-R.mjs → search-DAXKE-P9.mjs} +269 -25
- package/dist/search-DAXKE-P9.mjs.map +1 -0
- package/dist/{search-BH33XhuU.d.mts → search-DEl3Pe47.d.ts} +5 -2
- package/dist/search-DEl3Pe47.d.ts.map +1 -0
- package/dist/search.d.mts +1 -1
- package/dist/search.d.ts +1 -1
- package/dist/search.js +1 -1
- package/dist/search.mjs +1 -1
- package/dist/{secret-config-CBZBs0p1.js → secret-config-CmK2wVkr.js} +6 -5
- package/dist/secret-config-CmK2wVkr.js.map +1 -0
- package/dist/{secret-config-BegMLkYl.mjs → secret-config-Dhb6pqTU.mjs} +6 -5
- package/dist/secret-config-Dhb6pqTU.mjs.map +1 -0
- package/dist/{slack.transport-DxHOXlLu.d.mts → slack.transport-BDyENuR0.d.mts} +2 -2
- package/dist/{slack.transport-DxHOXlLu.d.mts.map → slack.transport-BDyENuR0.d.mts.map} +1 -1
- package/dist/{slack.transport-Ce96JBDk.mjs → slack.transport-BTEwsREY.mjs} +66 -15
- package/dist/slack.transport-BTEwsREY.mjs.map +1 -0
- package/dist/{slack.transport-DrirgDNy.d.ts → slack.transport-C6E0l4kw.d.ts} +2 -2
- package/dist/{slack.transport-DrirgDNy.d.ts.map → slack.transport-C6E0l4kw.d.ts.map} +1 -1
- package/dist/{slack.transport-Dlx3xvb7.js → slack.transport-UbYvOdKx.js} +67 -16
- package/dist/slack.transport-UbYvOdKx.js.map +1 -0
- package/dist/testing.d.mts +11 -4
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.d.ts +11 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +38 -3
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +38 -3
- package/dist/testing.mjs.map +1 -1
- package/dist/{transport.types-BJVL1QQl.d.ts → transport.types-CzJq4IrF.d.mts} +14 -3
- package/dist/transport.types-CzJq4IrF.d.mts.map +1 -0
- package/dist/{transport.types-BJVL1QQl.d.mts → transport.types-CzJq4IrF.d.ts} +14 -3
- package/dist/transport.types-CzJq4IrF.d.ts.map +1 -0
- package/dist/transports.d.mts +25 -13
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +25 -13
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +15 -15
- package/dist/transports.mjs +6 -6
- package/dist/worker-entry.js +105 -24
- package/dist/worker.d.mts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +1 -1
- package/dist/{worker.transport-BuPwBi3d.d.ts → worker.transport-B9mCQSM1.d.ts} +7 -2
- package/dist/worker.transport-B9mCQSM1.d.ts.map +1 -0
- package/dist/{worker.transport-hJay1wxA.d.mts → worker.transport-Bl8lFRck.d.mts} +7 -2
- package/dist/worker.transport-Bl8lFRck.d.mts.map +1 -0
- package/dist/{worker.transport-DLVA4y2e.mjs → worker.transport-BmmOKb1-.mjs} +13 -10
- package/dist/worker.transport-BmmOKb1-.mjs.map +1 -0
- package/dist/{worker.transport-C6GNl_r2.js → worker.transport-DxxbqQCG.js} +13 -10
- package/dist/worker.transport-DxxbqQCG.js.map +1 -0
- package/package.json +33 -65
- package/dist/async-context-B05ArHgM.mjs.map +0 -1
- package/dist/async-context-DTQgi8f7.js.map +0 -1
- package/dist/azure-monitor.transport-BPbgjATu.mjs.map +0 -1
- package/dist/azure-monitor.transport-CwbOLZHB.js.map +0 -1
- package/dist/builder-D70z6kjj.mjs.map +0 -1
- package/dist/builder-M7NoaugM.js.map +0 -1
- package/dist/cloudwatch.transport-B2wKQFF7.js.map +0 -1
- package/dist/cloudwatch.transport-BTvYfLs9.mjs.map +0 -1
- package/dist/entry-fields-CGuvT2R0.mjs.map +0 -1
- package/dist/entry-fields-RLd1jCoR.js.map +0 -1
- package/dist/gcp.transport-CGKopAhQ.mjs.map +0 -1
- package/dist/gcp.transport-KZe9hCAR.js.map +0 -1
- package/dist/index-DwozbmB4.d.ts.map +0 -1
- package/dist/index-xqaJtAZn.d.mts.map +0 -1
- package/dist/internal-log-b0Vp4qrB.js.map +0 -1
- package/dist/internal-log-uCSd1PMc.mjs.map +0 -1
- package/dist/logitron-logger-D2B75Oc7.d.ts.map +0 -1
- package/dist/logitron-logger-oEd6wNhf.d.mts.map +0 -1
- package/dist/safe-stringify-BMRl3EX3.mjs.map +0 -1
- package/dist/safe-stringify-DLz1Kz3o.js.map +0 -1
- package/dist/search-BH33XhuU.d.mts.map +0 -1
- package/dist/search-CWMVYC-R.mjs.map +0 -1
- package/dist/search-CazwyX5Z.d.ts.map +0 -1
- package/dist/search-DUfWuzFP.js.map +0 -1
- package/dist/secret-config-BegMLkYl.mjs.map +0 -1
- package/dist/secret-config-CBZBs0p1.js.map +0 -1
- package/dist/slack.transport-Ce96JBDk.mjs.map +0 -1
- package/dist/slack.transport-Dlx3xvb7.js.map +0 -1
- package/dist/transport.manager-DkcEOlqV.js.map +0 -1
- package/dist/transport.manager-eZ_EeC00.mjs.map +0 -1
- package/dist/transport.types-BJVL1QQl.d.mts.map +0 -1
- package/dist/transport.types-BJVL1QQl.d.ts.map +0 -1
- package/dist/worker.transport-BuPwBi3d.d.ts.map +0 -1
- package/dist/worker.transport-C6GNl_r2.js.map +0 -1
- package/dist/worker.transport-DLVA4y2e.mjs.map +0 -1
- package/dist/worker.transport-hJay1wxA.d.mts.map +0 -1
package/dist/transports.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { t as AzureMonitorTransport } from "./azure-monitor.transport-
|
|
3
|
-
import { t as CloudWatchTransport } from "./cloudwatch.transport-
|
|
4
|
-
import { n as GCPTransport } from "./gcp.transport-
|
|
5
|
-
import {
|
|
6
|
-
import { a as DiscordTransport, c as OtlpLogTransportConfig, i as DiscordEmbed, l as toOtelSeverity, n as SlackTransport, o as DiscordTransportConfig, r as SlackTransportConfig, s as OtlpLogTransport, t as SlackMessage } from "./slack.transport-
|
|
7
|
-
import { t as WorkerTransport } from "./worker.transport-
|
|
1
|
+
import { _ as TransportLogEntry, a as DatabaseTransportConfig, b as TransportType, c as GoogleAnalyticsTransportConfig, d as ITransport, f as MixpanelTransportConfig, g as TransportEvents, h as TransportConfig, i as DataDogTransportConfig, l as IAsyncTransport, m as SegmentTransportConfig, n as AnalyticsTransportConfig, o as FileStats, p as RotationConfig, r as ConsoleTransportConfig, s as FileTransportConfig, t as AnalyticsConfig, u as IBatchTransport, v as TransportMetrics, y as TransportRetryConfig } from "./transport.types-CzJq4IrF.js";
|
|
2
|
+
import { n as AzureMonitorTransportConfig, t as AzureMonitorTransport } from "./azure-monitor.transport-Bvf7Xegt.js";
|
|
3
|
+
import { n as CloudWatchTransportConfig, t as CloudWatchTransport } from "./cloudwatch.transport-CQyT6U91.js";
|
|
4
|
+
import { n as GCPTransport, r as GCPTransportConfig } from "./gcp.transport-BCIvdFV-.js";
|
|
5
|
+
import { g as LogEntry } from "./index-CFDGkI8n.js";
|
|
6
|
+
import { a as DiscordTransport, c as OtlpLogTransportConfig, i as DiscordEmbed, l as toOtelSeverity, n as SlackTransport, o as DiscordTransportConfig, r as SlackTransportConfig, s as OtlpLogTransport, t as SlackMessage } from "./slack.transport-C6E0l4kw.js";
|
|
7
|
+
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-B9mCQSM1.js";
|
|
8
8
|
import { EventEmitter } from "node:events";
|
|
9
9
|
export declare abstract class AnalyticsTransport implements ITransport, IBatchTransport {
|
|
10
10
|
readonly name: string;
|
|
@@ -81,6 +81,7 @@ interface AnalyticsMetric {
|
|
|
81
81
|
export declare class ConsoleTransport implements ITransport {
|
|
82
82
|
private config;
|
|
83
83
|
readonly name = "console";
|
|
84
|
+
readonly level?: string | undefined;
|
|
84
85
|
readonly filter?: (entry: TransportLogEntry) => boolean;
|
|
85
86
|
private static readonly COLORS;
|
|
86
87
|
private static sanitize;
|
|
@@ -108,6 +109,7 @@ export declare class DatabaseTransport implements IAsyncTransport, IBatchTranspo
|
|
|
108
109
|
readonly name = "database";
|
|
109
110
|
readonly batchSize: number;
|
|
110
111
|
readonly flushInterval: number;
|
|
112
|
+
readonly level?: string | undefined;
|
|
111
113
|
readonly filter?: (entry: TransportLogEntry) => boolean;
|
|
112
114
|
private batch;
|
|
113
115
|
private flushTimer?;
|
|
@@ -179,8 +181,12 @@ export declare class DatabaseTransport implements IAsyncTransport, IBatchTranspo
|
|
|
179
181
|
*
|
|
180
182
|
* The API key is transmitted via the `DD-API-KEY` request header — never in the URL.
|
|
181
183
|
*
|
|
184
|
+
* Metric names keep the legacy `logitron.logs.<level>` prefix (kept for
|
|
185
|
+
* dashboards and monitors that already query it; renaming would be a breaking
|
|
186
|
+
* change). Query `logitron.logs.error`, not `logixia.logs.error`.
|
|
187
|
+
*
|
|
182
188
|
* @example
|
|
183
|
-
*
|
|
189
|
+
* analytics: { datadog: { apiKey: process.env.DD_API_KEY, service: 'api', env: 'production' } }
|
|
184
190
|
*/
|
|
185
191
|
export declare class DataDogTransport extends AnalyticsTransport {
|
|
186
192
|
private datadogConfig;
|
|
@@ -335,7 +341,7 @@ export declare class FileTransport implements ITransport, IBatchTransport {
|
|
|
335
341
|
* Sends log entries as Google Analytics 4 Measurement Protocol events.
|
|
336
342
|
*
|
|
337
343
|
* @example
|
|
338
|
-
*
|
|
344
|
+
* analytics: {
|
|
339
345
|
* googleAnalytics: { measurementId: 'G-XXXXXXX', apiSecret: process.env.GA_API_SECRET }
|
|
340
346
|
* }
|
|
341
347
|
*/
|
|
@@ -369,7 +375,7 @@ export declare class GoogleAnalyticsTransport extends AnalyticsTransport {
|
|
|
369
375
|
* Sends log entries as Mixpanel events via the Track and Engage HTTP APIs.
|
|
370
376
|
*
|
|
371
377
|
* @example
|
|
372
|
-
*
|
|
378
|
+
* analytics: { mixpanel: { token: process.env.MIXPANEL_TOKEN } }
|
|
373
379
|
*/
|
|
374
380
|
export declare class MixpanelTransport extends AnalyticsTransport {
|
|
375
381
|
private mixpanelConfig;
|
|
@@ -394,7 +400,7 @@ export declare class MixpanelTransport extends AnalyticsTransport {
|
|
|
394
400
|
* Sends log entries as Segment track/identify events via the HTTP Tracking API.
|
|
395
401
|
*
|
|
396
402
|
* @example
|
|
397
|
-
*
|
|
403
|
+
* analytics: { segment: { writeKey: process.env.SEGMENT_WRITE_KEY } }
|
|
398
404
|
*/
|
|
399
405
|
export declare class SegmentTransport extends AnalyticsTransport {
|
|
400
406
|
private segmentConfig;
|
|
@@ -428,7 +434,13 @@ export declare class TransportManager extends EventEmitter {
|
|
|
428
434
|
private isShuttingDown;
|
|
429
435
|
private transportLevelPreferences;
|
|
430
436
|
private warnedPromptDeprecated;
|
|
431
|
-
|
|
437
|
+
private readonly levelValues;
|
|
438
|
+
/**
|
|
439
|
+
* @param config Transport configuration.
|
|
440
|
+
* @param levels The logger's `levelOptions.levels`; used with the built-in levels
|
|
441
|
+
* to compare entries against each transport's `level`.
|
|
442
|
+
*/
|
|
443
|
+
constructor(config?: TransportConfig, levels?: Record<string, number>);
|
|
432
444
|
private setupTransports;
|
|
433
445
|
addTransport(transport: ITransport, id?: string): void;
|
|
434
446
|
removeTransport(id: string): boolean;
|
|
@@ -482,5 +494,5 @@ export declare class TransportManager extends EventEmitter {
|
|
|
482
494
|
getTransportLevels(transportId: string): string[] | undefined;
|
|
483
495
|
clearTransportLevelPreferences(): void;
|
|
484
496
|
}
|
|
485
|
-
export { AzureMonitorTransport, CloudWatchTransport, type DiscordEmbed, DiscordTransport, type DiscordTransportConfig, GCPTransport, OtlpLogTransport, type OtlpLogTransportConfig, type SlackMessage, SlackTransport, type SlackTransportConfig, WorkerTransport, toOtelSeverity };
|
|
497
|
+
export { type AnalyticsConfig, type AnalyticsTransportConfig, AzureMonitorTransport, type AzureMonitorTransportConfig, CloudWatchTransport, type CloudWatchTransportConfig, type ConsoleTransportConfig, type DataDogTransportConfig, type DatabaseTransportConfig, type DiscordEmbed, DiscordTransport, type DiscordTransportConfig, type FileStats, type FileTransportConfig, GCPTransport, type GCPTransportConfig, type GoogleAnalyticsTransportConfig, type IAsyncTransport, type IBatchTransport, type ITransport, type MixpanelTransportConfig, OtlpLogTransport, type OtlpLogTransportConfig, type RotationConfig, type SegmentTransportConfig, type SlackMessage, SlackTransport, type SlackTransportConfig, type TransportConfig, type TransportEvents, type TransportLogEntry, type TransportMetrics, type TransportRetryConfig, type TransportType, WorkerTransport, type WorkerTransportConfig, toOtelSeverity };
|
|
486
498
|
//# sourceMappingURL=transports.d.ts.map
|
package/dist/transports.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transports.d.ts","names":[],"sources":["../src/transports/analytics.transport.ts","../src/transports/console.transport.ts","../src/transports/database.transport.ts","../src/transports/datadog.transport.ts","../src/transports/file.transport.ts","../src/transports/google-analytics.transport.ts","../src/transports/mixpanel.transport.ts","../src/transports/segment.transport.ts","../src/transports/transport.manager.ts"],"mappings":";;;;;;;;8BA0BsB,8BAA8B,YAAY;WAC9C;WACA;WACA;WACA;YAEN,QAAQ;YACR,OAAO;YACP,aAAa,OAAO;YACpB;;;;;;;;;UASF;;UAEA;mBACS;EAEL,YAAA,cAAc,QAAQ;;YAiBxB;EAIJ,MAAM,OAAO,oBAAoB;EAkBvC,WAAW,OAAO;EAgBZ,SAAS;;;;;;;;UAyBD;EAkBR,SAAS;YA4BL,gBAAgB,OAAO;YAMvB,eAAe,OAAO,oBAAoB;;YAwB1C;;;;;YAQA,eAAe;;YAST,gBAAgB;qBAKb,cAAc;qBACd,UAAU,OAAO,oBAAoB;qBACrC,UAAU,SAAS,sBAAsB;qBACzC,WAAW;;UAYf;EACf;EACA,aAAa;EACb,SAAS;;UAGM;EACf;EACA;EACA;EACA,OAAO;EACP,YAAY;;;;;;;;;;qBC3OD,4BAA4B;
|
|
1
|
+
{"version":3,"file":"transports.d.ts","names":[],"sources":["../src/transports/analytics.transport.ts","../src/transports/console.transport.ts","../src/transports/database.transport.ts","../src/transports/datadog.transport.ts","../src/transports/file.transport.ts","../src/transports/google-analytics.transport.ts","../src/transports/mixpanel.transport.ts","../src/transports/segment.transport.ts","../src/transports/transport.manager.ts"],"mappings":";;;;;;;;8BA0BsB,8BAA8B,YAAY;WAC9C;WACA;WACA;WACA;YAEN,QAAQ;YACR,OAAO;YACP,aAAa,OAAO;YACpB;;;;;;;;;UASF;;UAEA;mBACS;EAEL,YAAA,cAAc,QAAQ;;YAiBxB;EAIJ,MAAM,OAAO,oBAAoB;EAkBvC,WAAW,OAAO;EAgBZ,SAAS;;;;;;;;UAyBD;EAkBR,SAAS;YA4BL,gBAAgB,OAAO;YAMvB,eAAe,OAAO,oBAAoB;;YAwB1C;;;;;YAQA,eAAe;;YAST,gBAAgB;qBAKb,cAAc;qBACd,UAAU,OAAO,oBAAoB;qBACrC,UAAU,SAAS,sBAAsB;qBACzC,WAAW;;UAYf;EACf;EACA,aAAa;EACb,SAAS;;UAGM;EACf;EACA;EACA;EACA,OAAO;EACP,YAAY;;;;;;;;;;qBC3OD,4BAA4B;UAiCnB;WAhCJ;WACA;WACA,UAAU,OAAO;0BAGT;iBAqBT;EAMK,YAAA,SAAQ;EAS5B,MAAM,OAAO;UAUL;UA4DA;UAsBA;EAQR,SAAS;;;;;;;;;;;;;;qBCtBE,6BAA6B,iBAAiB;UAuBrC;WAtBJ;WACA;WACA;WACA;WACA,UAAU,OAAO;UAEzB;UACA;;;;;;;;UAQA;UAEA;UACA;UACA;mBACS;EAEG,YAAA,QAAQ;U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EAgBF,gBAAgB;EAchB,SAAS;EAgBT,SAAS;EA2Bf;EAIA,aAAa,aAAa;EAI1B,cAAc;EAId,uBAAuB,aAAa;EAIpC,iBAAiB,aAAa;UAYtB;UAMA;EAOR,MAAM,WAAW,OAAO;EAIxB,QAAQ,WAAW,OAAO,OAAO;EAIjC,QAAQ,WAAW,mBAAmB;EAItC,iBAAiB,WAAW,YAAY,WAAW;EAInD,mBAAmB,WAAW;EAKxB,eAAe;IACnB;IACA,SAAS;;;EAwBX;;EAKA;UAIQ;EAQR,mBAAmB,qBAAqB;EAKxC,mBAAmB;EAInB"}
|
package/dist/transports.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_slack_transport = require("./slack.transport-
|
|
4
|
-
const require_azure_monitor_transport = require("./azure-monitor.transport-
|
|
5
|
-
const require_cloudwatch_transport = require("./cloudwatch.transport-
|
|
6
|
-
const require_gcp_transport = require("./gcp.transport-
|
|
7
|
-
const require_worker_transport = require("./worker.transport-
|
|
8
|
-
exports.AnalyticsTransport =
|
|
2
|
+
const require_otel = require("./otel-DyeH6DVR.js");
|
|
3
|
+
const require_slack_transport = require("./slack.transport-UbYvOdKx.js");
|
|
4
|
+
const require_azure_monitor_transport = require("./azure-monitor.transport-Bu4S2I2q.js");
|
|
5
|
+
const require_cloudwatch_transport = require("./cloudwatch.transport-Ch1Uae-0.js");
|
|
6
|
+
const require_gcp_transport = require("./gcp.transport-Dy2Lf8FI.js");
|
|
7
|
+
const require_worker_transport = require("./worker.transport-DxxbqQCG.js");
|
|
8
|
+
exports.AnalyticsTransport = require_otel.AnalyticsTransport;
|
|
9
9
|
exports.AzureMonitorTransport = require_azure_monitor_transport.AzureMonitorTransport;
|
|
10
10
|
exports.CloudWatchTransport = require_cloudwatch_transport.CloudWatchTransport;
|
|
11
|
-
exports.ConsoleTransport =
|
|
12
|
-
exports.DataDogTransport =
|
|
13
|
-
exports.DatabaseTransport =
|
|
11
|
+
exports.ConsoleTransport = require_otel.ConsoleTransport;
|
|
12
|
+
exports.DataDogTransport = require_otel.DataDogTransport;
|
|
13
|
+
exports.DatabaseTransport = require_otel.DatabaseTransport;
|
|
14
14
|
exports.DiscordTransport = require_slack_transport.DiscordTransport;
|
|
15
|
-
exports.FileTransport =
|
|
15
|
+
exports.FileTransport = require_otel.FileTransport;
|
|
16
16
|
exports.GCPTransport = require_gcp_transport.GCPTransport;
|
|
17
|
-
exports.GoogleAnalyticsTransport =
|
|
18
|
-
exports.MixpanelTransport =
|
|
17
|
+
exports.GoogleAnalyticsTransport = require_otel.GoogleAnalyticsTransport;
|
|
18
|
+
exports.MixpanelTransport = require_otel.MixpanelTransport;
|
|
19
19
|
exports.OtlpLogTransport = require_slack_transport.OtlpLogTransport;
|
|
20
|
-
exports.SegmentTransport =
|
|
20
|
+
exports.SegmentTransport = require_otel.SegmentTransport;
|
|
21
21
|
exports.SlackTransport = require_slack_transport.SlackTransport;
|
|
22
|
-
exports.TransportManager =
|
|
22
|
+
exports.TransportManager = require_otel.TransportManager;
|
|
23
23
|
exports.WorkerTransport = require_worker_transport.WorkerTransport;
|
|
24
24
|
exports.toOtelSeverity = require_slack_transport.toOtelSeverity;
|
package/dist/transports.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as toOtelSeverity, n as DiscordTransport, r as OtlpLogTransport, t as SlackTransport } from "./slack.transport-
|
|
3
|
-
import { t as AzureMonitorTransport } from "./azure-monitor.transport-
|
|
4
|
-
import { t as CloudWatchTransport } from "./cloudwatch.transport-
|
|
5
|
-
import { t as GCPTransport } from "./gcp.transport-
|
|
6
|
-
import { t as WorkerTransport } from "./worker.transport-
|
|
1
|
+
import { _ as ConsoleTransport, c as TransportManager, d as GoogleAnalyticsTransport, f as FileTransport, h as DatabaseTransport, l as SegmentTransport, m as AnalyticsTransport, p as DataDogTransport, u as MixpanelTransport } from "./otel-Dt5riXuE.mjs";
|
|
2
|
+
import { i as toOtelSeverity, n as DiscordTransport, r as OtlpLogTransport, t as SlackTransport } from "./slack.transport-BTEwsREY.mjs";
|
|
3
|
+
import { t as AzureMonitorTransport } from "./azure-monitor.transport-C1RWAumT.mjs";
|
|
4
|
+
import { t as CloudWatchTransport } from "./cloudwatch.transport-DZqF2xZO.mjs";
|
|
5
|
+
import { t as GCPTransport } from "./gcp.transport-DVCmnA3b.mjs";
|
|
6
|
+
import { t as WorkerTransport } from "./worker.transport-BmmOKb1-.mjs";
|
|
7
7
|
export { AnalyticsTransport, AzureMonitorTransport, CloudWatchTransport, ConsoleTransport, DataDogTransport, DatabaseTransport, DiscordTransport, FileTransport, GCPTransport, GoogleAnalyticsTransport, MixpanelTransport, OtlpLogTransport, SegmentTransport, SlackTransport, TransportManager, WorkerTransport, toOtelSeverity };
|
package/dist/worker-entry.js
CHANGED
|
@@ -61,7 +61,55 @@ function safeToString(value) {
|
|
|
61
61
|
} catch {}
|
|
62
62
|
return `[${((_constructor = value.constructor) === null || _constructor === void 0 ? void 0 : _constructor.name) ?? "object"}]`;
|
|
63
63
|
}
|
|
64
|
+
// src/utils/own-property.ts
|
|
65
|
+
/**
|
|
66
|
+
* True for the one key that must never be assigned with `target[key] = value`.
|
|
67
|
+
*
|
|
68
|
+
* Assigning `constructor` or `prototype` on a fresh plain object only creates an
|
|
69
|
+
* own property, which is harmless. Only `__proto__` invokes the prototype setter.
|
|
70
|
+
*/
|
|
71
|
+
function isProtoKey(key) {
|
|
72
|
+
return key === "__proto__";
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Copy `value` onto `target[key]` as an own, enumerable data property.
|
|
76
|
+
*
|
|
77
|
+
* Normal keys use a plain assignment, which is the fast path. `__proto__` goes
|
|
78
|
+
* through `Object.defineProperty` so that a key taken from logged or parsed data
|
|
79
|
+
* becomes an own property instead of replacing the object's prototype.
|
|
80
|
+
*/
|
|
81
|
+
function assignOwn(target, key, value) {
|
|
82
|
+
if (key === "__proto__") Object.defineProperty(target, key, {
|
|
83
|
+
value,
|
|
84
|
+
enumerable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
else target[key] = value;
|
|
89
|
+
}
|
|
64
90
|
// src/utils/safe-stringify.ts
|
|
91
|
+
/**
|
|
92
|
+
* logixia — robust JSON serialization for log payloads.
|
|
93
|
+
*
|
|
94
|
+
* Modern Winston/Pino already neutralize circular refs to `[Circular]` (via
|
|
95
|
+
* safe-stable-stringify / fast-safe-stringify), so merely "surviving cycles" is
|
|
96
|
+
* not a differentiator. This goes one notch further:
|
|
97
|
+
*
|
|
98
|
+
* - **BigInt** → serialized (as a string by default; JSON.stringify throws on
|
|
99
|
+
* BigInt, which silently breaks logging of e.g. DB bigint ids).
|
|
100
|
+
* - **Deterministic key order** (optional) so identical objects hash/diff equal.
|
|
101
|
+
* - **True decycle** (optional) — replace repeated references with JSONPath
|
|
102
|
+
* `$ref` pointers that round-trip back to the original object graph, instead
|
|
103
|
+
* of the lossy `[Circular]` tag. Useful when you need to reconstruct shared
|
|
104
|
+
* structure downstream.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* safeStringify({ id: 10n, self: obj }); // → BigInt + cycle safe
|
|
109
|
+
* safeStringify(graph, { decycle: true }); // → round-trippable $ref pointers
|
|
110
|
+
* const back = retrocycle(JSON.parse(json)); // → reconstruct shared refs
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
65
113
|
/** Build a JSONPath like `$["a"][0]["b"]` for a decycle pointer. */
|
|
66
114
|
function jsonPath(parts) {
|
|
67
115
|
let path = "$";
|
|
@@ -91,10 +139,7 @@ function safeStringify(value, options = {}) {
|
|
|
91
139
|
const rec = val;
|
|
92
140
|
const keys = deterministic ? Object.keys(rec).sort() : Object.keys(rec);
|
|
93
141
|
const obj = {};
|
|
94
|
-
for (const k of keys)
|
|
95
|
-
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
96
|
-
obj[k] = transform(rec[k]);
|
|
97
|
-
}
|
|
142
|
+
for (const k of keys) assignOwn(obj, k, transform(rec[k]));
|
|
98
143
|
out = obj;
|
|
99
144
|
}
|
|
100
145
|
seen.delete(val);
|
|
@@ -119,10 +164,7 @@ function decycleValue(value, bigint = "string") {
|
|
|
119
164
|
if (Array.isArray(val)) return val.map((item, i) => walk(item, [...path, i]));
|
|
120
165
|
const rec = val;
|
|
121
166
|
const obj = {};
|
|
122
|
-
for (const k of Object.keys(rec))
|
|
123
|
-
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
124
|
-
obj[k] = walk(rec[k], [...path, k]);
|
|
125
|
-
}
|
|
167
|
+
for (const k of Object.keys(rec)) assignOwn(obj, k, walk(rec[k], [...path, k]));
|
|
126
168
|
return obj;
|
|
127
169
|
};
|
|
128
170
|
return walk(value, []);
|
|
@@ -163,7 +205,6 @@ function stripControlChars(value) {
|
|
|
163
205
|
}
|
|
164
206
|
// src/transports/entry-fields.ts
|
|
165
207
|
const PAYLOAD_PREFIX = "data_";
|
|
166
|
-
const UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__"]);
|
|
167
208
|
/**
|
|
168
209
|
* Copies `core` and then the user payload into one object. The core fields stay
|
|
169
210
|
* authoritative: a payload key that matches a core key (even one whose value is
|
|
@@ -171,6 +212,10 @@ const UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__"]);
|
|
|
171
212
|
* prefix is repeated until the name is free of core keys and of every other
|
|
172
213
|
* payload key, so the result does not depend on key order and a payload's own
|
|
173
214
|
* `data_level` stays where it is.
|
|
215
|
+
*
|
|
216
|
+
* Exception: a payload `traceId` equal to the core `traceId` is a duplicate (the
|
|
217
|
+
* context middleware copies the trace id into the payload) and is dropped rather
|
|
218
|
+
* than emitted again as `data_traceId`. A different value is still kept.
|
|
174
219
|
*/
|
|
175
220
|
function mergeCoreFields(core, data, extraReserved = []) {
|
|
176
221
|
const merged = { ...core };
|
|
@@ -178,7 +223,8 @@ function mergeCoreFields(core, data, extraReserved = []) {
|
|
|
178
223
|
const reserved = /* @__PURE__ */ new Set([...Object.keys(core), ...extraReserved]);
|
|
179
224
|
const payloadKeys = new Set(Object.keys(data));
|
|
180
225
|
for (const key of payloadKeys) {
|
|
181
|
-
if (
|
|
226
|
+
if (isProtoKey(key)) continue;
|
|
227
|
+
if (key === "traceId" && core["traceId"] !== void 0 && data[key] === core["traceId"]) continue;
|
|
182
228
|
let target = key;
|
|
183
229
|
if (reserved.has(target)) do
|
|
184
230
|
target = `${PAYLOAD_PREFIX}${target}`;
|
|
@@ -203,6 +249,7 @@ var ConsoleTransport = class ConsoleTransport {
|
|
|
203
249
|
constructor(config = {}) {
|
|
204
250
|
this.config = config;
|
|
205
251
|
this.name = "console";
|
|
252
|
+
this.level = config.level;
|
|
206
253
|
if (config.filter) this.filter = config.filter;
|
|
207
254
|
}
|
|
208
255
|
write(entry) {
|
|
@@ -515,9 +562,9 @@ function redactConfig(value, depth = 0, key = "") {
|
|
|
515
562
|
if (Array.isArray(value)) return depth >= MAX_DEPTH ? "[Array]" : value.map((v) => redactConfig(v, depth + 1, key));
|
|
516
563
|
if (!isPlainObject(value) || depth >= MAX_DEPTH) return `[${((_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) ?? "Object"}]`;
|
|
517
564
|
const out = {};
|
|
518
|
-
for (const [name, inner] of Object.entries(value)) if (isSecretKey(name)) out
|
|
519
|
-
else if (name.toLowerCase() === "headers") out
|
|
520
|
-
else out
|
|
565
|
+
for (const [name, inner] of Object.entries(value)) if (isSecretKey(name)) assignOwn(out, name, inner === void 0 ? void 0 : REDACTED);
|
|
566
|
+
else if (name.toLowerCase() === "headers") assignOwn(out, name, redactHeaders(inner));
|
|
567
|
+
else assignOwn(out, name, redactConfig(inner, depth + 1, name));
|
|
521
568
|
return out;
|
|
522
569
|
}
|
|
523
570
|
const hiddenKeys = /* @__PURE__ */ new WeakMap();
|
|
@@ -741,6 +788,7 @@ var DatabaseTransport = class {
|
|
|
741
788
|
this.batchSize = config.batchSize || 100;
|
|
742
789
|
this.flushInterval = config.flushInterval || 5e3;
|
|
743
790
|
this.cap = new BufferCap("DatabaseTransport", config.maxBufferSize, this.batchSize);
|
|
791
|
+
this.level = config.level;
|
|
744
792
|
if (config.filter) this.filter = config.filter;
|
|
745
793
|
if (config.table) validateSqlIdentifier(config.table, "table");
|
|
746
794
|
this.setupFlushTimer();
|
|
@@ -1683,10 +1731,41 @@ var FileTransport = class {
|
|
|
1683
1731
|
this.reportDropped(0);
|
|
1684
1732
|
}
|
|
1685
1733
|
};
|
|
1734
|
+
// src/transports/level-filter.ts
|
|
1735
|
+
/** Severity values of the built-in levels; lower is more severe (same scale as the logger). */
|
|
1736
|
+
const BUILTIN_LEVEL_VALUES = {
|
|
1737
|
+
error: 0,
|
|
1738
|
+
warn: 1,
|
|
1739
|
+
info: 2,
|
|
1740
|
+
debug: 3,
|
|
1741
|
+
trace: 4,
|
|
1742
|
+
verbose: 5
|
|
1743
|
+
};
|
|
1744
|
+
/** Built-in levels plus the logger's custom `levelOptions.levels`. */
|
|
1745
|
+
function buildLevelValues(custom) {
|
|
1746
|
+
return new Map([...Object.entries(BUILTIN_LEVEL_VALUES), ...Object.entries(custom ?? {})]);
|
|
1747
|
+
}
|
|
1748
|
+
function lookup(values, level) {
|
|
1749
|
+
return values.get(level) ?? values.get(level.toLowerCase());
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Whether an entry at `level` passes a transport's minimum `threshold`, using the
|
|
1753
|
+
* logger's scale (an entry passes when its value is <= the threshold's value).
|
|
1754
|
+
* The logger has already rejected unknown entry levels, so an unknown entry level
|
|
1755
|
+
* or threshold here does not filter.
|
|
1756
|
+
*/
|
|
1757
|
+
function meetsTransportLevel(threshold, level, values) {
|
|
1758
|
+
if (!threshold) return true;
|
|
1759
|
+
const min = lookup(values, threshold);
|
|
1760
|
+
const actual = lookup(values, level);
|
|
1761
|
+
if (min === void 0 || actual === void 0) return true;
|
|
1762
|
+
return actual <= min;
|
|
1763
|
+
}
|
|
1686
1764
|
// src/transports/worker-entry.ts
|
|
1687
1765
|
const port = node_worker_threads.parentPort;
|
|
1688
1766
|
if (!port) throw new Error("worker-entry must run inside a worker thread");
|
|
1689
|
-
const { transportType, transportConfig } = node_worker_threads.workerData;
|
|
1767
|
+
const { transportType, transportConfig, levels } = node_worker_threads.workerData;
|
|
1768
|
+
const levelValues = buildLevelValues(levels);
|
|
1690
1769
|
function createTransport() {
|
|
1691
1770
|
const config = transportConfig;
|
|
1692
1771
|
switch (transportType) {
|
|
@@ -1710,16 +1789,18 @@ const flushTransport = async () => {
|
|
|
1710
1789
|
if (typeof transport.flush === "function") await transport.flush();
|
|
1711
1790
|
};
|
|
1712
1791
|
async function handle(msg) {
|
|
1713
|
-
if (msg.type === "write")
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1792
|
+
if (msg.type === "write") {
|
|
1793
|
+
if (!meetsTransportLevel(transport.level, msg.entry.level, levelValues)) return;
|
|
1794
|
+
try {
|
|
1795
|
+
await transport.write(msg.entry);
|
|
1796
|
+
} catch (err) {
|
|
1797
|
+
port === null || port === void 0 || port.postMessage({
|
|
1798
|
+
type: "write-error",
|
|
1799
|
+
error: errorMessage(err),
|
|
1800
|
+
entry: msg.entry
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
} else if (msg.type === "flush") try {
|
|
1723
1804
|
await flushTransport();
|
|
1724
1805
|
port === null || port === void 0 || port.postMessage({ type: "flushed" });
|
|
1725
1806
|
} catch (err) {
|
package/dist/worker.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-
|
|
1
|
+
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-Bl8lFRck.mjs";
|
|
2
2
|
export { WorkerTransport, WorkerTransportConfig };
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-
|
|
1
|
+
import { n as WorkerTransportConfig, t as WorkerTransport } from "./worker.transport-B9mCQSM1.js";
|
|
2
2
|
export { WorkerTransport, WorkerTransportConfig };
|
package/dist/worker.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_worker_transport = require("./worker.transport-
|
|
2
|
+
const require_worker_transport = require("./worker.transport-DxxbqQCG.js");
|
|
3
3
|
exports.WorkerTransport = require_worker_transport.WorkerTransport;
|
package/dist/worker.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as WorkerTransport } from "./worker.transport-
|
|
1
|
+
export { t as WorkerTransport } from "./worker.transport-BmmOKb1-.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as TransportLogEntry, d as ITransport } from "./transport.types-CzJq4IrF.js";
|
|
2
2
|
interface WorkerTransportConfig {
|
|
3
3
|
/**
|
|
4
4
|
* Which built-in logixia transport to run inside the worker thread.
|
|
@@ -18,6 +18,11 @@ interface WorkerTransportConfig {
|
|
|
18
18
|
* @default 3
|
|
19
19
|
*/
|
|
20
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>;
|
|
21
26
|
/**
|
|
22
27
|
* Log level filter — only entries at or above this level are forwarded.
|
|
23
28
|
* Useful for routing only errors to an expensive transport in a worker.
|
|
@@ -69,4 +74,4 @@ declare class WorkerTransport implements ITransport {
|
|
|
69
74
|
private drainBufferTo;
|
|
70
75
|
}
|
|
71
76
|
export { WorkerTransportConfig as n, WorkerTransport as t };
|
|
72
|
-
//# 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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as TransportLogEntry, d as ITransport } from "./transport.types-CzJq4IrF.mjs";
|
|
2
2
|
interface WorkerTransportConfig {
|
|
3
3
|
/**
|
|
4
4
|
* Which built-in logixia transport to run inside the worker thread.
|
|
@@ -18,6 +18,11 @@ interface WorkerTransportConfig {
|
|
|
18
18
|
* @default 3
|
|
19
19
|
*/
|
|
20
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>;
|
|
21
26
|
/**
|
|
22
27
|
* Log level filter — only entries at or above this level are forwarded.
|
|
23
28
|
* Useful for routing only errors to an expensive transport in a worker.
|
|
@@ -69,4 +74,4 @@ declare class WorkerTransport implements ITransport {
|
|
|
69
74
|
private drainBufferTo;
|
|
70
75
|
}
|
|
71
76
|
export { WorkerTransportConfig as n, WorkerTransport as t };
|
|
72
|
-
//# 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,5 +1,5 @@
|
|
|
1
|
-
import { r as internalWarn, t as internalError } from "./internal-log-
|
|
2
|
-
import { n as protectSecrets } from "./secret-config-
|
|
1
|
+
import { r as internalWarn, t as internalError } from "./internal-log-Bg4V1cPg.mjs";
|
|
2
|
+
import { n as protectSecrets } from "./secret-config-Dhb6pqTU.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { Worker } from "node:worker_threads";
|
|
@@ -30,12 +30,14 @@ const __dirname = /* @__PURE__ */ getDirname();
|
|
|
30
30
|
* const logger = createLogger({
|
|
31
31
|
* transports: {
|
|
32
32
|
* // Run file transport inside a worker thread — zero event-loop impact
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
33
|
+
* custom: [
|
|
34
|
+
* new WorkerTransport({
|
|
35
|
+
* transportType: 'file',
|
|
36
|
+
* transportConfig: { filename: 'app.log', dirname: './logs' },
|
|
37
|
+
* bufferSize: 500,
|
|
38
|
+
* maxRestarts: 3,
|
|
39
|
+
* }),
|
|
40
|
+
* ],
|
|
39
41
|
* },
|
|
40
42
|
* });
|
|
41
43
|
* ```
|
|
@@ -68,7 +70,8 @@ var WorkerTransport = class {
|
|
|
68
70
|
try {
|
|
69
71
|
this.worker = new Worker(this.workerFile(), { workerData: {
|
|
70
72
|
transportType: this.config.transportType,
|
|
71
|
-
transportConfig: this.config.transportConfig
|
|
73
|
+
transportConfig: this.config.transportConfig,
|
|
74
|
+
levels: this.config.levels
|
|
72
75
|
} });
|
|
73
76
|
this.worker.on("message", (msg) => {
|
|
74
77
|
if (msg.type === "ready") {
|
|
@@ -194,4 +197,4 @@ var WorkerTransport = class {
|
|
|
194
197
|
};
|
|
195
198
|
export { WorkerTransport as t };
|
|
196
199
|
|
|
197
|
-
//# sourceMappingURL=worker.transport-
|
|
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,KAAK,SAAS;EACd,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,cAAc,OAAO,eAAe;EACzC,KAAK,QAAQ,OAAO;EACpB,eAAe,MAAM,CAAC,QAAQ,CAAC;EAC/B,KAAK,YAAY;CACnB;CAEA,cAA4B;EAC1B,IAAI;GACF,KAAK,SAAS,IAAI,OAAO,KAAK,WAAW,GAAG,EAC1C,YAAY;IACV,eAAe,KAAK,OAAO;IAC3B,iBAAiB,KAAK,OAAO;IAC7B,QAAQ,KAAK,OAAO;GACtB,EACF,CAAC;GAED,KAAK,OAAO,GAAG,YAAY,QAA0C;IACnE,IAAI,IAAI,SAAS,SAAS;KACxB,KAAK,QAAQ;KACb,KAAK,YAAY;IACnB,OAAO,IAAI,IAAI,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,5 @@
|
|
|
1
|
-
const require_secret_config = require("./secret-config-
|
|
2
|
-
const require_internal_log = require("./internal-log-
|
|
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
4
|
node_path = require_secret_config.__toESM(node_path);
|
|
5
5
|
let node_worker_threads = require("node:worker_threads");
|
|
@@ -26,12 +26,14 @@ let node_worker_threads = require("node:worker_threads");
|
|
|
26
26
|
* const logger = createLogger({
|
|
27
27
|
* transports: {
|
|
28
28
|
* // Run file transport inside a worker thread — zero event-loop impact
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* custom: [
|
|
30
|
+
* new WorkerTransport({
|
|
31
|
+
* transportType: 'file',
|
|
32
|
+
* transportConfig: { filename: 'app.log', dirname: './logs' },
|
|
33
|
+
* bufferSize: 500,
|
|
34
|
+
* maxRestarts: 3,
|
|
35
|
+
* }),
|
|
36
|
+
* ],
|
|
35
37
|
* },
|
|
36
38
|
* });
|
|
37
39
|
* ```
|
|
@@ -64,7 +66,8 @@ var WorkerTransport = class {
|
|
|
64
66
|
try {
|
|
65
67
|
this.worker = new node_worker_threads.Worker(this.workerFile(), { workerData: {
|
|
66
68
|
transportType: this.config.transportType,
|
|
67
|
-
transportConfig: this.config.transportConfig
|
|
69
|
+
transportConfig: this.config.transportConfig,
|
|
70
|
+
levels: this.config.levels
|
|
68
71
|
} });
|
|
69
72
|
this.worker.on("message", (msg) => {
|
|
70
73
|
if (msg.type === "ready") {
|
|
@@ -195,4 +198,4 @@ Object.defineProperty(exports, "WorkerTransport", {
|
|
|
195
198
|
}
|
|
196
199
|
});
|
|
197
200
|
|
|
198
|
-
//# sourceMappingURL=worker.transport-
|
|
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,KAAA,WAAA;EAI2B,KAAA,eAAA;EAE5B,KAAA,UAAA;EAEkB,KAAA,mBAAA;EAEG,KAAA,sBAAA;EAGrC,KAAK,SAAS;EACd,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,cAAc,OAAO,eAAe;EACzC,KAAK,QAAQ,OAAO;EACpB,sBAAA,eAAe,MAAM,CAAC,QAAQ,CA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