logixia 2.0.0 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +172 -2597
  2. package/dist/async-context-2mbUKhcl.mjs +132 -0
  3. package/dist/async-context-2mbUKhcl.mjs.map +1 -0
  4. package/dist/async-context-DUFMDYAr.js +148 -0
  5. package/dist/async-context-DUFMDYAr.js.map +1 -0
  6. package/dist/{azure-monitor.transport-CrvfHd9C.js → azure-monitor.transport-Bu4S2I2q.js} +32 -20
  7. package/dist/azure-monitor.transport-Bu4S2I2q.js.map +1 -0
  8. package/dist/{azure-monitor.transport-Cn_3Usvu.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts} +3 -6
  9. package/dist/azure-monitor.transport-Bvf7Xegt.d.ts.map +1 -0
  10. package/dist/{azure-monitor.transport-CHnjVRF-.mjs → azure-monitor.transport-C1RWAumT.mjs} +27 -15
  11. package/dist/azure-monitor.transport-C1RWAumT.mjs.map +1 -0
  12. package/dist/{azure-monitor.transport-D7Da4RAb.d.mts → azure-monitor.transport-CbSHOnNX.d.mts} +3 -6
  13. package/dist/azure-monitor.transport-CbSHOnNX.d.mts.map +1 -0
  14. package/dist/azure.d.mts +1 -2
  15. package/dist/azure.d.ts +1 -2
  16. package/dist/azure.js +3 -6
  17. package/dist/azure.mjs +1 -6
  18. package/dist/{batch-buffer-PGvSgbmd.mjs → batch-buffer-BvXLDPlV.mjs} +21 -7
  19. package/dist/batch-buffer-BvXLDPlV.mjs.map +1 -0
  20. package/dist/{batch-buffer-BY-mRWIK.js → batch-buffer-C7Am4Mw-.js} +53 -40
  21. package/dist/batch-buffer-C7Am4Mw-.js.map +1 -0
  22. package/dist/browser.d.mts +47 -27
  23. package/dist/browser.d.mts.map +1 -1
  24. package/dist/browser.d.ts +47 -27
  25. package/dist/browser.d.ts.map +1 -1
  26. package/dist/browser.js +464 -62
  27. package/dist/browser.js.map +1 -1
  28. package/dist/browser.mjs +465 -65
  29. package/dist/browser.mjs.map +1 -1
  30. package/dist/{builder-0gEzRopq.mjs → builder-DhNhvOkt.mjs} +307 -246
  31. package/dist/builder-DhNhvOkt.mjs.map +1 -0
  32. package/dist/{builder-D44QktIo.js → builder-yFvJrz7o.js} +435 -399
  33. package/dist/builder-yFvJrz7o.js.map +1 -0
  34. package/dist/cli/index.js +216 -125
  35. package/dist/cloudwatch.d.mts +1 -2
  36. package/dist/cloudwatch.d.ts +1 -2
  37. package/dist/cloudwatch.js +3 -7
  38. package/dist/cloudwatch.mjs +1 -7
  39. package/dist/{cloudwatch.transport-DsEq633o.d.ts → cloudwatch.transport-CQyT6U91.d.ts} +2 -6
  40. package/dist/cloudwatch.transport-CQyT6U91.d.ts.map +1 -0
  41. package/dist/{cloudwatch.transport-BO1ahxw-.js → cloudwatch.transport-Ch1Uae-0.js} +61 -36
  42. package/dist/cloudwatch.transport-Ch1Uae-0.js.map +1 -0
  43. package/dist/{cloudwatch.transport-UlyZFWMn.d.mts → cloudwatch.transport-CjVrI6S4.d.mts} +2 -6
  44. package/dist/cloudwatch.transport-CjVrI6S4.d.mts.map +1 -0
  45. package/dist/{cloudwatch.transport-DZ6ies7g.mjs → cloudwatch.transport-DZqF2xZO.mjs} +54 -28
  46. package/dist/cloudwatch.transport-DZqF2xZO.mjs.map +1 -0
  47. package/dist/{coerce.utils-Cu6IUTgX.mjs → coerce.utils-B_rEudCn.mjs} +3 -4
  48. package/dist/{coerce.utils-Cu6IUTgX.mjs.map → coerce.utils-B_rEudCn.mjs.map} +1 -1
  49. package/dist/{coerce.utils-B-LilukN.js → coerce.utils-C1C5sIX0.js} +8 -10
  50. package/dist/{coerce.utils-B-LilukN.js.map → coerce.utils-C1C5sIX0.js.map} +1 -1
  51. package/dist/correlation.d.mts +15 -69
  52. package/dist/correlation.d.mts.map +1 -1
  53. package/dist/correlation.d.ts +15 -69
  54. package/dist/correlation.d.ts.map +1 -1
  55. package/dist/correlation.js +69 -20
  56. package/dist/correlation.js.map +1 -1
  57. package/dist/correlation.mjs +67 -17
  58. package/dist/correlation.mjs.map +1 -1
  59. package/dist/{entry-fields-BvOLFlJ4.js → entry-fields-BSLkzw18.js} +16 -13
  60. package/dist/entry-fields-BSLkzw18.js.map +1 -0
  61. package/dist/{entry-fields-BJkuPnIg.mjs → entry-fields-J1OBi24o.mjs} +11 -7
  62. package/dist/entry-fields-J1OBi24o.mjs.map +1 -0
  63. package/dist/gcp.d.mts +1 -2
  64. package/dist/gcp.d.ts +1 -2
  65. package/dist/gcp.js +3 -7
  66. package/dist/gcp.mjs +1 -7
  67. package/dist/{gcp.transport-B7oc97sG.d.ts → gcp.transport-BCIvdFV-.d.ts} +5 -8
  68. package/dist/gcp.transport-BCIvdFV-.d.ts.map +1 -0
  69. package/dist/{gcp.transport-GrJurKo8.d.mts → gcp.transport-D9SdLPwP.d.mts} +5 -8
  70. package/dist/gcp.transport-D9SdLPwP.d.mts.map +1 -0
  71. package/dist/{gcp.transport-DBX5TPIy.mjs → gcp.transport-DVCmnA3b.mjs} +59 -16
  72. package/dist/gcp.transport-DVCmnA3b.mjs.map +1 -0
  73. package/dist/{gcp.transport-CHV8MGgz.js → gcp.transport-Dy2Lf8FI.js} +64 -22
  74. package/dist/gcp.transport-Dy2Lf8FI.js.map +1 -0
  75. package/dist/http-shapes-BnBkJcid.d.mts +32 -0
  76. package/dist/http-shapes-BnBkJcid.d.mts.map +1 -0
  77. package/dist/http-shapes-BnBkJcid.d.ts +32 -0
  78. package/dist/http-shapes-BnBkJcid.d.ts.map +1 -0
  79. package/dist/{index-3mw5gaCw.d.mts → index-BSTtFcQ6.d.mts} +142 -13
  80. package/dist/index-BSTtFcQ6.d.mts.map +1 -0
  81. package/dist/{index-DhIoploR.d.ts → index-CFDGkI8n.d.ts} +142 -13
  82. package/dist/index-CFDGkI8n.d.ts.map +1 -0
  83. package/dist/index.d.mts +114 -217
  84. package/dist/index.d.mts.map +1 -1
  85. package/dist/index.d.ts +113 -216
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +182 -279
  88. package/dist/index.js.map +1 -1
  89. package/dist/index.mjs +160 -256
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/internal-log-Bg4V1cPg.mjs +170 -0
  92. package/dist/internal-log-Bg4V1cPg.mjs.map +1 -0
  93. package/dist/internal-log-By4Govmu.js +223 -0
  94. package/dist/internal-log-By4Govmu.js.map +1 -0
  95. package/dist/{logitron-logger-UVeN-mQm.d.ts → logitron-logger-D22Yb61K.d.mts} +121 -100
  96. package/dist/logitron-logger-D22Yb61K.d.mts.map +1 -0
  97. package/dist/{logitron-logger-BFDSO8Io.d.mts → logitron-logger-D_MYYrQt.d.ts} +121 -100
  98. package/dist/logitron-logger-D_MYYrQt.d.ts.map +1 -0
  99. package/dist/middleware.d.mts +13 -28
  100. package/dist/middleware.d.mts.map +1 -1
  101. package/dist/middleware.d.ts +13 -28
  102. package/dist/middleware.d.ts.map +1 -1
  103. package/dist/middleware.js +20 -81
  104. package/dist/middleware.js.map +1 -1
  105. package/dist/middleware.mjs +17 -79
  106. package/dist/middleware.mjs.map +1 -1
  107. package/dist/nest.d.mts +37 -48
  108. package/dist/nest.d.mts.map +1 -1
  109. package/dist/nest.d.ts +37 -48
  110. package/dist/nest.d.ts.map +1 -1
  111. package/dist/nest.js +124 -135
  112. package/dist/nest.js.map +1 -1
  113. package/dist/nest.mjs +69 -78
  114. package/dist/nest.mjs.map +1 -1
  115. package/dist/{transport.manager-BiuCAJd2.mjs → otel-Dt5riXuE.mjs} +275 -117
  116. package/dist/otel-Dt5riXuE.mjs.map +1 -0
  117. package/dist/{transport.manager-CXbKKdVE.js → otel-DyeH6DVR.js} +373 -178
  118. package/dist/otel-DyeH6DVR.js.map +1 -0
  119. package/dist/own-property-BWkibepN.js +40 -0
  120. package/dist/own-property-BWkibepN.js.map +1 -0
  121. package/dist/own-property-CjFw9qwZ.mjs +29 -0
  122. package/dist/own-property-CjFw9qwZ.mjs.map +1 -0
  123. package/dist/{trace.utils-CvXgaiQT.mjs → request-trace-BgNykH9M.mjs} +40 -9
  124. package/dist/request-trace-BgNykH9M.mjs.map +1 -0
  125. package/dist/{trace.utils-DpBOLDtq.js → request-trace-ByujsUZk.js} +117 -77
  126. package/dist/request-trace-ByujsUZk.js.map +1 -0
  127. package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
  128. package/dist/{safe-stringify-DJ66tW5I.mjs → safe-stringify-B5p5ktFe.mjs} +39 -15
  129. package/dist/safe-stringify-B5p5ktFe.mjs.map +1 -0
  130. package/dist/{safe-stringify-DWo3aZp_.js → safe-stringify-J3sh-7YM.js} +59 -36
  131. package/dist/safe-stringify-J3sh-7YM.js.map +1 -0
  132. package/dist/{search-C4V0OMEn.js → search-CRjhHxe9.js} +319 -92
  133. package/dist/search-CRjhHxe9.js.map +1 -0
  134. package/dist/{search-CNh9uVwR.d.ts → search-DA3ft3X5.d.mts} +5 -22
  135. package/dist/search-DA3ft3X5.d.mts.map +1 -0
  136. package/dist/{search-BFbu_oVn.mjs → search-DAXKE-P9.mjs} +289 -62
  137. package/dist/search-DAXKE-P9.mjs.map +1 -0
  138. package/dist/{search-DXANsQ2n.d.mts → search-DEl3Pe47.d.ts} +5 -22
  139. package/dist/search-DEl3Pe47.d.ts.map +1 -0
  140. package/dist/search.d.mts +2 -4
  141. package/dist/search.d.ts +2 -4
  142. package/dist/search.js +3 -4
  143. package/dist/search.mjs +1 -4
  144. package/dist/secret-config-CmK2wVkr.js +272 -0
  145. package/dist/secret-config-CmK2wVkr.js.map +1 -0
  146. package/dist/secret-config-Dhb6pqTU.mjs +210 -0
  147. package/dist/secret-config-Dhb6pqTU.mjs.map +1 -0
  148. package/dist/{slack.transport-CXjQYOes.d.ts → slack.transport-BDyENuR0.d.mts} +56 -9
  149. package/dist/slack.transport-BDyENuR0.d.mts.map +1 -0
  150. package/dist/{slack.transport-Bzw7sucI.mjs → slack.transport-BTEwsREY.mjs} +263 -31
  151. package/dist/slack.transport-BTEwsREY.mjs.map +1 -0
  152. package/dist/{slack.transport-BZzoXDPn.d.mts → slack.transport-C6E0l4kw.d.ts} +56 -9
  153. package/dist/slack.transport-C6E0l4kw.d.ts.map +1 -0
  154. package/dist/{slack.transport-BfJRouB2.js → slack.transport-UbYvOdKx.js} +286 -42
  155. package/dist/slack.transport-UbYvOdKx.js.map +1 -0
  156. package/dist/testing.d.mts +13 -11
  157. package/dist/testing.d.mts.map +1 -1
  158. package/dist/testing.d.ts +13 -11
  159. package/dist/testing.d.ts.map +1 -1
  160. package/dist/testing.js +41 -7
  161. package/dist/testing.js.map +1 -1
  162. package/dist/testing.mjs +40 -6
  163. package/dist/testing.mjs.map +1 -1
  164. package/dist/{transport.types-CGoHpWQR.d.ts → transport.types-CzJq4IrF.d.mts} +14 -5
  165. package/dist/transport.types-CzJq4IrF.d.mts.map +1 -0
  166. package/dist/{transport.types-BMnurPcc.d.mts → transport.types-CzJq4IrF.d.ts} +14 -5
  167. package/dist/transport.types-CzJq4IrF.d.ts.map +1 -0
  168. package/dist/transports.d.mts +39 -41
  169. package/dist/transports.d.mts.map +1 -1
  170. package/dist/transports.d.ts +39 -41
  171. package/dist/transports.d.ts.map +1 -1
  172. package/dist/transports.js +19 -22
  173. package/dist/transports.mjs +7 -13
  174. package/dist/worker-entry.js +438 -107
  175. package/dist/worker.d.mts +1 -2
  176. package/dist/worker.d.ts +1 -2
  177. package/dist/worker.js +3 -4
  178. package/dist/worker.mjs +1 -4
  179. package/dist/{worker.transport-JvGPog3C.d.mts → worker.transport-B9mCQSM1.d.ts} +7 -6
  180. package/dist/worker.transport-B9mCQSM1.d.ts.map +1 -0
  181. package/dist/{worker.transport-CdzSZJmw.d.ts → worker.transport-Bl8lFRck.d.mts} +7 -6
  182. package/dist/worker.transport-Bl8lFRck.d.mts.map +1 -0
  183. package/dist/{worker.transport-lPxO2MVL.mjs → worker.transport-BmmOKb1-.mjs} +43 -10
  184. package/dist/worker.transport-BmmOKb1-.mjs.map +1 -0
  185. package/dist/{worker.transport-BdPxu3PN.js → worker.transport-DxxbqQCG.js} +48 -15
  186. package/dist/worker.transport-DxxbqQCG.js.map +1 -0
  187. package/package.json +51 -75
  188. package/dist/async-context-BzJrbfQs.mjs +0 -72
  189. package/dist/async-context-BzJrbfQs.mjs.map +0 -1
  190. package/dist/async-context-DyQQYq3I.js +0 -92
  191. package/dist/async-context-DyQQYq3I.js.map +0 -1
  192. package/dist/azure-monitor.transport-CHnjVRF-.mjs.map +0 -1
  193. package/dist/azure-monitor.transport-Cn_3Usvu.d.ts.map +0 -1
  194. package/dist/azure-monitor.transport-CrvfHd9C.js.map +0 -1
  195. package/dist/azure-monitor.transport-D7Da4RAb.d.mts.map +0 -1
  196. package/dist/batch-buffer-BY-mRWIK.js.map +0 -1
  197. package/dist/batch-buffer-PGvSgbmd.mjs.map +0 -1
  198. package/dist/builder-0gEzRopq.mjs.map +0 -1
  199. package/dist/builder-D44QktIo.js.map +0 -1
  200. package/dist/chunk-DLSkYcPk.mjs +0 -7
  201. package/dist/chunk-nOFOJqeH.js +0 -30
  202. package/dist/cloudwatch.transport-BO1ahxw-.js.map +0 -1
  203. package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +0 -1
  204. package/dist/cloudwatch.transport-DsEq633o.d.ts.map +0 -1
  205. package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +0 -1
  206. package/dist/entry-fields-BJkuPnIg.mjs.map +0 -1
  207. package/dist/entry-fields-BvOLFlJ4.js.map +0 -1
  208. package/dist/gcp.transport-B7oc97sG.d.ts.map +0 -1
  209. package/dist/gcp.transport-CHV8MGgz.js.map +0 -1
  210. package/dist/gcp.transport-DBX5TPIy.mjs.map +0 -1
  211. package/dist/gcp.transport-GrJurKo8.d.mts.map +0 -1
  212. package/dist/index-3mw5gaCw.d.mts.map +0 -1
  213. package/dist/index-DhIoploR.d.ts.map +0 -1
  214. package/dist/internal-log-BUJYMZbE.js +0 -70
  215. package/dist/internal-log-BUJYMZbE.js.map +0 -1
  216. package/dist/internal-log-Cm8SOWSV.mjs +0 -52
  217. package/dist/internal-log-Cm8SOWSV.mjs.map +0 -1
  218. package/dist/logitron-logger-BFDSO8Io.d.mts.map +0 -1
  219. package/dist/logitron-logger-UVeN-mQm.d.ts.map +0 -1
  220. package/dist/safe-stringify-DJ66tW5I.mjs.map +0 -1
  221. package/dist/safe-stringify-DWo3aZp_.js.map +0 -1
  222. package/dist/search-BFbu_oVn.mjs.map +0 -1
  223. package/dist/search-C4V0OMEn.js.map +0 -1
  224. package/dist/search-CNh9uVwR.d.ts.map +0 -1
  225. package/dist/search-DXANsQ2n.d.mts.map +0 -1
  226. package/dist/slack.transport-BZzoXDPn.d.mts.map +0 -1
  227. package/dist/slack.transport-BfJRouB2.js.map +0 -1
  228. package/dist/slack.transport-Bzw7sucI.mjs.map +0 -1
  229. package/dist/slack.transport-CXjQYOes.d.ts.map +0 -1
  230. package/dist/trace.utils-CvXgaiQT.mjs.map +0 -1
  231. package/dist/trace.utils-DpBOLDtq.js.map +0 -1
  232. package/dist/transport.manager-BiuCAJd2.mjs.map +0 -1
  233. package/dist/transport.manager-CXbKKdVE.js.map +0 -1
  234. package/dist/transport.types-BMnurPcc.d.mts.map +0 -1
  235. package/dist/transport.types-CGoHpWQR.d.ts.map +0 -1
  236. package/dist/worker.transport-BdPxu3PN.js.map +0 -1
  237. package/dist/worker.transport-CdzSZJmw.d.ts.map +0 -1
  238. package/dist/worker.transport-JvGPog3C.d.mts.map +0 -1
  239. package/dist/worker.transport-lPxO2MVL.mjs.map +0 -1
@@ -1,105 +1,17 @@
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-3mw5gaCw.mjs";
2
-
3
- //#region src/plugin.d.ts
4
-
5
- interface LogixiaPlugin {
6
- /**
7
- * Unique plugin name.
8
- * logixia uses this to prevent duplicate registration of the same plugin
9
- * on the same logger instance.
10
- */
11
- name: string;
12
- /**
13
- * Called once immediately after `logger.use(plugin)` is called.
14
- * Use for one-time setup (open connections, allocate buffers, etc.).
15
- * Async `onInit` errors are silently swallowed to avoid blocking the logger.
16
- */
17
- onInit?(): void | Promise<void>;
18
- /**
19
- * Called for every log entry **after** PII redaction and **before** transport
20
- * dispatch. Plugins run in registration order; each receives the (possibly
21
- * modified) output of the previous plugin.
22
- *
23
- * - Return the entry (modified or unchanged) to continue processing.
24
- * - Return `null` to **drop** the entry — no transport will receive it.
25
- *
26
- * Errors thrown inside `onLog` are swallowed so a buggy plugin cannot crash
27
- * logging; the chain continues with the previous (un-transformed) entry.
28
- */
29
- onLog?(entry: LogEntry): LogEntry | null | Promise<LogEntry | null>;
30
- /**
31
- * Called when a transport write fails (after any configured retries).
32
- * Useful for routing transport errors to an alerting or metrics system.
33
- * Errors thrown inside `onError` are silently swallowed.
34
- */
35
- onError?(error: Error, entry?: LogEntry): void | Promise<void>;
36
- /**
37
- * Called when the logger is closed via `logger.close()` or the process
38
- * receives a shutdown signal (when `gracefulShutdown` is enabled).
39
- * Errors thrown inside `onShutdown` are silently swallowed.
40
- */
41
- onShutdown?(): void | Promise<void>;
42
- }
43
- /**
44
- * Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
45
- * events to them. One registry is created per logger instance; a global
46
- * singleton is also exported for process-wide registration.
47
- */
48
- declare class PluginRegistry {
49
- private readonly _plugins;
50
- /**
51
- * Register a plugin. Silently skips if a plugin with the same `name` is
52
- * already registered on this registry.
53
- */
54
- register(plugin: LogixiaPlugin): void;
55
- /** Remove a previously registered plugin by name. No-op if not found. */
56
- unregister(name: string): void;
57
- /** Returns `true` if a plugin with the given name is registered. */
58
- has(name: string): boolean;
59
- /** Number of currently registered plugins. */
60
- get size(): number;
61
- /**
62
- * Run all `onLog` hooks in order.
63
- * Returns `null` if any plugin cancels the entry; otherwise returns the
64
- * (possibly transformed) entry.
65
- */
66
- runOnLog(entry: LogEntry): Promise<LogEntry | null>;
67
- /**
68
- * Notify all `onError` hooks.
69
- * Errors thrown inside hooks are swallowed to prevent error cascades.
70
- */
71
- runOnError(error: Error, entry?: LogEntry): Promise<void>;
72
- /** Run all `onShutdown` hooks concurrently. Hook errors are swallowed. */
73
- runOnShutdown(): Promise<void>;
74
- }
1
+ import { C as LogixiaLoggerInstance, L as LogixiaPlugin, b as LoggerConfig, p as ILoggerDefault, w as NamespaceLevels, x as LoggerWithLevels, y as LogLevelString } from "./index-CFDGkI8n.js";
75
2
  /**
76
- * Module-level singleton registry.
77
- *
78
- * Plugins registered here are automatically copied into every **new** logger
79
- * instance created after the registration. Already-created loggers are not
80
- * retroactively affected — use `logger.use(plugin)` for per-instance control.
81
- */
82
- declare const globalPluginRegistry: PluginRegistry;
83
- /**
84
- * Register a plugin in the global registry so it applies to every future
85
- * logger instance.
3
+ * The logixia logger. Create instances with {@link createLogger} so that custom
4
+ * levels from `levelOptions.levels` also become methods.
86
5
  *
87
6
  * @example
88
7
  * ```ts
89
- * import { usePlugin } from 'logixia';
90
- *
91
- * usePlugin({
92
- * name: 'audit-sink',
93
- * onLog(entry) {
94
- * if (entry.level === 'error') auditQueue.push(entry);
95
- * return entry;
96
- * },
97
- * });
8
+ * const logger = createLogger({ appName: 'api', environment: 'production' });
9
+ * await logger.info('Server started', { port: 3000 });
10
+ * const req = logger.child('RequestHandler', { requestId: 'r-1' });
11
+ * await req.error(new Error('boom'));
12
+ * await logger.close(); // flush buffered transports before exit
98
13
  * ```
99
14
  */
100
- declare function usePlugin(plugin: LogixiaPlugin): void;
101
- //#endregion
102
- //#region src/core/logitron-logger.d.ts
103
15
  declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>> = LoggerConfig> implements ILoggerDefault {
104
16
  [K: string]: any;
105
17
  private config;
@@ -114,6 +26,8 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
114
26
  private _levelValues;
115
27
  /** Numeric threshold for the currently active log level. */
116
28
  private _minLevelValue;
29
+ /** Level set via setLevel(); outranks every other level source until the process ends. */
30
+ private _runtimeLevel;
117
31
  /** `source=value` pairs already reported as unknown levels — warn once per logger. */
118
32
  private readonly _warnedInvalidLevels;
119
33
  /** Pre-built ANSI color codes to avoid recreating the object in colorize(). */
@@ -137,6 +51,10 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
137
51
  private readonly _pluginRegistry;
138
52
  /** Set on loggers created by child(); they borrow the root's transports, sampler and plugins. */
139
53
  private readonly _parent;
54
+ /** Namespace level map shared by a logger and all its children; `version` bumps on every change. */
55
+ private readonly _nsStore;
56
+ /** Store version this logger's threshold was last computed against. */
57
+ private _nsSeenVersion;
140
58
  constructor(config: TConfig, context?: string, parent?: LogixiaLogger<TConfig>);
141
59
  private setupGracefulShutdown;
142
60
  private createCustomLevelMethods;
@@ -145,17 +63,61 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
145
63
  * Keeps the actual log() call free of allocations in the common case.
146
64
  */
147
65
  private _buildPerfCaches;
66
+ /**
67
+ * Log at `error` level. An `Error` is logged with its message and serialized
68
+ * (name, message, stack) under `data.error`; a string is logged as-is.
69
+ * `data` is merged into the entry payload.
70
+ */
148
71
  error(messageOrError: string | Error, data?: Record<string, unknown>): Promise<void>;
72
+ /** Log `message` at `warn` level; `data` is merged into the entry payload. */
149
73
  warn(message: string, data?: Record<string, unknown>): Promise<void>;
74
+ /** Log `message` at `info` level; `data` is merged into the entry payload. */
150
75
  info(message: string, data?: Record<string, unknown>): Promise<void>;
76
+ /** Log `message` at `debug` level; `data` is merged into the entry payload. */
151
77
  debug(message: string, data?: Record<string, unknown>): Promise<void>;
78
+ /** Log `message` at `trace` level; `data` is merged into the entry payload. */
152
79
  trace(message: string, data?: Record<string, unknown>): Promise<void>;
80
+ /** Log `message` at `verbose` level; `data` is merged into the entry payload. */
153
81
  verbose(message: string, data?: Record<string, unknown>): Promise<void>;
82
+ /**
83
+ * Log at an arbitrary level name, including custom levels. Levels below the
84
+ * active threshold are dropped, as are level names that are not registered
85
+ * in `levelOptions.levels` (and are not built-in).
86
+ */
154
87
  logLevel(level: string, message: string, data?: Record<string, unknown>): Promise<void>;
88
+ /** Start a named timer; finish it with {@link timeEnd}. Reusing a label restarts it. */
155
89
  time(label: string): void;
90
+ /**
91
+ * Stop the timer `label`, log its duration at `info` level, and return the
92
+ * elapsed milliseconds. Logs a `warn` and returns `undefined` if the timer
93
+ * does not exist.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * logger.time('db');
98
+ * await query();
99
+ * const ms = await logger.timeEnd('db');
100
+ * ```
101
+ */
156
102
  timeEnd(label: string): Promise<number | undefined>;
157
103
  timeAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
104
+ /**
105
+ * Change the minimum log level at runtime. The override outranks
106
+ * `LOGIXIA_LEVEL`, `LOGIXIA_LEVEL_<NS>` and `namespaceLevels`, and survives
107
+ * later changes to fields or namespace levels. Unknown level names are
108
+ * ignored with a warning and the current level is kept.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * logger.setLevel('debug');
113
+ * ```
114
+ */
158
115
  setLevel(level: LogLevelString): void;
116
+ /**
117
+ * Return the configured minimum log level, not the per-namespace effective
118
+ * one. Without `setLevel()` it is `LOGIXIA_LEVEL`, else `levelOptions.level`,
119
+ * else a `NODE_ENV` default (`debug` in development, `warn` in test), else `info`.
120
+ */
159
121
  getLevel(): LogLevelString;
160
122
  private _validLevelList;
161
123
  /**
@@ -171,6 +133,10 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
171
133
  * (flip a module's verbosity live to chase a bug without raising global
172
134
  * volume). The new map fully replaces the previous one.
173
135
  *
136
+ * The map is shared by a logger and all its `child()` loggers: calling this on
137
+ * a child changes the whole family, and existing children pick the change up on
138
+ * their next log call.
139
+ *
174
140
  * @example
175
141
  * ```ts
176
142
  * // Turn on debug for the DB layer only, live:
@@ -182,22 +148,45 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
182
148
  patchNamespaceLevels(levels: NamespaceLevels): void;
183
149
  /** Return a copy of the current per-namespace level map. */
184
150
  getNamespaceLevels(): NamespaceLevels;
151
+ private _syncNamespaceLevels;
152
+ /** Set the context label (e.g. a class or module name) attached to every subsequent entry. */
185
153
  setContext(context: string): void;
154
+ /** Return the current context label, or `undefined` if none is set. */
186
155
  getContext(): string | undefined;
156
+ /** Show `fieldName` in log output, overriding the config for this logger instance. */
187
157
  enableField(fieldName: string): void;
158
+ /** Hide `fieldName` from log output, overriding the config for this logger instance. */
188
159
  disableField(fieldName: string): void;
160
+ /** Whether `fieldName` is currently shown: runtime override first, then config, default `true`. */
189
161
  isFieldEnabled(fieldName: string): boolean;
162
+ /** Return the visibility (`true` = shown) of every standard log field. */
190
163
  getFieldState(): Record<string, boolean>;
164
+ /** Drop all runtime enable/disable overrides so field visibility follows the config again. */
191
165
  resetFieldState(): void;
192
166
  /** @deprecated No-op. Library code never prompts on stdin; use setTransportLevels(). */
193
167
  enableTransportLevelPrompting(): void;
194
168
  /** @deprecated No-op. */
195
169
  disableTransportLevelPrompting(): void;
170
+ /** Restrict `transportId` to only the given `levels`. Warns if no transports are configured. */
196
171
  setTransportLevels(transportId: string, levels: string[]): void;
172
+ /** Return the levels `transportId` is restricted to, or `undefined` if it has none. */
197
173
  getTransportLevels(transportId: string): string[] | undefined;
198
174
  clearTransportLevelPreferences(): void;
175
+ /** Return the identifiers of the configured transports (empty if none). */
199
176
  getAvailableTransports(): string[];
200
- child(context: string, data?: Record<string, unknown>): ILogger;
177
+ /**
178
+ * Create a child logger with its own `context` that shares this logger's
179
+ * configuration and transports. `data` is merged into the bound fields
180
+ * inherited from this logger and added to every entry the child writes.
181
+ * Closing a child does not close the shared transports.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const req = logger.child('Checkout', { requestId: 'r-42' });
186
+ * await req.info('started'); // entry includes requestId
187
+ * ```
188
+ */
189
+ child(context: string, data?: Record<string, unknown>): LogixiaLoggerInstance;
201
190
  /**
202
191
  * Register a plugin on this logger instance.
203
192
  *
@@ -215,11 +204,27 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
215
204
  * No-op if the plugin is not registered on this instance.
216
205
  */
217
206
  unuse(pluginName: string): this;
207
+ /** Flush buffered entries in all transports without closing them. */
218
208
  flush(): Promise<void>;
209
+ /** Report whether the transports are healthy; `healthy: false` if no transport manager exists. */
219
210
  healthCheck(): Promise<{
220
211
  healthy: boolean;
221
212
  details: Record<string, unknown>;
222
213
  }>;
214
+ /**
215
+ * Warn about timers that were never ended, then flush and close all transports,
216
+ * stop the sampler and run plugin shutdown hooks. On a child logger only the
217
+ * timer warnings run; the shared transports stay open.
218
+ *
219
+ * To flush on SIGTERM/SIGINT, set the `gracefulShutdown` config option rather
220
+ * than writing your own signal handler; do not combine it with a manual
221
+ * handler that calls `process.exit`, which can cut the flush short.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * await logger.close(); // e.g. at the end of a script or a test
226
+ * ```
227
+ */
223
228
  close(): Promise<void>;
224
229
  private log;
225
230
  /**
@@ -231,6 +236,7 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
231
236
  * Feature 3: Resolve the effective log level for this logger instance.
232
237
  *
233
238
  * Priority:
239
+ * 0. A level set at runtime with `setLevel()` (explicit programmatic call, wins over all below)
234
240
  * 1. ENV `LOGIXIA_LEVEL_<NS_UPPER>` (e.g. LOGIXIA_LEVEL_DB for ns "db" or "db.queries")
235
241
  * 2. Matching `namespaceLevels` config entry (longer pattern = more specific, wins)
236
242
  * 3. Global `LOGIXIA_LEVEL` ENV override
@@ -251,7 +257,22 @@ declare class LogixiaLogger<TConfig extends LoggerConfig<Record<string, number>>
251
257
  * back to a direct stdout/stderr write so the entry is never lost. */
252
258
  private _handleOutputError;
253
259
  }
260
+ /**
261
+ * Create a logger from `config`, with an optional default `context` label.
262
+ *
263
+ * Every key of `levelOptions.levels` that is not already a method becomes an
264
+ * async method on the returned logger, typed through the config, and routes to
265
+ * {@link LogixiaLogger.logLevel}.
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * const logger = createLogger({
270
+ * appName: 'api',
271
+ * levelOptions: { level: 'info', levels: { error: 0, warn: 1, info: 2, audit: 2 } },
272
+ * });
273
+ * await logger.audit('user exported data', { userId: 'u1' });
274
+ * ```
275
+ */
254
276
  declare function createLogger<T extends LoggerConfig<Record<string, number>>>(config: T, context?: string): LoggerWithLevels<T>;
255
- //#endregion
256
- export { globalPluginRegistry as a, PluginRegistry as i, createLogger as n, usePlugin as o, LogixiaPlugin as r, LogixiaLogger as t };
257
- //# sourceMappingURL=logitron-logger-BFDSO8Io.d.mts.map
277
+ export { createLogger as n, LogixiaLogger as t };
278
+ //# sourceMappingURL=logitron-logger-D_MYYrQt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logitron-logger-D_MYYrQt.d.ts","names":[],"sources":["../src/core/logitron-logger.ts"],"mappings":";;;;;;;;;;;;;;cAyLa,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;;mBAEA;;UAET;EAEI,YAAA,QAAQ,SAAS,kBAAkB,SAAS,cAAc;UA4G9D;UAiBA;;;;;UAsBA;;;;;;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;;;;;;;;;;;;;;;;;;;EAkCR,mBAAmB,QAAQ;;EAS3B,qBAAqB,QAAQ;;EAO7B,sBAAsB;UAId;;EAMR,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;;;;;UA8GN;;;;;;;;;;;UAgBA;UAwCA;UAgDA;;;;;;;;UAcA;;;UAuBM;;;;;;;;;;;;;;;;;;iBA+BA,aAAa,UAAU,aAAa,yBAClD,QAAQ,GACR,mBACC,iBAAiB"}
@@ -1,8 +1,5 @@
1
- import "./transport.types-BMnurPcc.mjs";
2
- import { u as IBaseLogger } from "./index-3mw5gaCw.mjs";
3
-
4
- //#region src/middleware/http-logger.d.ts
5
-
1
+ import { n as HttpResponseShape, t as HttpRequestShape } from "./http-shapes-BnBkJcid.mjs";
2
+ import { u as IBaseLogger } from "./index-BSTtFcQ6.mjs";
6
3
  interface HttpLoggerOptions {
7
4
  /**
8
5
  * Skip logging for a request. Called before any I/O.
@@ -28,10 +25,13 @@ interface HttpLoggerOptions {
28
25
  */
29
26
  extraFields?: (req: IncomingRequest) => Record<string, unknown>;
30
27
  /**
31
- * Trace ID header. Default: 'x-trace-id'.
32
- * If the header is absent, a short random ID is generated.
28
+ * Header name, or list of names tried in order, to read the trace ID from.
29
+ * Default: the library-wide list (`DEFAULT_TRACE_HEADERS`: traceparent,
30
+ * x-trace-id, x-request-id, x-correlation-id, trace-id).
31
+ * If none is present, `request.id` is used when it is not a framework counter,
32
+ * otherwise a UUID is generated and shared with the logixia context helpers.
33
33
  */
34
- traceIdHeader?: string;
34
+ traceIdHeader?: string | readonly string[];
35
35
  /**
36
36
  * Additional headers to redact from logged output. Merged with the defaults
37
37
  * (authorization, cookie, set-cookie, x-api-key, proxy-authorization,
@@ -54,26 +54,12 @@ interface HttpLoggerOptions {
54
54
  /** Log level for error responses (status ≥ 500). Default: 'error'. */
55
55
  errorLevel?: string;
56
56
  }
57
- interface IncomingRequest {
58
- method?: string;
59
- url?: string;
60
- headers?: Record<string, string | string[] | undefined>;
61
- body?: unknown;
62
- socket?: {
63
- remoteAddress?: string;
64
- };
65
- ip?: string;
66
- }
67
- interface OutgoingResponse {
68
- statusCode?: number;
69
- on?: (event: string, cb: () => void) => void;
70
- once?: (event: string, cb: () => void) => void;
71
- getHeader?: (name: string) => string | number | string[] | undefined;
72
- }
57
+ type IncomingRequest = HttpRequestShape;
58
+ type OutgoingResponse = HttpResponseShape;
73
59
  /**
74
60
  * Create an Express / Connect compatible middleware that replaces Morgan.
75
61
  */
76
- declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
62
+ export declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
77
63
  interface FastifyInstance {
78
64
  addHook: (name: string, fn: (req: unknown, reply: unknown, done: () => void) => void) => void;
79
65
  }
@@ -85,9 +71,8 @@ interface FastifyInstance {
85
71
  * await fastify.register(createFastifyPlugin(logger, { slowRequestThresholdMs: 500 }));
86
72
  * ```
87
73
  */
88
- declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
74
+ export declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
89
75
  [x: symbol]: string | boolean;
90
76
  };
91
- //#endregion
92
- export { type FastifyInstance, type HttpLoggerOptions, type IncomingRequest, type OutgoingResponse, createExpressMiddleware, createFastifyPlugin };
77
+ export type { FastifyInstance, HttpLoggerOptions, IncomingRequest, OutgoingResponse };
93
78
  //# sourceMappingURL=middleware.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware/http-logger.ts"],"sourcesContent":[],"mappings":";;;;;UA+BiB,iBAAA;;;;;eAKF;;;;;;;;;;;;;;;;;;sBAkBO,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BzB,eAAA;;;YAGL;;;;;;;UAMK,gBAAA;;;;;;;;;iBAsID,uBAAA,SACN,uBACC,0BACF,sBAAsB;UAqFd,eAAA;;;;;;;;;;;iBAYD,mBAAA,SAA4B,uBAAsB,+BAYzB"}
1
+ {"version":3,"file":"middleware.d.mts","names":[],"sources":["../src/middleware/http-logger.ts"],"mappings":";;UAuCiB;;;;;EAKf,QAAQ,KAAK;;;;;;EAMb;;EAEA;;;;;EAKA;;;;;EAKA,eAAe,KAAK,oBAAoB;;;;;;;;EAQxC;;;;;;EAMA;;;;;;EAMA;;;;;EAKA;;EAEA;;EAEA;;KAIU,kBAAkB;KAClB,mBAAmB;;;;wBA+Df,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"}
@@ -1,8 +1,5 @@
1
- import "./transport.types-CGoHpWQR.js";
2
- import { u as IBaseLogger } from "./index-DhIoploR.js";
3
-
4
- //#region src/middleware/http-logger.d.ts
5
-
1
+ import { n as HttpResponseShape, t as HttpRequestShape } from "./http-shapes-BnBkJcid.js";
2
+ import { u as IBaseLogger } from "./index-CFDGkI8n.js";
6
3
  interface HttpLoggerOptions {
7
4
  /**
8
5
  * Skip logging for a request. Called before any I/O.
@@ -28,10 +25,13 @@ interface HttpLoggerOptions {
28
25
  */
29
26
  extraFields?: (req: IncomingRequest) => Record<string, unknown>;
30
27
  /**
31
- * Trace ID header. Default: 'x-trace-id'.
32
- * If the header is absent, a short random ID is generated.
28
+ * Header name, or list of names tried in order, to read the trace ID from.
29
+ * Default: the library-wide list (`DEFAULT_TRACE_HEADERS`: traceparent,
30
+ * x-trace-id, x-request-id, x-correlation-id, trace-id).
31
+ * If none is present, `request.id` is used when it is not a framework counter,
32
+ * otherwise a UUID is generated and shared with the logixia context helpers.
33
33
  */
34
- traceIdHeader?: string;
34
+ traceIdHeader?: string | readonly string[];
35
35
  /**
36
36
  * Additional headers to redact from logged output. Merged with the defaults
37
37
  * (authorization, cookie, set-cookie, x-api-key, proxy-authorization,
@@ -54,26 +54,12 @@ interface HttpLoggerOptions {
54
54
  /** Log level for error responses (status ≥ 500). Default: 'error'. */
55
55
  errorLevel?: string;
56
56
  }
57
- interface IncomingRequest {
58
- method?: string;
59
- url?: string;
60
- headers?: Record<string, string | string[] | undefined>;
61
- body?: unknown;
62
- socket?: {
63
- remoteAddress?: string;
64
- };
65
- ip?: string;
66
- }
67
- interface OutgoingResponse {
68
- statusCode?: number;
69
- on?: (event: string, cb: () => void) => void;
70
- once?: (event: string, cb: () => void) => void;
71
- getHeader?: (name: string) => string | number | string[] | undefined;
72
- }
57
+ type IncomingRequest = HttpRequestShape;
58
+ type OutgoingResponse = HttpResponseShape;
73
59
  /**
74
60
  * Create an Express / Connect compatible middleware that replaces Morgan.
75
61
  */
76
- declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
62
+ export declare function createExpressMiddleware(logger: IBaseLogger, options?: HttpLoggerOptions): (req: IncomingRequest, res: OutgoingResponse, next: () => void) => void;
77
63
  interface FastifyInstance {
78
64
  addHook: (name: string, fn: (req: unknown, reply: unknown, done: () => void) => void) => void;
79
65
  }
@@ -85,9 +71,8 @@ interface FastifyInstance {
85
71
  * await fastify.register(createFastifyPlugin(logger, { slowRequestThresholdMs: 500 }));
86
72
  * ```
87
73
  */
88
- declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
74
+ export declare function createFastifyPlugin(logger: IBaseLogger, options?: HttpLoggerOptions): ((fastify: FastifyInstance, _opts: unknown, done: () => void) => void) & {
89
75
  [x: symbol]: string | boolean;
90
76
  };
91
- //#endregion
92
- export { type FastifyInstance, type HttpLoggerOptions, type IncomingRequest, type OutgoingResponse, createExpressMiddleware, createFastifyPlugin };
77
+ export type { FastifyInstance, HttpLoggerOptions, IncomingRequest, OutgoingResponse };
93
78
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","names":[],"sources":["../src/middleware/http-logger.ts"],"sourcesContent":[],"mappings":";;;;;UA+BiB,iBAAA;;;;;eAKF;;;;;;;;;;;;;;;;;;sBAkBO,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BzB,eAAA;;;YAGL;;;;;;;UAMK,gBAAA;;;;;;;;;iBAsID,uBAAA,SACN,uBACC,0BACF,sBAAsB;UAqFd,eAAA;;;;;;;;;;;iBAYD,mBAAA,SAA4B,uBAAsB,+BAYzB"}
1
+ {"version":3,"file":"middleware.d.ts","names":[],"sources":["../src/middleware/http-logger.ts"],"mappings":";;UAuCiB;;;;;EAKf,QAAQ,KAAK;;;;;;EAMb;;EAEA;;;;;EAKA;;;;;EAKA,eAAe,KAAK,oBAAoB;;;;;;;;EAQxC;;;;;;EAMA;;;;;;EAMA;;;;;EAKA;;EAEA;;EAEA;;KAIU,kBAAkB;KAClB,mBAAmB;;;;wBA+Df,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"}
@@ -1,80 +1,23 @@
1
- const require_internal_log = require('./internal-log-BUJYMZbE.js');
2
- const require_safe_stringify = require('./safe-stringify-DWo3aZp_.js');
3
- const require_trace_utils = require('./trace.utils-DpBOLDtq.js');
4
-
5
- //#region src/middleware/http-logger.ts
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
- ];
31
- function buildNameSet(defaults, extra) {
32
- return new Set([...defaults, ...extra ?? []].map((n) => n.toLowerCase()));
33
- }
34
- function safeDecode(value) {
35
- try {
36
- return decodeURIComponent(value.replace(/\+/g, " "));
37
- } catch {
38
- return value;
39
- }
40
- }
41
- /** Replace the values of sensitive query parameters, leaving the rest verbatim. */
42
- function sanitizeUrl(url, redactParams) {
43
- const q = url.indexOf("?");
44
- if (q === -1) return url;
45
- const hashAt = url.indexOf("#", q);
46
- const query = url.slice(q + 1, hashAt === -1 ? void 0 : hashAt);
47
- const hash = hashAt === -1 ? "" : url.slice(hashAt);
48
- const cleaned = query.split("&").map((pair) => {
49
- const eq = pair.indexOf("=");
50
- const rawKey = eq === -1 ? pair : pair.slice(0, eq);
51
- const decoded = safeDecode(rawKey);
52
- const bracket = decoded.indexOf("[");
53
- const name = (bracket === -1 ? decoded : decoded.slice(0, bracket)).toLowerCase();
54
- return redactParams.has(name) && eq !== -1 ? `${rawKey}=[REDACTED]` : pair;
55
- }).join("&");
56
- return `${url.slice(0, q)}?${cleaned}${hash}`;
57
- }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_own_property = require("./own-property-BWkibepN.js");
3
+ const require_request_trace = require("./request-trace-ByujsUZk.js");
4
+ const require_internal_log = require("./internal-log-By4Govmu.js");
5
+ const require_safe_stringify = require("./safe-stringify-J3sh-7YM.js");
6
+ // src/middleware/http-logger.ts
58
7
  function sanitizeHeaders(headers, redactSet) {
59
8
  if (!headers) return {};
60
9
  const out = {};
61
- for (const [k, v] of Object.entries(headers)) {
62
- if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
63
- out[k] = redactSet.has(k.toLowerCase()) ? "[REDACTED]" : v;
64
- }
10
+ for (const [k, v] of Object.entries(headers)) require_own_property.assignOwn(out, k, redactSet.has(k.toLowerCase()) ? "[REDACTED]" : v);
65
11
  return out;
66
12
  }
67
13
  /** Fire-and-forget a logger call; a failing log must never become an unhandled rejection. */
68
14
  function fire(result) {
69
15
  if (result && typeof result.catch === "function") result.catch((error) => require_internal_log.internalError("http-logger: log call failed", error));
70
16
  }
71
- function shortId() {
72
- return Math.random().toString(36).slice(2, 10);
73
- }
74
17
  function resolveNameSets(options) {
75
18
  return {
76
- headers: buildNameSet(DEFAULT_REDACT_HEADERS, options.redactHeaders),
77
- queryParams: buildNameSet(DEFAULT_REDACT_QUERY_PARAMS, options.redactQueryParams)
19
+ headers: require_internal_log.buildNameSet(require_internal_log.DEFAULT_REDACT_HEADERS, options.redactHeaders),
20
+ queryParams: require_internal_log.buildNameSet(require_internal_log.DEFAULT_REDACT_QUERY_PARAMS, options.redactQueryParams)
78
21
  };
79
22
  }
80
23
  function buildBaseFields(req, traceId, options, { headers: redactSet, queryParams: paramSet }) {
@@ -82,7 +25,7 @@ function buildBaseFields(req, traceId, options, { headers: redactSet, queryParam
82
25
  const fields = {
83
26
  traceId,
84
27
  method: ((_req$method = req.method) === null || _req$method === void 0 ? void 0 : _req$method.toUpperCase()) ?? "UNKNOWN",
85
- url: sanitizeUrl(req.url ?? "/", paramSet),
28
+ url: require_internal_log.redactUrlQuery(req.url ?? "/", paramSet),
86
29
  ip: req.ip ?? ((_req$socket = req.socket) === null || _req$socket === void 0 ? void 0 : _req$socket.remoteAddress) ?? "unknown",
87
30
  headers: sanitizeHeaders(req.headers, redactSet)
88
31
  };
@@ -93,16 +36,16 @@ function buildBaseFields(req, traceId, options, { headers: redactSet, queryParam
93
36
  * Create an Express / Connect compatible middleware that replaces Morgan.
94
37
  */
95
38
  function createExpressMiddleware(logger, options = {}) {
96
- const { skip, logBody, bodyMaxBytes, traceIdHeader = "x-trace-id", requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
39
+ const { skip, logBody, bodyMaxBytes, traceIdHeader, requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
97
40
  const nameSets = resolveNameSets(options);
98
- const traceHeaderName = traceIdHeader.toLowerCase();
41
+ const traceHeaders = require_request_trace.resolveTraceHeaders(traceIdHeader);
99
42
  return function logixiaHttpMiddleware(req, res, next) {
100
- var _req$headers, _res$once, _res$once2;
43
+ var _res$once, _res$once2;
101
44
  if (skip === null || skip === void 0 ? void 0 : skip(req)) {
102
45
  next();
103
46
  return;
104
47
  }
105
- const traceId = require_trace_utils.sanitizeIncomingId((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers[traceHeaderName]) ?? shortId();
48
+ const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
106
49
  const startMs = Date.now();
107
50
  const baseFields = buildBaseFields(req, traceId, options, nameSets);
108
51
  if (requestLevel !== "silent") fire(logger.logLevel(requestLevel, "request started", {
@@ -142,20 +85,18 @@ function createExpressMiddleware(logger, options = {}) {
142
85
  * ```
143
86
  */
144
87
  function createFastifyPlugin(logger, options = {}) {
145
- const { skip, traceIdHeader = "x-trace-id", requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
88
+ const { skip, traceIdHeader, requestLevel = "debug", responseLevel = "info", errorLevel = "error", slowRequestThresholdMs = 1e3 } = options;
146
89
  const nameSets = resolveNameSets(options);
147
- const traceHeaderName = traceIdHeader.toLowerCase();
90
+ const traceHeaders = require_request_trace.resolveTraceHeaders(traceIdHeader);
148
91
  function logixiaFastifyPlugin(fastify, _opts, done) {
149
92
  fastify.addHook("onRequest", (request, _reply, hookDone) => {
150
- var _req$headers2;
151
93
  const req = request;
152
94
  if (skip === null || skip === void 0 ? void 0 : skip(req)) {
153
95
  hookDone();
154
96
  return;
155
97
  }
156
- const traceId = require_trace_utils.sanitizeIncomingId((_req$headers2 = req.headers) === null || _req$headers2 === void 0 ? void 0 : _req$headers2[traceHeaderName]) ?? shortId();
98
+ const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
157
99
  req._logixiaStart = Date.now();
158
- req._logixiaId = traceId;
159
100
  if (requestLevel !== "silent") fire(logger.logLevel(requestLevel, "request started", buildBaseFields(req, traceId, options, nameSets)));
160
101
  hookDone();
161
102
  });
@@ -168,7 +109,7 @@ function createFastifyPlugin(logger, options = {}) {
168
109
  const rep = reply;
169
110
  const duration = Date.now() - req._logixiaStart;
170
111
  const status = rep.statusCode ?? 0;
171
- const traceId = req._logixiaId ?? shortId();
112
+ const traceId = require_request_trace.resolveRequestTraceId(req, traceHeaders);
172
113
  const level = status >= 500 ? errorLevel : responseLevel;
173
114
  const baseFields = buildBaseFields(req, traceId, options, nameSets);
174
115
  fire(logger.logLevel(level, "request completed", {
@@ -247,13 +188,12 @@ function pruneValue(value, budget, depth, ancestors) {
247
188
  }
248
189
  const record = {};
249
190
  for (const [k, v] of Object.entries(value)) {
250
- if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
251
191
  if (budget.left <= 0) {
252
192
  record["…"] = TRUNCATED;
253
193
  break;
254
194
  }
255
195
  budget.left -= k.length;
256
- record[k] = pruneValue(v, budget, depth + 1, ancestors);
196
+ require_own_property.assignOwn(record, k, pruneValue(v, budget, depth + 1, ancestors));
257
197
  }
258
198
  return record;
259
199
  } catch {
@@ -262,8 +202,7 @@ function pruneValue(value, budget, depth, ancestors) {
262
202
  ancestors.delete(value);
263
203
  }
264
204
  }
265
-
266
- //#endregion
267
205
  exports.createExpressMiddleware = createExpressMiddleware;
268
206
  exports.createFastifyPlugin = createFastifyPlugin;
207
+
269
208
  //# sourceMappingURL=middleware.js.map