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,14 +1,14 @@
1
- import { t as __require } from "./chunk-DLSkYcPk.mjs";
2
- import { n as internalLog, r as internalWarn, t as internalError } from "./internal-log-Cm8SOWSV.mjs";
3
- import { i as stringifyForLog } from "./safe-stringify-DJ66tW5I.mjs";
4
- import { i as TraceContext } from "./trace.utils-CvXgaiQT.mjs";
5
- import { t as LogixiaContext } from "./async-context-BzJrbfQs.mjs";
6
- import { t as safeToString } from "./coerce.utils-Cu6IUTgX.mjs";
7
- import { d as stripControlChars, t as TransportManager } from "./transport.manager-BiuCAJd2.mjs";
8
- import { constants } from "node:os";
1
+ import { t as assignOwn } from "./own-property-CjFw9qwZ.mjs";
2
+ import { o as TraceContext } from "./request-trace-BgNykH9M.mjs";
3
+ import { t as LogixiaContext } from "./async-context-2mbUKhcl.mjs";
4
+ import { n as internalLog, o as SENSITIVE_KEY_NAMES, r as internalWarn, t as internalError } from "./internal-log-Bg4V1cPg.mjs";
5
+ import { n as protectSecrets } from "./secret-config-Dhb6pqTU.mjs";
6
+ import { t as safeToString } from "./coerce.utils-B_rEudCn.mjs";
7
+ import { i as stringifyForLog } from "./safe-stringify-B5p5ktFe.mjs";
8
+ import { c as TransportManager, n as _getOtelPayloadIfEnabled, r as _isOtelBridgeEnabled, v as stripControlChars } from "./otel-Dt5riXuE.mjs";
9
9
  import buildFastStringify from "fast-json-stringify";
10
-
11
- //#region src/types/index.ts
10
+ import { constants } from "node:os";
11
+ // src/types/index.ts
12
12
  const LogLevel = {
13
13
  ERROR: "error",
14
14
  WARN: "warn",
@@ -33,9 +33,7 @@ const DEFAULT_LOG_COLORS = {
33
33
  trace: "magenta",
34
34
  verbose: "cyan"
35
35
  };
36
-
37
- //#endregion
38
- //#region src/core/default-config.ts
36
+ // src/core/default-config.ts
39
37
  /**
40
38
  * Default configuration for Logixia logger
41
39
  */
@@ -79,9 +77,7 @@ const DEFAULT_CONFIG = {
79
77
  },
80
78
  outputs: ["console"]
81
79
  };
82
-
83
- //#endregion
84
- //#region src/plugin.ts
80
+ // src/plugin.ts
85
81
  /**
86
82
  * Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
87
83
  * events to them. One registry is created per logger instance; a global
@@ -186,9 +182,7 @@ const globalPluginRegistry = new PluginRegistry();
186
182
  function usePlugin(plugin) {
187
183
  globalPluginRegistry.register(plugin);
188
184
  }
189
-
190
- //#endregion
191
- //#region src/utils/error.utils.ts
185
+ // src/utils/error.utils.ts
192
186
  const EXTRA_FIELDS = [
193
187
  "code",
194
188
  "statusCode",
@@ -230,13 +224,15 @@ function _serializeError(error, includeStack, maxDepth, excludeFields, depth, se
230
224
  };
231
225
  if (includeStack && error.stack) serialized.stack = error.stack;
232
226
  const errorWithCause = error;
233
- if (errorWithCause.cause !== void 0) if (errorWithCause.cause instanceof Error) serialized.cause = _serializeError(errorWithCause.cause, includeStack, maxDepth, excludeFields, depth + 1, seen);
234
- else serialized.cause = serializeValue(errorWithCause.cause, maxDepth - depth - 1, seen);
227
+ if (errorWithCause.cause !== void 0) {
228
+ if (errorWithCause.cause instanceof Error) serialized.cause = _serializeError(errorWithCause.cause, includeStack, maxDepth, excludeFields, depth + 1, seen);
229
+ else serialized.cause = serializeValue(errorWithCause.cause, maxDepth - depth - 1, seen);
230
+ }
235
231
  const aggregateError = error;
236
232
  if (Array.isArray(aggregateError.errors)) serialized.errors = aggregateError.errors.map((e) => e instanceof Error ? _serializeError(e, includeStack, maxDepth, excludeFields, depth + 1, seen) : serializeValue(e, maxDepth - depth - 1, seen));
237
233
  const errorRecord = error;
238
234
  for (const field of EXTRA_FIELDS) if (!excludeFields.includes(field) && field in error && errorRecord[field] !== void 0) serialized[field] = errorRecord[field];
239
- const skip = new Set([
235
+ const skip = /* @__PURE__ */ new Set([
240
236
  "name",
241
237
  "message",
242
238
  "stack",
@@ -247,11 +243,10 @@ function _serializeError(error, includeStack, maxDepth, excludeFields, depth, se
247
243
  ]);
248
244
  for (const key of Object.getOwnPropertyNames(error)) {
249
245
  if (skip.has(key)) continue;
250
- if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
251
246
  try {
252
- serialized[key] = serializeValue(errorRecord[key], maxDepth - depth - 1, seen);
247
+ assignOwn(serialized, key, serializeValue(errorRecord[key], maxDepth - depth - 1, seen));
253
248
  } catch {
254
- serialized[key] = "[Unserializable]";
249
+ assignOwn(serialized, key, "[Unserializable]");
255
250
  }
256
251
  }
257
252
  return serialized;
@@ -286,13 +281,10 @@ function serializeValue(value, remainingDepth, seen) {
286
281
  if (seen.has(value)) return "[Circular]";
287
282
  seen.add(value);
288
283
  const out = {};
289
- for (const [k, v] of Object.entries(value)) {
290
- if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
291
- try {
292
- out[k] = serializeValue(v, remainingDepth - 1, seen);
293
- } catch {
294
- out[k] = "[Unserializable]";
295
- }
284
+ for (const [k, v] of Object.entries(value)) try {
285
+ assignOwn(out, k, serializeValue(v, remainingDepth - 1, seen));
286
+ } catch {
287
+ assignOwn(out, k, "[Unserializable]");
296
288
  }
297
289
  return out;
298
290
  }
@@ -318,116 +310,7 @@ function normalizeError(error) {
318
310
  }
319
311
  return new Error(String(error));
320
312
  }
321
-
322
- //#endregion
323
- //#region src/utils/otel.ts
324
- let _otelApi;
325
- function tryLoadOtelApi() {
326
- if (_otelApi !== void 0) return _otelApi;
327
- try {
328
- _otelApi = __require("@opentelemetry/api");
329
- return _otelApi;
330
- } catch {
331
- _otelApi = null;
332
- return null;
333
- }
334
- }
335
- /**
336
- * Read the currently active OTel span context (if any) and return its fields
337
- * in a plain object suitable for spreading into a log entry.
338
- *
339
- * Returns `undefined` when:
340
- * - `@opentelemetry/api` is not installed
341
- * - No active span exists (root context)
342
- * - The span context is invalid (all-zeros)
343
- */
344
- function getActiveOtelContext(opts = {}) {
345
- const api = tryLoadOtelApi();
346
- if (!api) return void 0;
347
- try {
348
- const ctx = api.context.active();
349
- const sc = api.trace.getSpanContext(ctx);
350
- if (!sc || !api.trace.isSpanContextValid(sc)) return void 0;
351
- const isSampled = (sc.traceFlags & api.trace.TraceFlags.SAMPLED) === api.trace.TraceFlags.SAMPLED;
352
- if (opts.sampledOnly && !isSampled) return void 0;
353
- return {
354
- traceId: sc.traceId,
355
- spanId: sc.spanId,
356
- traceFlags: sc.traceFlags,
357
- isSampled
358
- };
359
- } catch {
360
- return;
361
- }
362
- }
363
- /**
364
- * Returns a metadata object with OTel context fields ready to merge into a log call,
365
- * using the configured field names.
366
- *
367
- * Returns `{}` when no active span exists (safe to spread unconditionally).
368
- *
369
- * @example
370
- * ```ts
371
- * await logger.info('Payment processed', {
372
- * ...getOtelMetaFields(),
373
- * orderId: 'ord_123',
374
- * });
375
- * ```
376
- */
377
- function getOtelMetaFields(opts = {}) {
378
- const { traceIdField = "traceId", spanIdField = "spanId", traceFlagsField = "traceFlags" } = opts;
379
- const ctx = getActiveOtelContext(opts);
380
- if (!ctx) return {};
381
- return {
382
- [traceIdField]: ctx.traceId,
383
- [spanIdField]: ctx.spanId,
384
- [traceFlagsField]: ctx.traceFlags
385
- };
386
- }
387
- let _bridgeOptions = null;
388
- /**
389
- * Initialise the global OTel bridge.
390
- *
391
- * Once called, logixia's internal log pipeline checks for an active OTel span
392
- * on **every** log call and automatically merges the span context into the
393
- * entry's metadata — no per-call wiring needed.
394
- *
395
- * Call once at app startup, **after** the OTel SDK has been initialised:
396
- * ```ts
397
- * import { initOtelBridge } from 'logixia';
398
- * initOtelBridge();
399
- * ```
400
- */
401
- function initOtelBridge(opts = {}) {
402
- _bridgeOptions = opts;
403
- }
404
- /**
405
- * @internal
406
- * True when initOtelBridge() has been called. Lets the logger hot path skip the
407
- * `_getOtelPayloadIfEnabled()` call (and its `{}` allocation + Object.keys) on
408
- * every log when the bridge is off — the overwhelmingly common case.
409
- */
410
- function _isOtelBridgeEnabled() {
411
- return _bridgeOptions !== null;
412
- }
413
- /**
414
- * @internal
415
- * Used by the core logger to inject OTel context when the bridge is active.
416
- * Returns `{}` when the bridge is not initialised or no active span exists.
417
- */
418
- function _getOtelPayloadIfEnabled() {
419
- if (!_bridgeOptions) return {};
420
- return getOtelMetaFields(_bridgeOptions);
421
- }
422
- /**
423
- * Disable the OTel bridge (useful for tests).
424
- */
425
- function disableOtelBridge() {
426
- _bridgeOptions = null;
427
- }
428
-
429
- //#endregion
430
- //#region src/utils/redact.utils.ts
313
+ // src/utils/redact.utils.ts
431
314
  const DEFAULT_CENSOR = "[REDACTED]";
432
315
  /** Maximum nesting depth walked; deeper values are replaced with a marker. */
433
316
  const MAX_DEPTH = 32;
@@ -456,34 +339,7 @@ const PII_CONSERVATIVE_PATTERNS = [
456
339
  /**
457
340
  * Conservative field-name paths auto-redacted by name regardless of value.
458
341
  */
459
- const PII_CONSERVATIVE_PATHS = [
460
- "**.password",
461
- "**.passwd",
462
- "**.secret",
463
- "**.token",
464
- "**.apiKey",
465
- "**.api_key",
466
- "**.accessToken",
467
- "**.access_token",
468
- "**.refreshToken",
469
- "**.refresh_token",
470
- "**.authorization",
471
- "**.credentials",
472
- "**.privateKey",
473
- "**.private_key",
474
- "**.clientSecret",
475
- "**.client_secret",
476
- "**.cookie",
477
- "**.set-cookie",
478
- "**.x-api-key",
479
- "**.session",
480
- "**.proxy-authorization",
481
- "**.x-auth-token",
482
- "**.x-access-token",
483
- "**.aws_secret_access_key",
484
- "**.awsSecretAccessKey",
485
- "**.secretAccessKey"
486
- ];
342
+ const PII_CONSERVATIVE_PATHS = SENSITIVE_KEY_NAMES.map((name) => `**.${name}`);
487
343
  /**
488
344
  * Aggressive patterns: also catch personal data that could identify a person.
489
345
  * Applied when `autoDetect: 'aggressive'`.
@@ -655,10 +511,9 @@ function walkRecord(obj, state, fullPath, bare, depth) {
655
511
  let result;
656
512
  const entries = Object.entries(obj);
657
513
  for (const [index, [key, value]] of entries.entries()) {
658
- const forbidden = key === "__proto__" || key === "constructor" || key === "prototype";
659
- const next = forbidden ? void 0 : walkValue(value, state, joinPath(fullPath, key), joinPath(bare, key), depth);
660
- if ((forbidden || next !== value) && !result) result = Object.fromEntries(entries.slice(0, index));
661
- if (result && !forbidden) result[key] = next;
514
+ const next = walkValue(value, state, joinPath(fullPath, key), joinPath(bare, key), depth);
515
+ if (next !== value && !result) result = Object.fromEntries(entries.slice(0, index));
516
+ if (result) assignOwn(result, key, next);
662
517
  }
663
518
  return result ?? obj;
664
519
  }
@@ -695,7 +550,7 @@ function walkToJSON(obj, state, fullPath, bare, depth) {
695
550
  function redactObject(obj, config, _currentPath = "") {
696
551
  const result = walkRecord(obj, {
697
552
  config,
698
- ancestors: new Set([obj]),
553
+ ancestors: /* @__PURE__ */ new Set([obj]),
699
554
  nodes: 0
700
555
  }, _currentPath, _currentPath, 0);
701
556
  return result === obj ? { ...obj } : result;
@@ -744,10 +599,8 @@ function isPlainObject(value) {
744
599
  if (ArrayBuffer.isView(value)) return false;
745
600
  return !OPAQUE_BUILTINS.some((ctor) => value instanceof ctor);
746
601
  }
747
-
748
- //#endregion
749
- //#region src/utils/sampling.utils.ts
750
- const ALWAYS_EMIT_LEVELS = new Set([
602
+ // src/utils/sampling.utils.ts
603
+ const ALWAYS_EMIT_LEVELS = /* @__PURE__ */ new Set([
751
604
  "error",
752
605
  "warn",
753
606
  "fatal"
@@ -765,8 +618,8 @@ var Sampler = class {
765
618
  constructor(config, onStats) {
766
619
  this.traceDecisions = /* @__PURE__ */ new Map();
767
620
  this.maxTrackedTraces = 1e5;
768
- this.traceTtlMs = 5 * 6e4;
769
- this.traceMaxLifetimeMs = 60 * 6e4;
621
+ this.traceTtlMs = 3e5;
622
+ this.traceMaxLifetimeMs = 36e5;
770
623
  this._tokenBucket = 0;
771
624
  this._lastRefillMs = Date.now();
772
625
  this._adaptiveWindow = [];
@@ -945,9 +798,14 @@ var Sampler = class {
945
798
  this._stats.dropped++;
946
799
  }
947
800
  };
948
-
949
- //#endregion
950
- //#region src/utils/shutdown.utils.ts
801
+ // src/utils/shutdown.utils.ts
802
+ /**
803
+ * Graceful shutdown utilities for Logixia
804
+ *
805
+ * Ensures all in-flight logs are flushed to every transport before the process
806
+ * exits on SIGTERM / SIGINT — solving the "last N seconds of logs are lost on
807
+ * deployment" problem reported in Pino issue #2002 and LogDNA issue #15.
808
+ */
951
809
  const MAX_BEFORE_EXIT_FLUSHES = 5;
952
810
  /** Module-level registry of all logger instances that have opted into graceful shutdown */
953
811
  const registry = /* @__PURE__ */ new Set();
@@ -1067,9 +925,59 @@ function resetShutdownHandlers() {
1067
925
  shutdownHandlerRegistered = false;
1068
926
  shutdownInProgress = false;
1069
927
  }
1070
-
1071
- //#endregion
1072
- //#region src/core/logitron-logger.ts
928
+ const RESERVED = /* @__PURE__ */ new Set([
929
+ "logLevel",
930
+ "time",
931
+ "timeEnd",
932
+ "timeAsync",
933
+ "setLevel",
934
+ "getLevel",
935
+ "setNamespaceLevels",
936
+ "patchNamespaceLevels",
937
+ "getNamespaceLevels",
938
+ "setContext",
939
+ "getContext",
940
+ "enableField",
941
+ "disableField",
942
+ "isFieldEnabled",
943
+ "getFieldState",
944
+ "resetFieldState",
945
+ "enableTransportLevelPrompting",
946
+ "disableTransportLevelPrompting",
947
+ "setTransportLevels",
948
+ "getTransportLevels",
949
+ "clearTransportLevelPreferences",
950
+ "getAvailableTransports",
951
+ "child",
952
+ "flush",
953
+ "healthCheck",
954
+ "close",
955
+ "use",
956
+ "unuse"
957
+ ]);
958
+ /**
959
+ * Warn when `levels` defines a level named like a logger method (e.g. `flush`, `child`).
960
+ * The method keeps its normal behaviour and no level shortcut is installed for that
961
+ * name; log at it with `logger.logLevel(name, ...)` or pick a different level name.
962
+ * Returns the clashing names.
963
+ */
964
+ function warnOnReservedLevelNames(levels) {
965
+ if (!levels) return [];
966
+ const clashes = Object.keys(levels).filter((name) => RESERVED.has(name));
967
+ if (clashes.length > 0) internalWarn(`levelOptions.levels uses reserved logger method name(s): ${clashes.join(", ")}. No level shortcut is created for them; use logger.logLevel(name, ...) or rename the level.`);
968
+ return clashes;
969
+ }
970
+ // src/core/logitron-logger.ts
971
+ /**
972
+ * Core Logixia Logger implementation
973
+ *
974
+ * v1.1 additions:
975
+ * - Feature 1: Graceful shutdown / flushOnExit (auto-registered via config)
976
+ * - Feature 2: Built-in log redaction (path-based + regex)
977
+ * - Feature 3: Per-namespace log levels + LOGIXIA_LEVEL* ENV overrides
978
+ * - Feature 4: Cause-chain error serialization (handled in error.utils)
979
+ * - Feature 5: Adaptive log level based on NODE_ENV / CI detection
980
+ */
1073
981
  const _fastStringifyEntry = buildFastStringify({
1074
982
  type: "object",
1075
983
  properties: {
@@ -1099,7 +1007,7 @@ function nowIso() {
1099
1007
  }
1100
1008
  function namespacePatternToRegex(pattern) {
1101
1009
  const escaped = pattern.split(".").map((s) => s === "*" ? "[^.]+" : s.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&")).join("\\.");
1102
- return /* @__PURE__ */ new RegExp(`^${escaped}$`);
1010
+ return new RegExp(`^${escaped}$`);
1103
1011
  }
1104
1012
  /** Max compiled patterns to keep in memory. Oldest entry is evicted when full. */
1105
1013
  const _NS_CACHE_MAX = 1e3;
@@ -1141,7 +1049,7 @@ function canonicalLevel(level, known) {
1141
1049
  function resolveInitialLevel(config) {
1142
1050
  var _config$levelOptions, _config$levelOptions2;
1143
1051
  const envLevel = process.env["LOGIXIA_LEVEL"];
1144
- const knownLevels = new Set([...Object.values(LogLevel), ...Object.keys(((_config$levelOptions = config.levelOptions) === null || _config$levelOptions === void 0 ? void 0 : _config$levelOptions.levels) ?? {})]);
1052
+ const knownLevels = /* @__PURE__ */ new Set([...Object.values(LogLevel), ...Object.keys(((_config$levelOptions = config.levelOptions) === null || _config$levelOptions === void 0 ? void 0 : _config$levelOptions.levels) ?? {})]);
1145
1053
  if (envLevel && canonicalLevel(envLevel, knownLevels)) return envLevel;
1146
1054
  if ((_config$levelOptions2 = config.levelOptions) === null || _config$levelOptions2 === void 0 ? void 0 : _config$levelOptions2.level) return config.levelOptions.level;
1147
1055
  const nodeEnv = process.env["NODE_ENV"];
@@ -1151,6 +1059,19 @@ function resolveInitialLevel(config) {
1151
1059
  if (process.env["CI"]) return LogLevel.INFO;
1152
1060
  return LogLevel.INFO;
1153
1061
  }
1062
+ /**
1063
+ * The logixia logger. Create instances with {@link createLogger} so that custom
1064
+ * levels from `levelOptions.levels` also become methods.
1065
+ *
1066
+ * @example
1067
+ * ```ts
1068
+ * const logger = createLogger({ appName: 'api', environment: 'production' });
1069
+ * await logger.info('Server started', { port: 3000 });
1070
+ * const req = logger.child('RequestHandler', { requestId: 'r-1' });
1071
+ * await req.error(new Error('boom'));
1072
+ * await logger.close(); // flush buffered transports before exit
1073
+ * ```
1074
+ */
1154
1075
  var LogixiaLogger = class LogixiaLogger {
1155
1076
  constructor(config, context, parent) {
1156
1077
  this.timers = /* @__PURE__ */ new Map();
@@ -1166,9 +1087,15 @@ var LogixiaLogger = class LogixiaLogger {
1166
1087
  this._formattedLevels = /* @__PURE__ */ new Map();
1167
1088
  this._formattedAppName = "";
1168
1089
  this._hasRedact = false;
1090
+ this._nsSeenVersion = 0;
1169
1091
  this._parent = parent;
1092
+ this._nsStore = parent ? parent._nsStore : {
1093
+ levels: { ...config.namespaceLevels },
1094
+ version: 0
1095
+ };
1096
+ this._nsSeenVersion = this._nsStore.version;
1170
1097
  this._pluginRegistry = parent ? parent._pluginRegistry : new PluginRegistry();
1171
- this.config = {
1098
+ const defaultConfig = {
1172
1099
  appName: "App",
1173
1100
  environment: "development",
1174
1101
  traceId: true,
@@ -1196,7 +1123,10 @@ var LogixiaLogger = class LogixiaLogger {
1196
1123
  [LogLevel.TRACE]: "gray",
1197
1124
  [LogLevel.VERBOSE]: "cyan"
1198
1125
  }
1199
- },
1126
+ }
1127
+ };
1128
+ this.config = {
1129
+ ...defaultConfig,
1200
1130
  ...config
1201
1131
  };
1202
1132
  const resolvedLevel = resolveInitialLevel(this.config);
@@ -1214,18 +1144,19 @@ var LogixiaLogger = class LogixiaLogger {
1214
1144
  timeTaken: "[time_taken_MS]"
1215
1145
  };
1216
1146
  this.context = context ?? "";
1147
+ protectSecrets(this, ["config"]);
1217
1148
  if (parent) {
1218
1149
  this.transportManager = parent.transportManager;
1219
1150
  this._sampler = parent._sampler;
1220
1151
  } else if (this.config.transports) {
1221
- var _this$config$levelOpt;
1152
+ var _this$config$levelOpt, _this$config$levelOpt2;
1222
1153
  const transportsWithColors = { ...this.config.transports };
1223
1154
  const userColors = (_this$config$levelOpt = this.config.levelOptions) === null || _this$config$levelOpt === void 0 ? void 0 : _this$config$levelOpt.colors;
1224
1155
  if (userColors && transportsWithColors.console) transportsWithColors.console = {
1225
1156
  ...typeof transportsWithColors.console === "object" ? transportsWithColors.console : {},
1226
1157
  levelColors: userColors
1227
1158
  };
1228
- this.transportManager = new TransportManager(transportsWithColors);
1159
+ this.transportManager = new TransportManager(transportsWithColors, (_this$config$levelOpt2 = this.config.levelOptions) === null || _this$config$levelOpt2 === void 0 ? void 0 : _this$config$levelOpt2.levels);
1229
1160
  }
1230
1161
  if (!parent && this.config.sampling) this._sampler = new Sampler(this.config.sampling, (stats) => {
1231
1162
  process.stdout.write(JSON.stringify({
@@ -1252,8 +1183,9 @@ var LogixiaLogger = class LogixiaLogger {
1252
1183
  });
1253
1184
  }
1254
1185
  createCustomLevelMethods() {
1255
- var _this$config$levelOpt2;
1256
- if ((_this$config$levelOpt2 = this.config.levelOptions) === null || _this$config$levelOpt2 === void 0 ? void 0 : _this$config$levelOpt2.levels) {
1186
+ var _this$config$levelOpt3, _this$config$levelOpt4;
1187
+ warnOnReservedLevelNames((_this$config$levelOpt3 = this.config.levelOptions) === null || _this$config$levelOpt3 === void 0 ? void 0 : _this$config$levelOpt3.levels);
1188
+ if ((_this$config$levelOpt4 = this.config.levelOptions) === null || _this$config$levelOpt4 === void 0 ? void 0 : _this$config$levelOpt4.levels) {
1257
1189
  for (const levelName of Object.keys(this.config.levelOptions.levels)) if (!this[levelName.toLowerCase()]) this[levelName.toLowerCase()] = async (message, data) => {
1258
1190
  await this.logLevel(levelName.toLowerCase(), message, data);
1259
1191
  };
@@ -1264,8 +1196,8 @@ var LogixiaLogger = class LogixiaLogger {
1264
1196
  * Keeps the actual log() call free of allocations in the common case.
1265
1197
  */
1266
1198
  _buildPerfCaches() {
1267
- var _this$config$levelOpt3, _this$config$format, _this$config$redact$p, _this$config$redact$p2;
1268
- const customLevelEntries = Object.entries(((_this$config$levelOpt3 = this.config.levelOptions) === null || _this$config$levelOpt3 === void 0 ? void 0 : _this$config$levelOpt3.levels) ?? {});
1199
+ var _this$config$levelOpt5, _this$config$format, _this$config$redact$p, _this$config$redact$p2;
1200
+ const customLevelEntries = Object.entries(((_this$config$levelOpt5 = this.config.levelOptions) === null || _this$config$levelOpt5 === void 0 ? void 0 : _this$config$levelOpt5.levels) ?? {});
1269
1201
  this._levelValues = new Map([
1270
1202
  [LogLevel.ERROR, 0],
1271
1203
  [LogLevel.WARN, 1],
@@ -1279,7 +1211,7 @@ var LogixiaLogger = class LogixiaLogger {
1279
1211
  this.config.levelOptions.level = this._validLevel(this.config.levelOptions.level, "levelOptions.level") ?? LogLevel.INFO;
1280
1212
  const effectiveLevel = this.resolveEffectiveLevel();
1281
1213
  this._minLevelValue = this._levelValues.get(effectiveLevel) ?? 2;
1282
- this._colorMap = new Map([
1214
+ this._colorMap = /* @__PURE__ */ new Map([
1283
1215
  ["black", "\x1B[30m"],
1284
1216
  ["red", "\x1B[31m"],
1285
1217
  ["green", "\x1B[32m"],
@@ -1322,7 +1254,7 @@ var LogixiaLogger = class LogixiaLogger {
1322
1254
  "green",
1323
1255
  "blue"
1324
1256
  ];
1325
- const _BUILTIN_LEVELS = new Set([
1257
+ const _BUILTIN_LEVELS = /* @__PURE__ */ new Set([
1326
1258
  "error",
1327
1259
  "warn",
1328
1260
  "info",
@@ -1334,12 +1266,14 @@ var LogixiaLogger = class LogixiaLogger {
1334
1266
  for (const [lvl] of this._levelValues) {
1335
1267
  const upper = lvl.toUpperCase();
1336
1268
  if (colorize && this._fieldCache.get("level") !== false) {
1337
- var _this$config$levelOpt4;
1338
- let colorName = (_this$config$levelOpt4 = this.config.levelOptions) === null || _this$config$levelOpt4 === void 0 || (_this$config$levelOpt4 = _this$config$levelOpt4.colors) === null || _this$config$levelOpt4 === void 0 ? void 0 : _this$config$levelOpt4[lvl];
1339
- if (!colorName) if (_BUILTIN_LEVELS.has(lvl)) colorName = "white";
1340
- else {
1341
- colorName = _AUTO_PALETTE[_paletteIdx % _AUTO_PALETTE.length];
1342
- _paletteIdx++;
1269
+ var _this$config$levelOpt6;
1270
+ let colorName = (_this$config$levelOpt6 = this.config.levelOptions) === null || _this$config$levelOpt6 === void 0 || (_this$config$levelOpt6 = _this$config$levelOpt6.colors) === null || _this$config$levelOpt6 === void 0 ? void 0 : _this$config$levelOpt6[lvl];
1271
+ if (!colorName) {
1272
+ if (_BUILTIN_LEVELS.has(lvl)) colorName = "white";
1273
+ else {
1274
+ colorName = _AUTO_PALETTE[_paletteIdx % _AUTO_PALETTE.length];
1275
+ _paletteIdx++;
1276
+ }
1343
1277
  }
1344
1278
  const code = this._colorMap.get(colorName.toLowerCase()) ?? this._colorMap.get("white");
1345
1279
  const reset = this._colorMap.get("reset");
@@ -1351,6 +1285,11 @@ var LogixiaLogger = class LogixiaLogger {
1351
1285
  else this._formattedAppName = colorize ? `${this._colorMap.get("gray")}${appNameRaw}${this._colorMap.get("reset")} ` : `${appNameRaw} `;
1352
1286
  this._hasRedact = !!(this.config.redact && ((((_this$config$redact$p = this.config.redact.paths) === null || _this$config$redact$p === void 0 ? void 0 : _this$config$redact$p.length) ?? 0) > 0 || (((_this$config$redact$p2 = this.config.redact.patterns) === null || _this$config$redact$p2 === void 0 ? void 0 : _this$config$redact$p2.length) ?? 0) > 0 || !!this.config.redact.autoDetect));
1353
1287
  }
1288
+ /**
1289
+ * Log at `error` level. An `Error` is logged with its message and serialized
1290
+ * (name, message, stack) under `data.error`; a string is logged as-is.
1291
+ * `data` is merged into the entry payload.
1292
+ */
1354
1293
  async error(messageOrError, data) {
1355
1294
  if (isError(messageOrError)) await this.log("error", messageOrError.message, {
1356
1295
  ...data,
@@ -1358,30 +1297,53 @@ var LogixiaLogger = class LogixiaLogger {
1358
1297
  });
1359
1298
  else await this.log("error", messageOrError, data);
1360
1299
  }
1300
+ /** Log `message` at `warn` level; `data` is merged into the entry payload. */
1361
1301
  async warn(message, data) {
1362
1302
  await this.log("warn", message, data);
1363
1303
  }
1304
+ /** Log `message` at `info` level; `data` is merged into the entry payload. */
1364
1305
  async info(message, data) {
1365
1306
  await this.log("info", message, data);
1366
1307
  }
1308
+ /** Log `message` at `debug` level; `data` is merged into the entry payload. */
1367
1309
  async debug(message, data) {
1368
1310
  await this.log("debug", message, data);
1369
1311
  }
1312
+ /** Log `message` at `trace` level; `data` is merged into the entry payload. */
1370
1313
  async trace(message, data) {
1371
1314
  await this.log("trace", message, data);
1372
1315
  }
1316
+ /** Log `message` at `verbose` level; `data` is merged into the entry payload. */
1373
1317
  async verbose(message, data) {
1374
1318
  await this.log("verbose", message, data);
1375
1319
  }
1320
+ /**
1321
+ * Log at an arbitrary level name, including custom levels. Levels below the
1322
+ * active threshold are dropped, as are level names that are not registered
1323
+ * in `levelOptions.levels` (and are not built-in).
1324
+ */
1376
1325
  async logLevel(level, message, data) {
1377
1326
  await this.log(level, message, data);
1378
1327
  }
1328
+ /** Start a named timer; finish it with {@link timeEnd}. Reusing a label restarts it. */
1379
1329
  time(label) {
1380
1330
  this.timers.set(label, {
1381
1331
  label,
1382
1332
  startTime: Date.now()
1383
1333
  });
1384
1334
  }
1335
+ /**
1336
+ * Stop the timer `label`, log its duration at `info` level, and return the
1337
+ * elapsed milliseconds. Logs a `warn` and returns `undefined` if the timer
1338
+ * does not exist.
1339
+ *
1340
+ * @example
1341
+ * ```ts
1342
+ * logger.time('db');
1343
+ * await query();
1344
+ * const ms = await logger.timeEnd('db');
1345
+ * ```
1346
+ */
1385
1347
  async timeEnd(label) {
1386
1348
  const timer = this.timers.get(label);
1387
1349
  if (!timer) {
@@ -1411,6 +1373,17 @@ var LogixiaLogger = class LogixiaLogger {
1411
1373
  throw error;
1412
1374
  }
1413
1375
  }
1376
+ /**
1377
+ * Change the minimum log level at runtime. The override outranks
1378
+ * `LOGIXIA_LEVEL`, `LOGIXIA_LEVEL_<NS>` and `namespaceLevels`, and survives
1379
+ * later changes to fields or namespace levels. Unknown level names are
1380
+ * ignored with a warning and the current level is kept.
1381
+ *
1382
+ * @example
1383
+ * ```ts
1384
+ * logger.setLevel('debug');
1385
+ * ```
1386
+ */
1414
1387
  setLevel(level) {
1415
1388
  const canonical = canonicalLevel(level, this._levelValues);
1416
1389
  if (canonical === void 0) {
@@ -1419,12 +1392,17 @@ var LogixiaLogger = class LogixiaLogger {
1419
1392
  }
1420
1393
  this.config.levelOptions = this.config.levelOptions ?? {};
1421
1394
  this.config.levelOptions.level = canonical;
1422
- this._minLevelValue = this._levelValues.get(canonical) ?? this._minLevelValue;
1395
+ this._runtimeLevel = canonical;
1423
1396
  this._buildPerfCaches();
1424
1397
  }
1398
+ /**
1399
+ * Return the configured minimum log level, not the per-namespace effective
1400
+ * one. Without `setLevel()` it is `LOGIXIA_LEVEL`, else `levelOptions.level`,
1401
+ * else a `NODE_ENV` default (`debug` in development, `warn` in test), else `info`.
1402
+ */
1425
1403
  getLevel() {
1426
- var _this$config$levelOpt5;
1427
- return ((_this$config$levelOpt5 = this.config.levelOptions) === null || _this$config$levelOpt5 === void 0 ? void 0 : _this$config$levelOpt5.level) ?? LogLevel.INFO;
1404
+ var _this$config$levelOpt7;
1405
+ return ((_this$config$levelOpt7 = this.config.levelOptions) === null || _this$config$levelOpt7 === void 0 ? void 0 : _this$config$levelOpt7.level) ?? LogLevel.INFO;
1428
1406
  }
1429
1407
  _validLevelList() {
1430
1408
  return [...this._levelValues.keys()].join(", ");
@@ -1453,6 +1431,10 @@ var LogixiaLogger = class LogixiaLogger {
1453
1431
  * (flip a module's verbosity live to chase a bug without raising global
1454
1432
  * volume). The new map fully replaces the previous one.
1455
1433
  *
1434
+ * The map is shared by a logger and all its `child()` loggers: calling this on
1435
+ * a child changes the whole family, and existing children pick the change up on
1436
+ * their next log call.
1437
+ *
1456
1438
  * @example
1457
1439
  * ```ts
1458
1440
  * // Turn on debug for the DB layer only, live:
@@ -1460,45 +1442,57 @@ var LogixiaLogger = class LogixiaLogger {
1460
1442
  * ```
1461
1443
  */
1462
1444
  setNamespaceLevels(levels) {
1463
- this.config.namespaceLevels = { ...levels };
1464
- this._buildPerfCaches();
1445
+ this._nsStore.levels = { ...levels };
1446
+ this._nsStore.version++;
1447
+ this._syncNamespaceLevels();
1465
1448
  }
1466
1449
  /** Merge entries into the existing per-namespace level map at runtime. */
1467
1450
  patchNamespaceLevels(levels) {
1468
- this.config.namespaceLevels = {
1469
- ...this.config.namespaceLevels,
1451
+ this._nsStore.levels = {
1452
+ ...this._nsStore.levels,
1470
1453
  ...levels
1471
1454
  };
1472
- this._buildPerfCaches();
1455
+ this._nsStore.version++;
1456
+ this._syncNamespaceLevels();
1473
1457
  }
1474
1458
  /** Return a copy of the current per-namespace level map. */
1475
1459
  getNamespaceLevels() {
1476
- return { ...this.config.namespaceLevels };
1460
+ return { ...this._nsStore.levels };
1477
1461
  }
1462
+ _syncNamespaceLevels() {
1463
+ this._nsSeenVersion = this._nsStore.version;
1464
+ this._minLevelValue = this._levelValues.get(this.resolveEffectiveLevel()) ?? 2;
1465
+ }
1466
+ /** Set the context label (e.g. a class or module name) attached to every subsequent entry. */
1478
1467
  setContext(context) {
1479
1468
  this.context = typeof context === "string" ? context : safeToString(context);
1480
1469
  }
1470
+ /** Return the current context label, or `undefined` if none is set. */
1481
1471
  getContext() {
1482
1472
  return this.context;
1483
1473
  }
1474
+ /** Show `fieldName` in log output, overriding the config for this logger instance. */
1484
1475
  enableField(fieldName) {
1485
1476
  this.fieldState.set(fieldName, true);
1486
1477
  this._fieldCache.set(fieldName, true);
1487
1478
  if (fieldName === "level" || fieldName === "appName") this._buildPerfCaches();
1488
1479
  internalLog(`Field '${fieldName}' enabled`);
1489
1480
  }
1481
+ /** Hide `fieldName` from log output, overriding the config for this logger instance. */
1490
1482
  disableField(fieldName) {
1491
1483
  this.fieldState.set(fieldName, false);
1492
1484
  this._fieldCache.set(fieldName, false);
1493
1485
  if (fieldName === "level" || fieldName === "appName") this._buildPerfCaches();
1494
1486
  internalLog(`Field '${fieldName}' disabled`);
1495
1487
  }
1488
+ /** Whether `fieldName` is currently shown: runtime override first, then config, default `true`. */
1496
1489
  isFieldEnabled(fieldName) {
1497
1490
  var _this$config$fields2;
1498
1491
  if (this.fieldState.has(fieldName)) return this.fieldState.get(fieldName);
1499
1492
  if (((_this$config$fields2 = this.config.fields) === null || _this$config$fields2 === void 0 ? void 0 : _this$config$fields2[fieldName]) !== void 0) return this.config.fields[fieldName] !== false;
1500
1493
  return true;
1501
1494
  }
1495
+ /** Return the visibility (`true` = shown) of every standard log field. */
1502
1496
  getFieldState() {
1503
1497
  return Object.fromEntries([
1504
1498
  "timestamp",
@@ -1515,6 +1509,7 @@ var LogixiaLogger = class LogixiaLogger {
1515
1509
  "environment"
1516
1510
  ].map((f) => [f, this.isFieldEnabled(f)]));
1517
1511
  }
1512
+ /** Drop all runtime enable/disable overrides so field visibility follows the config again. */
1518
1513
  resetFieldState() {
1519
1514
  this.fieldState.clear();
1520
1515
  internalLog("Field state reset to configuration defaults");
@@ -1529,10 +1524,12 @@ var LogixiaLogger = class LogixiaLogger {
1529
1524
  if (this.transportManager) this.transportManager.disableLevelPrompting();
1530
1525
  else internalWarn("Transport manager not initialized");
1531
1526
  }
1527
+ /** Restrict `transportId` to only the given `levels`. Warns if no transports are configured. */
1532
1528
  setTransportLevels(transportId, levels) {
1533
1529
  if (this.transportManager) this.transportManager.setTransportLevels(transportId, levels);
1534
1530
  else internalWarn("Transport manager not initialized");
1535
1531
  }
1532
+ /** Return the levels `transportId` is restricted to, or `undefined` if it has none. */
1536
1533
  getTransportLevels(transportId) {
1537
1534
  if (this.transportManager) return this.transportManager.getTransportLevels(transportId);
1538
1535
  internalWarn("Transport manager not initialized");
@@ -1541,10 +1538,23 @@ var LogixiaLogger = class LogixiaLogger {
1541
1538
  if (this.transportManager) this.transportManager.clearTransportLevelPreferences();
1542
1539
  else internalWarn("Transport manager not initialized");
1543
1540
  }
1541
+ /** Return the identifiers of the configured transports (empty if none). */
1544
1542
  getAvailableTransports() {
1545
1543
  var _this$transportManage;
1546
1544
  return ((_this$transportManage = this.transportManager) === null || _this$transportManage === void 0 ? void 0 : _this$transportManage.getTransports()) ?? [];
1547
1545
  }
1546
+ /**
1547
+ * Create a child logger with its own `context` that shares this logger's
1548
+ * configuration and transports. `data` is merged into the bound fields
1549
+ * inherited from this logger and added to every entry the child writes.
1550
+ * Closing a child does not close the shared transports.
1551
+ *
1552
+ * @example
1553
+ * ```ts
1554
+ * const req = logger.child('Checkout', { requestId: 'r-42' });
1555
+ * await req.info('started'); // entry includes requestId
1556
+ * ```
1557
+ */
1548
1558
  child(context, data) {
1549
1559
  const childLogger = new LogixiaLogger(this.config, context, this);
1550
1560
  const mergedContextData = {
@@ -1580,9 +1590,11 @@ var LogixiaLogger = class LogixiaLogger {
1580
1590
  this._pluginRegistry.unregister(pluginName);
1581
1591
  return this;
1582
1592
  }
1593
+ /** Flush buffered entries in all transports without closing them. */
1583
1594
  async flush() {
1584
1595
  if (this.transportManager) await this.transportManager.flush();
1585
1596
  }
1597
+ /** Report whether the transports are healthy; `healthy: false` if no transport manager exists. */
1586
1598
  async healthCheck() {
1587
1599
  if (!this.transportManager) return {
1588
1600
  healthy: false,
@@ -1590,6 +1602,20 @@ var LogixiaLogger = class LogixiaLogger {
1590
1602
  };
1591
1603
  return this.transportManager.healthCheck();
1592
1604
  }
1605
+ /**
1606
+ * Warn about timers that were never ended, then flush and close all transports,
1607
+ * stop the sampler and run plugin shutdown hooks. On a child logger only the
1608
+ * timer warnings run; the shared transports stay open.
1609
+ *
1610
+ * To flush on SIGTERM/SIGINT, set the `gracefulShutdown` config option rather
1611
+ * than writing your own signal handler; do not combine it with a manual
1612
+ * handler that calls `process.exit`, which can cut the flush short.
1613
+ *
1614
+ * @example
1615
+ * ```ts
1616
+ * await logger.close(); // e.g. at the end of a script or a test
1617
+ * ```
1618
+ */
1593
1619
  async close() {
1594
1620
  var _this$_sampler;
1595
1621
  for (const [label, timer] of this.timers) await this.warn(`Timer '${label}' was not ended properly`, {
@@ -1606,21 +1632,27 @@ var LogixiaLogger = class LogixiaLogger {
1606
1632
  async log(level, message, data) {
1607
1633
  if (this.config.silent) return;
1608
1634
  if (!this.shouldLog(level)) return;
1609
- if (this._sampler) {
1610
- const traceId$1 = this.config.traceId ? TraceContext.instance.getCurrentTraceId() : void 0;
1611
- if (!this._sampler.shouldEmit(level, traceId$1)) return;
1612
- }
1613
1635
  const alsContext = LogixiaContext.get();
1636
+ let activeTraceId;
1637
+ if (this.config.traceId) {
1638
+ const ctxTraceId = alsContext === null || alsContext === void 0 ? void 0 : alsContext.traceId;
1639
+ activeTraceId = TraceContext.instance.getCurrentTraceId() ?? (typeof ctxTraceId === "string" ? ctxTraceId : void 0);
1640
+ }
1641
+ if (this._sampler && !this._sampler.shouldEmit(level, activeTraceId)) return;
1614
1642
  const hasAls = alsContext !== void 0 && Object.keys(alsContext).length > 0;
1615
1643
  const otelFields = _isOtelBridgeEnabled() ? _getOtelPayloadIfEnabled() : void 0;
1616
1644
  const hasOtel = otelFields !== void 0 && Object.keys(otelFields).length > 0;
1645
+ const traceId = this.config.traceId ? activeTraceId ?? this.fallbackTraceId : void 0;
1617
1646
  let mergedData;
1618
- if (hasAls) mergedData = {
1619
- ...alsContext,
1620
- ...hasOtel ? otelFields : {},
1621
- ...data
1622
- };
1623
- else if (hasOtel) mergedData = {
1647
+ if (hasAls) {
1648
+ const als = { ...alsContext };
1649
+ if (traceId !== void 0 && als["traceId"] === traceId) delete als["traceId"];
1650
+ mergedData = {
1651
+ ...als,
1652
+ ...hasOtel ? otelFields : {},
1653
+ ...data
1654
+ };
1655
+ } else if (hasOtel) mergedData = {
1624
1656
  ...otelFields,
1625
1657
  ...data
1626
1658
  };
@@ -1630,14 +1662,15 @@ var LogixiaLogger = class LogixiaLogger {
1630
1662
  ...mergedData
1631
1663
  } : mergedData;
1632
1664
  let payload;
1633
- if (rawPayload !== void 0 && rawPayload !== null) if (this._hasRedact) try {
1634
- payload = applyRedaction(rawPayload, this.config.redact) ?? rawPayload;
1635
- } catch (error) {
1636
- internalError("Redaction failed", error);
1637
- payload = { redaction: REDACTION_FAILED };
1665
+ if (rawPayload !== void 0 && rawPayload !== null) {
1666
+ if (this._hasRedact) try {
1667
+ payload = applyRedaction(rawPayload, this.config.redact) ?? rawPayload;
1668
+ } catch (error) {
1669
+ internalError("Redaction failed", error);
1670
+ payload = { redaction: REDACTION_FAILED };
1671
+ }
1672
+ else payload = rawPayload;
1638
1673
  }
1639
- else payload = rawPayload;
1640
- const traceId = this.config.traceId ? TraceContext.instance.getCurrentTraceId() ?? this.fallbackTraceId : void 0;
1641
1674
  let safeMessage = message;
1642
1675
  if (this._hasRedact) try {
1643
1676
  safeMessage = applyRedactionToString(message, this.config.redact);
@@ -1668,6 +1701,7 @@ var LogixiaLogger = class LogixiaLogger {
1668
1701
  * The level map and threshold are pre-built in _buildPerfCaches().
1669
1702
  */
1670
1703
  shouldLog(level) {
1704
+ if (this._nsSeenVersion !== this._nsStore.version) this._syncNamespaceLevels();
1671
1705
  const v = this._levelValues.get(level);
1672
1706
  return v !== void 0 && v <= this._minLevelValue;
1673
1707
  }
@@ -1675,19 +1709,21 @@ var LogixiaLogger = class LogixiaLogger {
1675
1709
  * Feature 3: Resolve the effective log level for this logger instance.
1676
1710
  *
1677
1711
  * Priority:
1712
+ * 0. A level set at runtime with `setLevel()` (explicit programmatic call, wins over all below)
1678
1713
  * 1. ENV `LOGIXIA_LEVEL_<NS_UPPER>` (e.g. LOGIXIA_LEVEL_DB for ns "db" or "db.queries")
1679
1714
  * 2. Matching `namespaceLevels` config entry (longer pattern = more specific, wins)
1680
1715
  * 3. Global `LOGIXIA_LEVEL` ENV override
1681
1716
  * 4. `levelOptions.level` (resolved via Feature 5 in constructor)
1682
1717
  */
1683
1718
  resolveEffectiveLevel() {
1719
+ if (this._runtimeLevel) return this._runtimeLevel;
1684
1720
  const ns = this.context;
1685
1721
  if (ns) {
1686
1722
  const nsKey = ns.split(".")[0].toUpperCase();
1687
1723
  const envNsLevel = this._validLevel(process.env[`LOGIXIA_LEVEL_${nsKey}`], `LOGIXIA_LEVEL_${nsKey}`);
1688
1724
  if (envNsLevel) return envNsLevel;
1689
- const namespaceLevels = this.config.namespaceLevels;
1690
- if (namespaceLevels) {
1725
+ const namespaceLevels = this._nsStore.levels;
1726
+ if (Object.keys(namespaceLevels).length > 0) {
1691
1727
  const sortedPatterns = Object.keys(namespaceLevels).sort((a, b) => b.length - a.length);
1692
1728
  for (const pattern of sortedPatterns) if (matchesNamespacePattern(ns, pattern)) {
1693
1729
  const nsLevel = this._validLevel(namespaceLevels[pattern], `namespaceLevels['${pattern}']`);
@@ -1754,6 +1790,22 @@ var LogixiaLogger = class LogixiaLogger {
1754
1790
  (level === LogLevel.ERROR ? process.stderr : process.stdout).write(this.formatLog(entry) + "\n");
1755
1791
  }
1756
1792
  };
1793
+ /**
1794
+ * Create a logger from `config`, with an optional default `context` label.
1795
+ *
1796
+ * Every key of `levelOptions.levels` that is not already a method becomes an
1797
+ * async method on the returned logger, typed through the config, and routes to
1798
+ * {@link LogixiaLogger.logLevel}.
1799
+ *
1800
+ * @example
1801
+ * ```ts
1802
+ * const logger = createLogger({
1803
+ * appName: 'api',
1804
+ * levelOptions: { level: 'info', levels: { error: 0, warn: 1, info: 2, audit: 2 } },
1805
+ * });
1806
+ * await logger.audit('user exported data', { userId: 'u1' });
1807
+ * ```
1808
+ */
1757
1809
  function createLogger(config, context) {
1758
1810
  var _config$levelOptions3;
1759
1811
  const logger = new LogixiaLogger(config, context);
@@ -1765,9 +1817,7 @@ function createLogger(config, context) {
1765
1817
  }
1766
1818
  return logger;
1767
1819
  }
1768
-
1769
- //#endregion
1770
- //#region src/exceptions/exception.ts
1820
+ // src/exceptions/exception.ts
1771
1821
  var LogixiaException = class extends Error {
1772
1822
  constructor(options) {
1773
1823
  super(options.message, { cause: options.cause });
@@ -1798,9 +1848,21 @@ var LogixiaException = class extends Error {
1798
1848
  function isLogixiaException(value) {
1799
1849
  return value instanceof LogixiaException;
1800
1850
  }
1801
-
1802
- //#endregion
1803
- //#region src/exceptions/builder.ts
1851
+ // src/exceptions/builder.ts
1852
+ /**
1853
+ * ErrorResponseBuilder — turns any exception into a `LogixiaErrorResponse`.
1854
+ *
1855
+ * Priority order:
1856
+ * 1. `LogixiaException` — typed fields used directly
1857
+ * 2. NestJS `HttpException` — duck-typed; status + message extracted
1858
+ * 3. Plain `Error` / unknown — falls back to 500 `server_error`
1859
+ *
1860
+ * The builder **always** populates `debug` when possible.
1861
+ * Your exception filter is responsible for stripping it in production:
1862
+ * ```ts
1863
+ * if (process.env.NODE_ENV === 'production') delete response.debug;
1864
+ * ```
1865
+ */
1804
1866
  /**
1805
1867
  * Generates a trace ID via the shared {@link TraceContext} generator.
1806
1868
  *
@@ -1902,7 +1964,7 @@ var ErrorResponseBuilder = class {
1902
1964
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
1903
1965
  const durationMs = startTime !== void 0 ? Date.now() - startTime : void 0;
1904
1966
  if (isLogixiaException(exception)) {
1905
- const debug$1 = buildDebug(exception, service, durationMs, expose);
1967
+ const debug = buildDebug(exception, service, durationMs, expose);
1906
1968
  const errorBlock = {
1907
1969
  type: exception.errorType,
1908
1970
  code: exception.errorCode,
@@ -1921,7 +1983,7 @@ var ErrorResponseBuilder = class {
1921
1983
  path,
1922
1984
  status: exception.httpStatus
1923
1985
  },
1924
- ...debug$1 !== void 0 ? { debug: debug$1 } : {}
1986
+ ...debug !== void 0 ? { debug } : {}
1925
1987
  },
1926
1988
  httpStatus: exception.httpStatus
1927
1989
  };
@@ -1937,7 +1999,7 @@ var ErrorResponseBuilder = class {
1937
1999
  } else message = exception.message;
1938
2000
  const type = httpStatusToType(status);
1939
2001
  const code = `HTTP_${status}`;
1940
- const debug$1 = buildDebug(exception, service, durationMs, expose);
2002
+ const debug = buildDebug(exception, service, durationMs, expose);
1941
2003
  return {
1942
2004
  response: {
1943
2005
  success: false,
@@ -1952,7 +2014,7 @@ var ErrorResponseBuilder = class {
1952
2014
  path,
1953
2015
  status
1954
2016
  },
1955
- ...debug$1 !== void 0 ? { debug: debug$1 } : {}
2017
+ ...debug !== void 0 ? { debug } : {}
1956
2018
  },
1957
2019
  httpStatus: status
1958
2020
  };
@@ -1978,7 +2040,6 @@ var ErrorResponseBuilder = class {
1978
2040
  };
1979
2041
  }
1980
2042
  };
2043
+ export { DEFAULT_LOG_LEVELS as C, DEFAULT_LOG_COLORS as S, serializeError as _, isLogixiaException as a, usePlugin as b, _shutdownRegistrySize as c, registerForShutdown as d, resetShutdownHandlers as f, normalizeError as g, isError as h, LogixiaException as i, deregisterFromShutdown as l, redactObject as m, generateRequestId as n, LogixiaLogger as o, applyRedaction as p, generateTraceId as r, createLogger as s, ErrorResponseBuilder as t, flushOnExit as u, PluginRegistry as v, LogLevel as w, DEFAULT_CONFIG as x, globalPluginRegistry as y };
1981
2044
 
1982
- //#endregion
1983
- export { globalPluginRegistry as C, DEFAULT_LOG_LEVELS as D, DEFAULT_LOG_COLORS as E, LogLevel as O, PluginRegistry as S, DEFAULT_CONFIG as T, getOtelMetaFields as _, isLogixiaException as a, normalizeError as b, _shutdownRegistrySize as c, registerForShutdown as d, resetShutdownHandlers as f, getActiveOtelContext as g, disableOtelBridge as h, LogixiaException as i, deregisterFromShutdown as l, redactObject as m, generateRequestId as n, LogixiaLogger as o, applyRedaction as p, generateTraceId as r, createLogger as s, ErrorResponseBuilder as t, flushOnExit as u, initOtelBridge as v, usePlugin as w, serializeError as x, isError as y };
1984
- //# sourceMappingURL=builder-0gEzRopq.mjs.map
2045
+ //# sourceMappingURL=builder-DhNhvOkt.mjs.map