logixia 1.13.3 → 2.0.4
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 +117 -44
- package/dist/async-context-B05ArHgM.mjs +134 -0
- package/dist/async-context-B05ArHgM.mjs.map +1 -0
- package/dist/async-context-DTQgi8f7.js +150 -0
- package/dist/async-context-DTQgi8f7.js.map +1 -0
- package/dist/{azure-monitor.transport-CHnjVRF-.mjs → azure-monitor.transport-BPbgjATu.mjs} +27 -15
- package/dist/azure-monitor.transport-BPbgjATu.mjs.map +1 -0
- package/dist/{azure-monitor.transport-BDFO4F-i.d.ts → azure-monitor.transport-C7kYyZUW.d.mts} +3 -6
- package/dist/azure-monitor.transport-C7kYyZUW.d.mts.map +1 -0
- package/dist/{azure-monitor.transport-CrvfHd9C.js → azure-monitor.transport-CwbOLZHB.js} +32 -20
- package/dist/azure-monitor.transport-CwbOLZHB.js.map +1 -0
- package/dist/{azure-monitor.transport-D5wQEH04.d.mts → azure-monitor.transport-DV03Z5P4.d.ts} +3 -6
- package/dist/azure-monitor.transport-DV03Z5P4.d.ts.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-0fgLmIPn.mjs} +21 -7
- package/dist/batch-buffer-0fgLmIPn.mjs.map +1 -0
- package/dist/{batch-buffer-BY-mRWIK.js → batch-buffer-DT4gdXmf.js} +53 -40
- package/dist/batch-buffer-DT4gdXmf.js.map +1 -0
- package/dist/browser.d.mts +52 -23
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +52 -23
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +460 -62
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +461 -65
- package/dist/browser.mjs.map +1 -1
- package/dist/{nestjs-extras-ImbuDhs1.mjs → builder-D70z6kjj.mjs} +279 -965
- package/dist/builder-D70z6kjj.mjs.map +1 -0
- package/dist/{nestjs-extras-DnJ6vrIC.js → builder-M7NoaugM.js} +421 -1177
- package/dist/builder-M7NoaugM.js.map +1 -0
- package/dist/cli/index.js +86 -67
- 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-BO1ahxw-.js → cloudwatch.transport-B2wKQFF7.js} +61 -36
- package/dist/cloudwatch.transport-B2wKQFF7.js.map +1 -0
- package/dist/{cloudwatch.transport-DZ6ies7g.mjs → cloudwatch.transport-BTvYfLs9.mjs} +54 -28
- package/dist/cloudwatch.transport-BTvYfLs9.mjs.map +1 -0
- package/dist/{cloudwatch.transport-B00st6Xv.d.ts → cloudwatch.transport-Bf7L4I59.d.ts} +2 -6
- package/dist/cloudwatch.transport-Bf7L4I59.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-Blc7Gtxt.d.mts → cloudwatch.transport-Rj4yTpRn.d.mts} +2 -6
- package/dist/cloudwatch.transport-Rj4yTpRn.d.mts.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 +13 -16
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +13 -16
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +58 -9
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +56 -6
- package/dist/correlation.mjs.map +1 -1
- package/dist/{entry-fields-BJkuPnIg.mjs → entry-fields-CGuvT2R0.mjs} +5 -6
- package/dist/entry-fields-CGuvT2R0.mjs.map +1 -0
- package/dist/{entry-fields-BvOLFlJ4.js → entry-fields-RLd1jCoR.js} +10 -12
- package/dist/entry-fields-RLd1jCoR.js.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-m4fVw0b1.d.ts → gcp.transport-C5D72b1g.d.mts} +3 -6
- package/dist/gcp.transport-C5D72b1g.d.mts.map +1 -0
- package/dist/{gcp.transport-zzNyIoih.d.mts → gcp.transport-CFQfdAOK.d.ts} +3 -6
- package/dist/gcp.transport-CFQfdAOK.d.ts.map +1 -0
- package/dist/{gcp.transport-DBX5TPIy.mjs → gcp.transport-CGKopAhQ.mjs} +55 -16
- package/dist/gcp.transport-CGKopAhQ.mjs.map +1 -0
- package/dist/{gcp.transport-CHV8MGgz.js → gcp.transport-KZe9hCAR.js} +60 -22
- package/dist/gcp.transport-KZe9hCAR.js.map +1 -0
- package/dist/{index-nZEeCr3X.d.ts → index-DwozbmB4.d.ts} +3 -8
- package/dist/index-DwozbmB4.d.ts.map +1 -0
- package/dist/{index-BPwEisy4.d.mts → index-xqaJtAZn.d.mts} +3 -8
- package/dist/index-xqaJtAZn.d.mts.map +1 -0
- package/dist/index.d.mts +141 -203
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +140 -202
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +196 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -294
- package/dist/index.mjs.map +1 -1
- package/dist/internal-log-b0Vp4qrB.js +183 -0
- package/dist/internal-log-b0Vp4qrB.js.map +1 -0
- package/dist/internal-log-uCSd1PMc.mjs +142 -0
- package/dist/internal-log-uCSd1PMc.mjs.map +1 -0
- package/dist/logitron-logger-D2B75Oc7.d.ts +365 -0
- package/dist/logitron-logger-D2B75Oc7.d.ts.map +1 -0
- package/dist/logitron-logger-oEd6wNhf.d.mts +365 -0
- package/dist/logitron-logger-oEd6wNhf.d.mts.map +1 -0
- package/dist/middleware.d.mts +10 -12
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +10 -12
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +16 -47
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +13 -45
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +467 -10
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +467 -10
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +889 -43
- package/dist/nest.js.map +1 -0
- package/dist/nest.mjs +850 -9
- package/dist/nest.mjs.map +1 -0
- package/dist/{trace.utils-CvXgaiQT.mjs → request-trace-C_fvIDv4.mjs} +44 -9
- package/dist/request-trace-C_fvIDv4.mjs.map +1 -0
- package/dist/{trace.utils-DpBOLDtq.js → request-trace-wTJdKp6-.js} +121 -77
- package/dist/request-trace-wTJdKp6-.js.map +1 -0
- package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
- package/dist/{safe-stringify-DJ66tW5I.mjs → safe-stringify-BMRl3EX3.mjs} +3 -4
- package/dist/safe-stringify-BMRl3EX3.mjs.map +1 -0
- package/dist/{safe-stringify-DWo3aZp_.js → safe-stringify-DLz1Kz3o.js} +23 -25
- package/dist/safe-stringify-DLz1Kz3o.js.map +1 -0
- package/dist/{search-CHUZPl0h.d.ts → search-BH33XhuU.d.mts} +2 -22
- package/dist/search-BH33XhuU.d.mts.map +1 -0
- package/dist/{search-DjXSn6v5.mjs → search-CWMVYC-R.mjs} +34 -41
- package/dist/search-CWMVYC-R.mjs.map +1 -0
- package/dist/{search-BfBzDIT9.d.mts → search-CazwyX5Z.d.ts} +2 -22
- package/dist/search-CazwyX5Z.d.ts.map +1 -0
- package/dist/{search-B0MH1SJJ.js → search-DUfWuzFP.js} +64 -71
- package/dist/search-DUfWuzFP.js.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-BegMLkYl.mjs +209 -0
- package/dist/secret-config-BegMLkYl.mjs.map +1 -0
- package/dist/secret-config-CBZBs0p1.js +271 -0
- package/dist/secret-config-CBZBs0p1.js.map +1 -0
- package/dist/slack.transport-Ce96JBDk.mjs +824 -0
- package/dist/slack.transport-Ce96JBDk.mjs.map +1 -0
- package/dist/slack.transport-Dlx3xvb7.js +847 -0
- package/dist/slack.transport-Dlx3xvb7.js.map +1 -0
- package/dist/slack.transport-DrirgDNy.d.ts +159 -0
- package/dist/slack.transport-DrirgDNy.d.ts.map +1 -0
- package/dist/slack.transport-DxHOXlLu.d.mts +159 -0
- package/dist/slack.transport-DxHOXlLu.d.mts.map +1 -0
- package/dist/testing.d.mts +3 -8
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.d.ts +3 -8
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +3 -4
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +2 -3
- package/dist/testing.mjs.map +1 -1
- package/dist/{transport.manager-Crau3Rle.js → transport.manager-DkcEOlqV.js} +331 -234
- package/dist/transport.manager-DkcEOlqV.js.map +1 -0
- package/dist/{transport.manager-CpdVHEGP.mjs → transport.manager-eZ_EeC00.mjs} +274 -178
- package/dist/transport.manager-eZ_EeC00.mjs.map +1 -0
- package/dist/{transport.types-CtNr3D7S.d.mts → transport.types-BJVL1QQl.d.mts} +5 -4
- package/dist/transport.types-BJVL1QQl.d.mts.map +1 -0
- package/dist/{transport.types-DqVLZTyf.d.ts → transport.types-BJVL1QQl.d.ts} +5 -4
- package/dist/transport.types-BJVL1QQl.d.ts.map +1 -0
- package/dist/transports.d.mts +32 -41
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +32 -41
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +12 -12
- package/dist/transports.mjs +7 -12
- package/dist/worker-entry.js +337 -87
- 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-Bj-i0P9V.d.ts → worker.transport-BuPwBi3d.d.ts} +2 -6
- package/dist/worker.transport-BuPwBi3d.d.ts.map +1 -0
- package/dist/{worker.transport-JP8YHBuU.js → worker.transport-C6GNl_r2.js} +44 -14
- package/dist/worker.transport-C6GNl_r2.js.map +1 -0
- package/dist/{worker.transport-otwhJ_Et.mjs → worker.transport-DLVA4y2e.mjs} +39 -9
- package/dist/worker.transport-DLVA4y2e.mjs.map +1 -0
- package/dist/{worker.transport-Bgv9heDI.d.mts → worker.transport-hJay1wxA.d.mts} +2 -6
- package/dist/worker.transport-hJay1wxA.d.mts.map +1 -0
- package/package.json +36 -19
- 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-BDFO4F-i.d.ts.map +0 -1
- package/dist/azure-monitor.transport-CHnjVRF-.mjs.map +0 -1
- package/dist/azure-monitor.transport-CrvfHd9C.js.map +0 -1
- package/dist/azure-monitor.transport-D5wQEH04.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/chunk-DLSkYcPk.mjs +0 -7
- package/dist/chunk-nOFOJqeH.js +0 -30
- package/dist/cloudwatch.transport-B00st6Xv.d.ts.map +0 -1
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +0 -1
- package/dist/cloudwatch.transport-Blc7Gtxt.d.mts.map +0 -1
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.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-CHV8MGgz.js.map +0 -1
- package/dist/gcp.transport-DBX5TPIy.mjs.map +0 -1
- package/dist/gcp.transport-m4fVw0b1.d.ts.map +0 -1
- package/dist/gcp.transport-zzNyIoih.d.mts.map +0 -1
- package/dist/index-BPwEisy4.d.mts.map +0 -1
- package/dist/index-nZEeCr3X.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/nestjs-extras-DnJ6vrIC.js.map +0 -1
- package/dist/nestjs-extras-ImbuDhs1.mjs.map +0 -1
- package/dist/nestjs-extras-OkC796py.d.mts +0 -725
- package/dist/nestjs-extras-OkC796py.d.mts.map +0 -1
- package/dist/nestjs-extras-mKrHE9S6.d.ts +0 -725
- package/dist/nestjs-extras-mKrHE9S6.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-B0MH1SJJ.js.map +0 -1
- package/dist/search-BfBzDIT9.d.mts.map +0 -1
- package/dist/search-CHUZPl0h.d.ts.map +0 -1
- package/dist/search-DjXSn6v5.mjs.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-CpdVHEGP.mjs.map +0 -1
- package/dist/transport.manager-Crau3Rle.js.map +0 -1
- package/dist/transport.types-CtNr3D7S.d.mts.map +0 -1
- package/dist/transport.types-DqVLZTyf.d.ts.map +0 -1
- package/dist/worker.transport-Bgv9heDI.d.mts.map +0 -1
- package/dist/worker.transport-Bj-i0P9V.d.ts.map +0 -1
- package/dist/worker.transport-JP8YHBuU.js.map +0 -1
- package/dist/worker.transport-otwhJ_Et.mjs.map +0 -1
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { b as LoggerWithLevels, f as ILogger, h as LogEntry, p as ILoggerDefault, v as LogLevelString, x as NamespaceLevels, y as LoggerConfig } from "./index-xqaJtAZn.mjs";
|
|
2
|
+
interface LogixiaPlugin {
|
|
3
|
+
/**
|
|
4
|
+
* Unique plugin name.
|
|
5
|
+
* logixia uses this to prevent duplicate registration of the same plugin
|
|
6
|
+
* on the same logger instance.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Called once immediately after `logger.use(plugin)` is called.
|
|
11
|
+
* Use for one-time setup (open connections, allocate buffers, etc.).
|
|
12
|
+
* Async `onInit` errors are silently swallowed to avoid blocking the logger.
|
|
13
|
+
*/
|
|
14
|
+
onInit?(): void | Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Called for every log entry **after** PII redaction and **before** transport
|
|
17
|
+
* dispatch. Plugins run in registration order; each receives the (possibly
|
|
18
|
+
* modified) output of the previous plugin.
|
|
19
|
+
*
|
|
20
|
+
* - Return the entry (modified or unchanged) to continue processing.
|
|
21
|
+
* - Return `null` to **drop** the entry — no transport will receive it.
|
|
22
|
+
*
|
|
23
|
+
* Errors thrown inside `onLog` are swallowed so a buggy plugin cannot crash
|
|
24
|
+
* logging; the chain continues with the previous (un-transformed) entry.
|
|
25
|
+
*/
|
|
26
|
+
onLog?(entry: LogEntry): LogEntry | null | Promise<LogEntry | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Called when a transport write fails (after any configured retries).
|
|
29
|
+
* Useful for routing transport errors to an alerting or metrics system.
|
|
30
|
+
* Errors thrown inside `onError` are silently swallowed.
|
|
31
|
+
*/
|
|
32
|
+
onError?(error: Error, entry?: LogEntry): void | Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Called when the logger is closed via `logger.close()` or the process
|
|
35
|
+
* receives a shutdown signal (when `gracefulShutdown` is enabled).
|
|
36
|
+
* Errors thrown inside `onShutdown` are silently swallowed.
|
|
37
|
+
*/
|
|
38
|
+
onShutdown?(): void | Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
|
|
42
|
+
* events to them. One registry is created per logger instance; a global
|
|
43
|
+
* singleton is also exported for process-wide registration.
|
|
44
|
+
*/
|
|
45
|
+
declare class PluginRegistry {
|
|
46
|
+
private readonly _plugins;
|
|
47
|
+
/**
|
|
48
|
+
* Register a plugin. Silently skips if a plugin with the same `name` is
|
|
49
|
+
* already registered on this registry.
|
|
50
|
+
*/
|
|
51
|
+
register(plugin: LogixiaPlugin): void;
|
|
52
|
+
/** Remove a previously registered plugin by name. No-op if not found. */
|
|
53
|
+
unregister(name: string): void;
|
|
54
|
+
/** Returns `true` if a plugin with the given name is registered. */
|
|
55
|
+
has(name: string): boolean;
|
|
56
|
+
/** Number of currently registered plugins. */
|
|
57
|
+
get size(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Run all `onLog` hooks in order.
|
|
60
|
+
* Returns `null` if any plugin cancels the entry; otherwise returns the
|
|
61
|
+
* (possibly transformed) entry.
|
|
62
|
+
*/
|
|
63
|
+
runOnLog(entry: LogEntry): Promise<LogEntry | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Notify all `onError` hooks.
|
|
66
|
+
* Errors thrown inside hooks are swallowed to prevent error cascades.
|
|
67
|
+
*/
|
|
68
|
+
runOnError(error: Error, entry?: LogEntry): Promise<void>;
|
|
69
|
+
/** Run all `onShutdown` hooks concurrently. Hook errors are swallowed. */
|
|
70
|
+
runOnShutdown(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Module-level singleton registry.
|
|
74
|
+
*
|
|
75
|
+
* Plugins registered here are automatically copied into every **new** logger
|
|
76
|
+
* instance created after the registration. Already-created loggers are not
|
|
77
|
+
* retroactively affected — use `logger.use(plugin)` for per-instance control.
|
|
78
|
+
*/
|
|
79
|
+
declare const globalPluginRegistry: PluginRegistry;
|
|
80
|
+
/**
|
|
81
|
+
* Register a plugin in the global registry so it applies to every future
|
|
82
|
+
* logger instance.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { usePlugin } from 'logixia';
|
|
87
|
+
*
|
|
88
|
+
* usePlugin({
|
|
89
|
+
* name: 'audit-sink',
|
|
90
|
+
* onLog(entry) {
|
|
91
|
+
* if (entry.level === 'error') auditQueue.push(entry);
|
|
92
|
+
* return entry;
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function usePlugin(plugin: LogixiaPlugin): void;
|
|
98
|
+
/**
|
|
99
|
+
* The logixia logger. Create instances with {@link createLogger} so that custom
|
|
100
|
+
* levels from `levelOptions.levels` also become methods.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* const logger = createLogger({ appName: 'api', environment: 'production' });
|
|
105
|
+
* await logger.info('Server started', { port: 3000 });
|
|
106
|
+
* const req = logger.child('RequestHandler', { requestId: 'r-1' });
|
|
107
|
+
* await req.error(new Error('boom'));
|
|
108
|
+
* await logger.close(); // flush buffered transports before exit
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>> = LoggerConfig> implements ILoggerDefault {
|
|
112
|
+
[K: string]: any;
|
|
113
|
+
private config;
|
|
114
|
+
private context?;
|
|
115
|
+
private timers;
|
|
116
|
+
private contextData;
|
|
117
|
+
private transportManager;
|
|
118
|
+
private fieldState;
|
|
119
|
+
/** Stable fallback trace ID generated ONCE per logger instance. */
|
|
120
|
+
private readonly fallbackTraceId;
|
|
121
|
+
/** Numeric value for each known log level — built once, read on every log call. */
|
|
122
|
+
private _levelValues;
|
|
123
|
+
/** Numeric threshold for the currently active log level. */
|
|
124
|
+
private _minLevelValue;
|
|
125
|
+
/** Level set via setLevel(); outranks every other level source until the process ends. */
|
|
126
|
+
private _runtimeLevel;
|
|
127
|
+
/** `source=value` pairs already reported as unknown levels — warn once per logger. */
|
|
128
|
+
private readonly _warnedInvalidLevels;
|
|
129
|
+
/** Pre-built ANSI color codes to avoid recreating the object in colorize(). */
|
|
130
|
+
private _colorMap;
|
|
131
|
+
/** Pre-computed field-enabled booleans so isFieldEnabled() isn't called per log. */
|
|
132
|
+
private _fieldCache;
|
|
133
|
+
/** True when contextData is non-empty — avoids Object.keys() check on hot path. */
|
|
134
|
+
private _hasContextData;
|
|
135
|
+
/**
|
|
136
|
+
* Pre-computed `[INFO] `, `[WARN] ` etc. strings — avoids a colorize() call per log.
|
|
137
|
+
* Key: lowercase level name. Value: formatted bracket string ready to concatenate.
|
|
138
|
+
*/
|
|
139
|
+
private _formattedLevels;
|
|
140
|
+
/** Pre-computed `[appName] ` string — avoids template literal allocation per log. */
|
|
141
|
+
private _formattedAppName;
|
|
142
|
+
/** True when a redact config is present — short-circuits applyRedaction when false. */
|
|
143
|
+
private _hasRedact;
|
|
144
|
+
/** Sampling engine — only created when sampling config is present. */
|
|
145
|
+
private _sampler;
|
|
146
|
+
/** Per-instance plugin registry — also inherits from the global registry at creation time. */
|
|
147
|
+
private readonly _pluginRegistry;
|
|
148
|
+
/** Set on loggers created by child(); they borrow the root's transports, sampler and plugins. */
|
|
149
|
+
private readonly _parent;
|
|
150
|
+
constructor(config: TConfig, context?: string, parent?: LogixiaLogger<TConfig>);
|
|
151
|
+
private setupGracefulShutdown;
|
|
152
|
+
private createCustomLevelMethods;
|
|
153
|
+
/**
|
|
154
|
+
* Rebuild all hot-path caches after any config mutation or level change.
|
|
155
|
+
* Keeps the actual log() call free of allocations in the common case.
|
|
156
|
+
*/
|
|
157
|
+
private _buildPerfCaches;
|
|
158
|
+
/**
|
|
159
|
+
* Log at `error` level. An `Error` is logged with its message and serialized
|
|
160
|
+
* (name, message, stack) under `data.error`; a string is logged as-is.
|
|
161
|
+
* `data` is merged into the entry payload.
|
|
162
|
+
*/
|
|
163
|
+
error(messageOrError: string | Error, data?: Record<string, unknown>): Promise<void>;
|
|
164
|
+
/** Log `message` at `warn` level; `data` is merged into the entry payload. */
|
|
165
|
+
warn(message: string, data?: Record<string, unknown>): Promise<void>;
|
|
166
|
+
/** Log `message` at `info` level; `data` is merged into the entry payload. */
|
|
167
|
+
info(message: string, data?: Record<string, unknown>): Promise<void>;
|
|
168
|
+
/** Log `message` at `debug` level; `data` is merged into the entry payload. */
|
|
169
|
+
debug(message: string, data?: Record<string, unknown>): Promise<void>;
|
|
170
|
+
/** Log `message` at `trace` level; `data` is merged into the entry payload. */
|
|
171
|
+
trace(message: string, data?: Record<string, unknown>): Promise<void>;
|
|
172
|
+
/** Log `message` at `verbose` level; `data` is merged into the entry payload. */
|
|
173
|
+
verbose(message: string, data?: Record<string, unknown>): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Log at an arbitrary level name, including custom levels. Levels below the
|
|
176
|
+
* active threshold are dropped, as are level names that are not registered
|
|
177
|
+
* in `levelOptions.levels` (and are not built-in).
|
|
178
|
+
*/
|
|
179
|
+
logLevel(level: string, message: string, data?: Record<string, unknown>): Promise<void>;
|
|
180
|
+
/** Start a named timer; finish it with {@link timeEnd}. Reusing a label restarts it. */
|
|
181
|
+
time(label: string): void;
|
|
182
|
+
/**
|
|
183
|
+
* Stop the timer `label`, log its duration at `info` level, and return the
|
|
184
|
+
* elapsed milliseconds. Logs a `warn` and returns `undefined` if the timer
|
|
185
|
+
* does not exist.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* logger.time('db');
|
|
190
|
+
* await query();
|
|
191
|
+
* const ms = await logger.timeEnd('db');
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
timeEnd(label: string): Promise<number | undefined>;
|
|
195
|
+
timeAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
|
196
|
+
/**
|
|
197
|
+
* Change the minimum log level at runtime. The override outranks
|
|
198
|
+
* `LOGIXIA_LEVEL`, `LOGIXIA_LEVEL_<NS>` and `namespaceLevels`, and survives
|
|
199
|
+
* later changes to fields or namespace levels. Unknown level names are
|
|
200
|
+
* ignored with a warning and the current level is kept.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* logger.setLevel('debug');
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
setLevel(level: LogLevelString): void;
|
|
208
|
+
/**
|
|
209
|
+
* Return the configured minimum log level, not the per-namespace effective
|
|
210
|
+
* one. Without `setLevel()` it is `LOGIXIA_LEVEL`, else `levelOptions.level`,
|
|
211
|
+
* else a `NODE_ENV` default (`debug` in development, `warn` in test), else `info`.
|
|
212
|
+
*/
|
|
213
|
+
getLevel(): LogLevelString;
|
|
214
|
+
private _validLevelList;
|
|
215
|
+
/**
|
|
216
|
+
* Canonicalise a level from config/ENV. Unknown values return undefined so the
|
|
217
|
+
* caller falls through to the next source, and warn once per logger per source.
|
|
218
|
+
*/
|
|
219
|
+
private _validLevel;
|
|
220
|
+
/**
|
|
221
|
+
* Replace the per-namespace level map at runtime — no restart needed.
|
|
222
|
+
*
|
|
223
|
+
* This is the runtime counterpart to the `namespaceLevels` config option and
|
|
224
|
+
* the most-requested logging feature across the Winston/Pino issue trackers
|
|
225
|
+
* (flip a module's verbosity live to chase a bug without raising global
|
|
226
|
+
* volume). The new map fully replaces the previous one.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* // Turn on debug for the DB layer only, live:
|
|
231
|
+
* logger.setNamespaceLevels({ 'db.*': 'debug', '*': 'info' });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
setNamespaceLevels(levels: NamespaceLevels): void;
|
|
235
|
+
/** Merge entries into the existing per-namespace level map at runtime. */
|
|
236
|
+
patchNamespaceLevels(levels: NamespaceLevels): void;
|
|
237
|
+
/** Return a copy of the current per-namespace level map. */
|
|
238
|
+
getNamespaceLevels(): NamespaceLevels;
|
|
239
|
+
/** Set the context label (e.g. a class or module name) attached to every subsequent entry. */
|
|
240
|
+
setContext(context: string): void;
|
|
241
|
+
/** Return the current context label, or `undefined` if none is set. */
|
|
242
|
+
getContext(): string | undefined;
|
|
243
|
+
/** Show `fieldName` in log output, overriding the config for this logger instance. */
|
|
244
|
+
enableField(fieldName: string): void;
|
|
245
|
+
/** Hide `fieldName` from log output, overriding the config for this logger instance. */
|
|
246
|
+
disableField(fieldName: string): void;
|
|
247
|
+
/** Whether `fieldName` is currently shown: runtime override first, then config, default `true`. */
|
|
248
|
+
isFieldEnabled(fieldName: string): boolean;
|
|
249
|
+
/** Return the visibility (`true` = shown) of every standard log field. */
|
|
250
|
+
getFieldState(): Record<string, boolean>;
|
|
251
|
+
/** Drop all runtime enable/disable overrides so field visibility follows the config again. */
|
|
252
|
+
resetFieldState(): void;
|
|
253
|
+
/** @deprecated No-op. Library code never prompts on stdin; use setTransportLevels(). */
|
|
254
|
+
enableTransportLevelPrompting(): void;
|
|
255
|
+
/** @deprecated No-op. */
|
|
256
|
+
disableTransportLevelPrompting(): void;
|
|
257
|
+
/** Restrict `transportId` to only the given `levels`. Warns if no transports are configured. */
|
|
258
|
+
setTransportLevels(transportId: string, levels: string[]): void;
|
|
259
|
+
/** Return the levels `transportId` is restricted to, or `undefined` if it has none. */
|
|
260
|
+
getTransportLevels(transportId: string): string[] | undefined;
|
|
261
|
+
clearTransportLevelPreferences(): void;
|
|
262
|
+
/** Return the identifiers of the configured transports (empty if none). */
|
|
263
|
+
getAvailableTransports(): string[];
|
|
264
|
+
/**
|
|
265
|
+
* Create a child logger with its own `context` that shares this logger's
|
|
266
|
+
* configuration and transports. `data` is merged into the bound fields
|
|
267
|
+
* inherited from this logger and added to every entry the child writes.
|
|
268
|
+
* Closing a child does not close the shared transports.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* const req = logger.child('Checkout', { requestId: 'r-42' });
|
|
273
|
+
* await req.info('started'); // entry includes requestId
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
child(context: string, data?: Record<string, unknown>): ILogger;
|
|
277
|
+
/**
|
|
278
|
+
* Register a plugin on this logger instance.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* logger.use({
|
|
283
|
+
* name: 'audit',
|
|
284
|
+
* onLog(entry) { auditQueue.push(entry); return entry; },
|
|
285
|
+
* });
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
use(plugin: LogixiaPlugin): this;
|
|
289
|
+
/**
|
|
290
|
+
* Remove a previously registered plugin by name.
|
|
291
|
+
* No-op if the plugin is not registered on this instance.
|
|
292
|
+
*/
|
|
293
|
+
unuse(pluginName: string): this;
|
|
294
|
+
/** Flush buffered entries in all transports without closing them. */
|
|
295
|
+
flush(): Promise<void>;
|
|
296
|
+
/** Report whether the transports are healthy; `healthy: false` if no transport manager exists. */
|
|
297
|
+
healthCheck(): Promise<{
|
|
298
|
+
healthy: boolean;
|
|
299
|
+
details: Record<string, unknown>;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Warn about timers that were never ended, then flush and close all transports,
|
|
303
|
+
* stop the sampler and run plugin shutdown hooks. On a child logger only the
|
|
304
|
+
* timer warnings run; the shared transports stay open.
|
|
305
|
+
*
|
|
306
|
+
* To flush on SIGTERM/SIGINT, set the `gracefulShutdown` config option rather
|
|
307
|
+
* than writing your own signal handler; do not combine it with a manual
|
|
308
|
+
* handler that calls `process.exit`, which can cut the flush short.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* await logger.close(); // e.g. at the end of a script or a test
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
close(): Promise<void>;
|
|
316
|
+
private log;
|
|
317
|
+
/**
|
|
318
|
+
* Hot-path level check: a single Map lookup + integer compare.
|
|
319
|
+
* The level map and threshold are pre-built in _buildPerfCaches().
|
|
320
|
+
*/
|
|
321
|
+
private shouldLog;
|
|
322
|
+
/**
|
|
323
|
+
* Feature 3: Resolve the effective log level for this logger instance.
|
|
324
|
+
*
|
|
325
|
+
* Priority:
|
|
326
|
+
* 0. A level set at runtime with `setLevel()` (explicit programmatic call, wins over all below)
|
|
327
|
+
* 1. ENV `LOGIXIA_LEVEL_<NS_UPPER>` (e.g. LOGIXIA_LEVEL_DB for ns "db" or "db.queries")
|
|
328
|
+
* 2. Matching `namespaceLevels` config entry (longer pattern = more specific, wins)
|
|
329
|
+
* 3. Global `LOGIXIA_LEVEL` ENV override
|
|
330
|
+
* 4. `levelOptions.level` (resolved via Feature 5 in constructor)
|
|
331
|
+
*/
|
|
332
|
+
private resolveEffectiveLevel;
|
|
333
|
+
private formatLog;
|
|
334
|
+
private colorize;
|
|
335
|
+
/**
|
|
336
|
+
* Dispatch the entry to transports (each formats itself). Returns `void` when
|
|
337
|
+
* the write completes synchronously (console-only hot path) and a Promise only
|
|
338
|
+
* when a transport is genuinely async — so the caller awaits only when needed.
|
|
339
|
+
* Formatting for the no-transport fallback is done lazily, never on the
|
|
340
|
+
* transport path.
|
|
341
|
+
*/
|
|
342
|
+
private output;
|
|
343
|
+
/** Shared transport-failure handler: log internally, notify plugins, then fall
|
|
344
|
+
* back to a direct stdout/stderr write so the entry is never lost. */
|
|
345
|
+
private _handleOutputError;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a logger from `config`, with an optional default `context` label.
|
|
349
|
+
*
|
|
350
|
+
* Every key of `levelOptions.levels` that is not already a method becomes an
|
|
351
|
+
* async method on the returned logger, typed through the config, and routes to
|
|
352
|
+
* {@link LogixiaLogger.logLevel}.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const logger = createLogger({
|
|
357
|
+
* appName: 'api',
|
|
358
|
+
* levelOptions: { level: 'info', levels: { error: 0, warn: 1, info: 2, audit: 2 } },
|
|
359
|
+
* });
|
|
360
|
+
* await logger.audit('user exported data', { userId: 'u1' });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
declare function createLogger<T extends LoggerConfig<Record<string, number>>>(config: T, context?: string): LoggerWithLevels<T>;
|
|
364
|
+
export { globalPluginRegistry as a, PluginRegistry as i, createLogger as n, usePlugin as o, LogixiaPlugin as r, LogixiaLogger as t };
|
|
365
|
+
//# sourceMappingURL=logitron-logger-oEd6wNhf.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logitron-logger-oEd6wNhf.d.mts","names":[],"sources":["../src/plugin.ts","../src/core/logitron-logger.ts"],"mappings":";UAkCiB;;;;;;EAMf;;;;;;EAOA,kBAAkB;;;;;;;;;;;;EAalB,OAAO,OAAO,WAAW,kBAAkB,QAAQ;;;;;;EAOnD,SAAS,OAAO,OAAO,QAAQ,kBAAkB;;;;;;EAOjD,sBAAsB;;;;;;;cAUX;mBACM;;;;;EAMjB,SAAS,QAAQ;;EAiBjB,WAAW;;EAMX,IAAI;;MAKA;;;;;;EASE,SAAS,OAAO,WAAW,QAAQ;;;;;EAsBnC,WAAW,OAAO,OAAO,QAAQ,WAAW;;EAiB5C,iBAAiB;;;;;;;;;cA2BZ,sBAAoB;;;;;;;;;;;;;;;;;;iBAmBjB,UAAU,QAAQ;;;;;;;;;;;;;;cC7BrB,cACX,gBAAgB,aAAa,0BAA0B,yBAC5C;GAEV;UAEO;UACA;UACA;UACA;UACA;UACA;;mBAGS;;UAIT;;UAEA;;UAEA;;mBAES;;UAET;;UAEA;;UAEA;;;;;UAKA;;UAEA;;UAEA;;UAEA;;mBAES;;mBAEA;EAEL,YAAA,QAAQ,SAAS,kBAAkB,SAAS,cAAc;UAqG9D;UAiBA;;;;;UAqBA;;;;;;EA2HF,MAAM,yBAAyB,OAAO,OAAO,0BAA0B;;EAYvE,KAAK,iBAAiB,OAAO,0BAA0B;;EAKvD,KAAK,iBAAiB,OAAO,0BAA0B;;EAKvD,MAAM,iBAAiB,OAAO,0BAA0B;;EAKxD,MAAM,iBAAiB,OAAO,0BAA0B;;EAKxD,QAAQ,iBAAiB,OAAO,0BAA0B;;;;;;EAS1D,SAAS,eAAe,iBAAiB,OAAO,0BAA0B;;EAOhF,KAAK;;;;;;;;;;;;;EAgBC,QAAQ,gBAAgB;EAmBxB,UAAU,GAAG,eAAe,UAAU,QAAQ,KAAK,QAAQ;;;;;;;;;;;;EAyBjE,SAAS,OAAO;;;;;;EAuBhB,YAAY;UAIJ;;;;;UAQA;;;;;;;;;;;;;;;EA8BR,mBAAmB,QAAQ;;EAQ3B,qBAAqB,QAAQ;;EAM7B,sBAAsB;;EAKtB,WAAW;;EAKX;;EAOA,YAAY;;EASZ,aAAa;;EASb,eAAe;;EASf,iBAAiB;;EAmBjB;;EAQA;;EAMA;;EAMA,mBAAmB,qBAAqB;;EAMxC,mBAAmB;EAMnB;;EAMA;;;;;;;;;;;;;EAkBA,MAAM,iBAAiB,OAAO,0BAA0B;;;;;;;;;;;;EA0BxD,IAAI,QAAQ;;;;;EASZ,MAAM;;EAQA,SAAS;;EAKT,eAAe;IAAU;IAAkB,SAAS;;;;;;;;;;;;;;;;EAqBpD,SAAS;UAsBD;;;;;UA0GN;;;;;;;;;;;UAeA;UAwCA;UAgDA;;;;;;;;UAcA;;;UAuBM;;;;;;;;;;;;;;;;;;iBA+BA,aAAa,UAAU,aAAa,yBAClD,QAAQ,GACR,mBACC,iBAAiB"}
|
package/dist/middleware.d.mts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { u as IBaseLogger } from "./index-BPwEisy4.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/middleware/http-logger.d.ts
|
|
5
|
-
|
|
1
|
+
import { u as IBaseLogger } from "./index-xqaJtAZn.mjs";
|
|
6
2
|
interface HttpLoggerOptions {
|
|
7
3
|
/**
|
|
8
4
|
* Skip logging for a request. Called before any I/O.
|
|
@@ -28,10 +24,13 @@ interface HttpLoggerOptions {
|
|
|
28
24
|
*/
|
|
29
25
|
extraFields?: (req: IncomingRequest) => Record<string, unknown>;
|
|
30
26
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
27
|
+
* Header name, or list of names tried in order, to read the trace ID from.
|
|
28
|
+
* Default: the library-wide list (`DEFAULT_TRACE_HEADERS`: traceparent,
|
|
29
|
+
* x-trace-id, x-request-id, x-correlation-id, trace-id).
|
|
30
|
+
* If none is present, `request.id` is used when it is not a framework counter,
|
|
31
|
+
* otherwise a UUID is generated and shared with the logixia context helpers.
|
|
33
32
|
*/
|
|
34
|
-
traceIdHeader?: string;
|
|
33
|
+
traceIdHeader?: string | readonly string[];
|
|
35
34
|
/**
|
|
36
35
|
* Additional headers to redact from logged output. Merged with the defaults
|
|
37
36
|
* (authorization, cookie, set-cookie, x-api-key, proxy-authorization,
|
|
@@ -73,7 +72,7 @@ interface OutgoingResponse {
|
|
|
73
72
|
/**
|
|
74
73
|
* Create an Express / Connect compatible middleware that replaces Morgan.
|
|
75
74
|
*/
|
|
76
|
-
declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
|
|
75
|
+
export declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
|
|
77
76
|
interface FastifyInstance {
|
|
78
77
|
addHook: (name: string, fn: (req: unknown, reply: unknown, done: () => void) => void) => void;
|
|
79
78
|
}
|
|
@@ -85,9 +84,8 @@ interface FastifyInstance {
|
|
|
85
84
|
* await fastify.register(createFastifyPlugin(logger, { slowRequestThresholdMs: 500 }));
|
|
86
85
|
* ```
|
|
87
86
|
*/
|
|
88
|
-
declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
|
|
87
|
+
export declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
|
|
89
88
|
[x: symbol]: string | boolean;
|
|
90
89
|
};
|
|
91
|
-
|
|
92
|
-
export { type FastifyInstance, type HttpLoggerOptions, type IncomingRequest, type OutgoingResponse, createExpressMiddleware, createFastifyPlugin };
|
|
90
|
+
export type { FastifyInstance, HttpLoggerOptions, IncomingRequest, OutgoingResponse };
|
|
93
91
|
//# sourceMappingURL=middleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware/http-logger.ts"],"
|
|
1
|
+
{"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware/http-logger.ts"],"mappings":";UAgCiB;;;;;EAKf,QAAQ,KAAK;;;;;;EAMb;;EAEA;;;;;EAKA;;;;;EAKA,eAAe,KAAK,oBAAoB;;;;;;;;EAQxC;;;;;;EAMA;;;;;;EAMA;;;;;EAKA;;EAEA;;EAEA;;UAIe;EACf;EACA;EACA,UAAU;EACV;EACA;IAAW;;EACX;;UAGe;EACf;EACA,MAAM,eAAe;EACrB,QAAQ,eAAe;EACvB,aAAa;;;;;wBAkGC,wBACd,QAAQ,aACR,UAAS,qBACP,KAAK,iBAAiB,KAAK,kBAAkB;UAqFhC;EACf,UAAU,cAAc,KAAK,cAAc,gBAAgB;;;;;;;;;;wBAW7C,oBAAoB,QAAQ,aAAa,UAAS,sBAAsB,SAY/C,iBAAe,gBAAgB"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { u as IBaseLogger } from "./index-nZEeCr3X.js";
|
|
3
|
-
|
|
4
|
-
//#region src/middleware/http-logger.d.ts
|
|
5
|
-
|
|
1
|
+
import { u as IBaseLogger } from "./index-DwozbmB4.js";
|
|
6
2
|
interface HttpLoggerOptions {
|
|
7
3
|
/**
|
|
8
4
|
* Skip logging for a request. Called before any I/O.
|
|
@@ -28,10 +24,13 @@ interface HttpLoggerOptions {
|
|
|
28
24
|
*/
|
|
29
25
|
extraFields?: (req: IncomingRequest) => Record<string, unknown>;
|
|
30
26
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
27
|
+
* Header name, or list of names tried in order, to read the trace ID from.
|
|
28
|
+
* Default: the library-wide list (`DEFAULT_TRACE_HEADERS`: traceparent,
|
|
29
|
+
* x-trace-id, x-request-id, x-correlation-id, trace-id).
|
|
30
|
+
* If none is present, `request.id` is used when it is not a framework counter,
|
|
31
|
+
* otherwise a UUID is generated and shared with the logixia context helpers.
|
|
33
32
|
*/
|
|
34
|
-
traceIdHeader?: string;
|
|
33
|
+
traceIdHeader?: string | readonly string[];
|
|
35
34
|
/**
|
|
36
35
|
* Additional headers to redact from logged output. Merged with the defaults
|
|
37
36
|
* (authorization, cookie, set-cookie, x-api-key, proxy-authorization,
|
|
@@ -73,7 +72,7 @@ interface OutgoingResponse {
|
|
|
73
72
|
/**
|
|
74
73
|
* Create an Express / Connect compatible middleware that replaces Morgan.
|
|
75
74
|
*/
|
|
76
|
-
declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
|
|
75
|
+
export declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
|
|
77
76
|
interface FastifyInstance {
|
|
78
77
|
addHook: (name: string, fn: (req: unknown, reply: unknown, done: () => void) => void) => void;
|
|
79
78
|
}
|
|
@@ -85,9 +84,8 @@ interface FastifyInstance {
|
|
|
85
84
|
* await fastify.register(createFastifyPlugin(logger, { slowRequestThresholdMs: 500 }));
|
|
86
85
|
* ```
|
|
87
86
|
*/
|
|
88
|
-
declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
|
|
87
|
+
export declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
|
|
89
88
|
[x: symbol]: string | boolean;
|
|
90
89
|
};
|
|
91
|
-
|
|
92
|
-
export { type FastifyInstance, type HttpLoggerOptions, type IncomingRequest, type OutgoingResponse, createExpressMiddleware, createFastifyPlugin };
|
|
90
|
+
export type { FastifyInstance, HttpLoggerOptions, IncomingRequest, OutgoingResponse };
|
|
93
91
|
//# sourceMappingURL=middleware.d.ts.map
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","names":[],"sources":["../src/middleware/http-logger.ts"],"
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","names":[],"sources":["../src/middleware/http-logger.ts"],"mappings":";UAgCiB;;;;;EAKf,QAAQ,KAAK;;;;;;EAMb;;EAEA;;;;;EAKA;;;;;EAKA,eAAe,KAAK,oBAAoB;;;;;;;;EAQxC;;;;;;EAMA;;;;;;EAMA;;;;;EAKA;;EAEA;;EAEA;;UAIe;EACf;EACA;EACA,UAAU;EACV;EACA;IAAW;;EACX;;UAGe;EACf;EACA,MAAM,eAAe;EACrB,QAAQ,eAAe;EACvB,aAAa;;;;;wBAkGC,wBACd,QAAQ,aACR,UAAS,qBACP,KAAK,iBAAiB,KAAK,kBAAkB;UAqFhC;EACf,UAAU,cAAc,KAAK,cAAc,gBAAgB;;;;;;;;;;wBAW7C,oBAAoB,QAAQ,aAAa,UAAS,sBAAsB,SAY/C,iBAAe,gBAAgB"}
|
package/dist/middleware.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const DEFAULT_REDACT_HEADERS = [
|
|
7
|
-
"authorization",
|
|
8
|
-
"cookie",
|
|
9
|
-
"set-cookie",
|
|
10
|
-
"x-api-key",
|
|
11
|
-
"proxy-authorization",
|
|
12
|
-
"x-auth-token",
|
|
13
|
-
"x-access-token",
|
|
14
|
-
"x-csrf-token",
|
|
15
|
-
"x-amz-security-token"
|
|
16
|
-
];
|
|
17
|
-
const DEFAULT_REDACT_QUERY_PARAMS = [
|
|
18
|
-
"token",
|
|
19
|
-
"access_token",
|
|
20
|
-
"refresh_token",
|
|
21
|
-
"code",
|
|
22
|
-
"password",
|
|
23
|
-
"secret",
|
|
24
|
-
"api_key",
|
|
25
|
-
"apikey",
|
|
26
|
-
"key",
|
|
27
|
-
"signature",
|
|
28
|
-
"sig",
|
|
29
|
-
"auth"
|
|
30
|
-
];
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_request_trace = require("./request-trace-wTJdKp6-.js");
|
|
3
|
+
const require_internal_log = require("./internal-log-b0Vp4qrB.js");
|
|
4
|
+
const require_safe_stringify = require("./safe-stringify-DLz1Kz3o.js");
|
|
5
|
+
// src/middleware/http-logger.ts
|
|
31
6
|
function buildNameSet(defaults, extra) {
|
|
32
7
|
return new Set([...defaults, ...extra ?? []].map((n) => n.toLowerCase()));
|
|
33
8
|
}
|
|
@@ -68,13 +43,10 @@ function sanitizeHeaders(headers, redactSet) {
|
|
|
68
43
|
function fire(result) {
|
|
69
44
|
if (result && typeof result.catch === "function") result.catch((error) => require_internal_log.internalError("http-logger: log call failed", error));
|
|
70
45
|
}
|
|
71
|
-
function shortId() {
|
|
72
|
-
return Math.random().toString(36).slice(2, 10);
|
|
73
|
-
}
|
|
74
46
|
function resolveNameSets(options) {
|
|
75
47
|
return {
|
|
76
|
-
headers: buildNameSet(DEFAULT_REDACT_HEADERS, options.redactHeaders),
|
|
77
|
-
queryParams: buildNameSet(DEFAULT_REDACT_QUERY_PARAMS, options.redactQueryParams)
|
|
48
|
+
headers: buildNameSet(require_internal_log.DEFAULT_REDACT_HEADERS, options.redactHeaders),
|
|
49
|
+
queryParams: buildNameSet(require_internal_log.DEFAULT_REDACT_QUERY_PARAMS, options.redactQueryParams)
|
|
78
50
|
};
|
|
79
51
|
}
|
|
80
52
|
function buildBaseFields(req, traceId, options, { headers: redactSet, queryParams: paramSet }) {
|
|
@@ -93,16 +65,16 @@ function buildBaseFields(req, traceId, options, { headers: redactSet, queryParam
|
|
|
93
65
|
* Create an Express / Connect compatible middleware that replaces Morgan.
|
|
94
66
|
*/
|
|
95
67
|
function createExpressMiddleware(logger, options = {}) {
|
|
96
|
-
const { skip, logBody, bodyMaxBytes, traceIdHeader
|
|
68
|
+
const { skip, logBody, bodyMaxBytes, traceIdHeader, requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
|
|
97
69
|
const nameSets = resolveNameSets(options);
|
|
98
|
-
const
|
|
70
|
+
const traceHeaders = require_request_trace.resolveTraceHeaders(traceIdHeader);
|
|
99
71
|
return function logixiaHttpMiddleware(req, res, next) {
|
|
100
|
-
var
|
|
72
|
+
var _res$once, _res$once2;
|
|
101
73
|
if (skip === null || skip === void 0 ? void 0 : skip(req)) {
|
|
102
74
|
next();
|
|
103
75
|
return;
|
|
104
76
|
}
|
|
105
|
-
const traceId =
|
|
77
|
+
const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
|
|
106
78
|
const startMs = Date.now();
|
|
107
79
|
const baseFields = buildBaseFields(req, traceId, options, nameSets);
|
|
108
80
|
if (requestLevel !== "silent") fire(logger.logLevel(requestLevel, "request started", {
|
|
@@ -142,20 +114,18 @@ function createExpressMiddleware(logger, options = {}) {
|
|
|
142
114
|
* ```
|
|
143
115
|
*/
|
|
144
116
|
function createFastifyPlugin(logger, options = {}) {
|
|
145
|
-
const { skip, traceIdHeader
|
|
117
|
+
const { skip, traceIdHeader, requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
|
|
146
118
|
const nameSets = resolveNameSets(options);
|
|
147
|
-
const
|
|
119
|
+
const traceHeaders = require_request_trace.resolveTraceHeaders(traceIdHeader);
|
|
148
120
|
function logixiaFastifyPlugin(fastify, _opts, done) {
|
|
149
121
|
fastify.addHook("onRequest", (request, _reply, hookDone) => {
|
|
150
|
-
var _req$headers2;
|
|
151
122
|
const req = request;
|
|
152
123
|
if (skip === null || skip === void 0 ? void 0 : skip(req)) {
|
|
153
124
|
hookDone();
|
|
154
125
|
return;
|
|
155
126
|
}
|
|
156
|
-
const traceId =
|
|
127
|
+
const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
|
|
157
128
|
req._logixiaStart = Date.now();
|
|
158
|
-
req._logixiaId = traceId;
|
|
159
129
|
if (requestLevel !== "silent") fire(logger.logLevel(requestLevel, "request started", buildBaseFields(req, traceId, options, nameSets)));
|
|
160
130
|
hookDone();
|
|
161
131
|
});
|
|
@@ -168,7 +138,7 @@ function createFastifyPlugin(logger, options = {}) {
|
|
|
168
138
|
const rep = reply;
|
|
169
139
|
const duration = Date.now() - req._logixiaStart;
|
|
170
140
|
const status = rep.statusCode ?? 0;
|
|
171
|
-
const traceId = req
|
|
141
|
+
const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
|
|
172
142
|
const level = status >= 500 ? errorLevel : responseLevel;
|
|
173
143
|
const baseFields = buildBaseFields(req, traceId, options, nameSets);
|
|
174
144
|
fire(logger.logLevel(level, "request completed", {
|
|
@@ -262,8 +232,7 @@ function pruneValue(value, budget, depth, ancestors) {
|
|
|
262
232
|
ancestors.delete(value);
|
|
263
233
|
}
|
|
264
234
|
}
|
|
265
|
-
|
|
266
|
-
//#endregion
|
|
267
235
|
exports.createExpressMiddleware = createExpressMiddleware;
|
|
268
236
|
exports.createFastifyPlugin = createFastifyPlugin;
|
|
237
|
+
|
|
269
238
|
//# sourceMappingURL=middleware.js.map
|