@logtape/logtape 2.3.0-dev.793 → 2.3.0-dev.797

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.cjs CHANGED
@@ -9,6 +9,7 @@ const require_sink = require('./sink.cjs');
9
9
  */
10
10
  let currentConfig = null;
11
11
  let activeScopedConfigCount = 0;
12
+ let globalConfigMutationInProgress = false;
12
13
  /**
13
14
  * Strong references to the loggers.
14
15
  * This is to prevent the loggers from being garbage collected so that their
@@ -39,7 +40,7 @@ function isLoggerConfigMeta(cfg) {
39
40
  return category.length === 0 || category.length === 1 && category[0] === "logtape" || category.length === 2 && category[0] === "logtape" && category[1] === "meta";
40
41
  }
41
42
  function registerDisposeHook(allowAsync) {
42
- const handler = allowAsync ? dispose : disposeSync;
43
+ const handler = allowAsync ? disposeInternal : disposeSyncInternal;
43
44
  if (typeof globalThis.EdgeRuntime !== "string" && "process" in globalThis && !("Deno" in globalThis)) {
44
45
  const proc = globalThis.process;
45
46
  const onMethod = proc?.["on"];
@@ -93,15 +94,20 @@ function registerDisposeHook(allowAsync) {
93
94
  * @param config The configuration.
94
95
  */
95
96
  async function configure(config) {
96
- assertNoScopedConfig("configure()");
97
- if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
98
- await reset();
99
- try {
100
- configureInternal(config, true);
101
- } catch (e) {
102
- if (e instanceof ConfigError) await reset();
103
- throw e;
104
- }
97
+ await runGlobalConfigMutation("configure()", async () => {
98
+ if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
99
+ await disposeInternal();
100
+ resetInternal();
101
+ try {
102
+ configureInternal(config, true);
103
+ } catch (e) {
104
+ if (e instanceof ConfigError) {
105
+ await disposeInternal();
106
+ resetInternal();
107
+ }
108
+ throw e;
109
+ }
110
+ });
105
111
  }
106
112
  /**
107
113
  * Configure sync loggers with the specified configuration.
@@ -137,16 +143,21 @@ async function configure(config) {
137
143
  * @since 0.9.0
138
144
  */
139
145
  function configureSync(config) {
140
- assertNoScopedConfig("configureSync()");
141
- if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
142
- if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
143
- resetSync();
144
- try {
145
- configureInternal(config, false);
146
- } catch (e) {
147
- if (e instanceof ConfigError) resetSync();
148
- throw e;
149
- }
146
+ runGlobalConfigMutationSync("configureSync()", () => {
147
+ if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
148
+ if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
149
+ disposeSyncInternal();
150
+ resetInternal();
151
+ try {
152
+ configureInternal(config, false);
153
+ } catch (e) {
154
+ if (e instanceof ConfigError) {
155
+ disposeSyncInternal();
156
+ resetInternal();
157
+ }
158
+ throw e;
159
+ }
160
+ });
150
161
  }
151
162
  /**
152
163
  * Runs a callback with a LogTape configuration scoped to the current execution
@@ -289,9 +300,10 @@ function getConfig() {
289
300
  * Reset the configuration. Mostly for testing purposes.
290
301
  */
291
302
  async function reset() {
292
- assertNoScopedConfig("reset()");
293
- await dispose();
294
- resetInternal();
303
+ await runGlobalConfigMutation("reset()", async () => {
304
+ await disposeInternal();
305
+ resetInternal();
306
+ });
295
307
  }
296
308
  /**
297
309
  * Reset the configuration. Mostly for testing purposes. Will not clear async
@@ -299,9 +311,10 @@ async function reset() {
299
311
  * @since 0.9.0
300
312
  */
301
313
  function resetSync() {
302
- assertNoScopedConfig("resetSync()");
303
- disposeSync();
304
- resetInternal();
314
+ runGlobalConfigMutationSync("resetSync()", () => {
315
+ disposeSyncInternal();
316
+ resetInternal();
317
+ });
305
318
  }
306
319
  function resetInternal() {
307
320
  const rootLogger = require_logger.LoggerImpl.getLogger([]);
@@ -314,7 +327,9 @@ function resetInternal() {
314
327
  * Dispose of the disposables.
315
328
  */
316
329
  async function dispose() {
317
- assertNoScopedConfig("dispose()");
330
+ await runGlobalConfigMutation("dispose()", disposeInternal);
331
+ }
332
+ async function disposeInternal() {
318
333
  const errors = [];
319
334
  try {
320
335
  disposeSyncFilters();
@@ -344,7 +359,9 @@ async function dispose() {
344
359
  * @since 0.9.0
345
360
  */
346
361
  function disposeSync() {
347
- assertNoScopedConfig("disposeSync()");
362
+ runGlobalConfigMutationSync("disposeSync()", disposeSyncInternal);
363
+ }
364
+ function disposeSyncInternal() {
348
365
  const errors = [];
349
366
  try {
350
367
  disposeSyncFilters();
@@ -359,11 +376,34 @@ function disposeSync() {
359
376
  throwDisposeErrors(errors);
360
377
  }
361
378
  function getConfiguredContextLocalStorage(functionName) {
379
+ if (globalConfigMutationInProgress) throw new ConfigError(`${functionName} cannot be called while LogTape is being reconfigured.`);
362
380
  if (currentConfig == null) throw new ConfigError(`${functionName} requires LogTape to be configured first.`);
363
381
  const contextLocalStorage = require_logger.LoggerImpl.getLogger().contextLocalStorage;
364
382
  if (contextLocalStorage == null) throw new ConfigError(`${functionName} requires Config.contextLocalStorage to be configured.`);
365
383
  return contextLocalStorage;
366
384
  }
385
+ async function runGlobalConfigMutation(functionName, callback) {
386
+ assertCanMutateGlobalConfig(functionName);
387
+ globalConfigMutationInProgress = true;
388
+ try {
389
+ return await callback();
390
+ } finally {
391
+ globalConfigMutationInProgress = false;
392
+ }
393
+ }
394
+ function runGlobalConfigMutationSync(functionName, callback) {
395
+ assertCanMutateGlobalConfig(functionName);
396
+ globalConfigMutationInProgress = true;
397
+ try {
398
+ return callback();
399
+ } finally {
400
+ globalConfigMutationInProgress = false;
401
+ }
402
+ }
403
+ function assertCanMutateGlobalConfig(functionName) {
404
+ if (globalConfigMutationInProgress) throw new ConfigError(`${functionName} cannot be called while LogTape is being reconfigured.`);
405
+ assertNoScopedConfig(functionName);
406
+ }
367
407
  function assertNoScopedConfig(functionName) {
368
408
  if (activeScopedConfigCount > 0) throw new ConfigError(`${functionName} cannot be called while a scoped configuration is active. Use nested withConfig() instead.`);
369
409
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAiBA;AAAuB,UAAN,MAAM,CAAA,gBAAA,MAAA,EAAA,kBAAA,MAAA,CAAA,CAAA;EAAA;;;;EAUK,KAAE,EALrB,MAKqB,CALd,OAKc,EALL,IAKK,CAAA;EAAU;;;;EAKjB,OAMqB,CAAA,EAXhC,MAWgC,CAXzB,SAWyB,EAXd,UAWc,CAAA;EAAM;AAAP;AAkB3C;EAAwB,OAAA,EAxBb,YAwBa,CAxBA,OAwBA,EAxBS,SAwBT,CAAA,EAAA;EAAA;;;AACN;EAEb,mBAAA,CAAA,EArBmB,mBAqBD,CArBqB,MAqBrB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EAAA;;;EAAuC,KAC1D,CAAA,EAAA,OAAA;AAAO;AAKX;;;;;AAoCwB;AAyHxB;;;;AAGU,KAzKE,YAyKF,CAAA,gBAAA,MAAA,EAAA,kBAAA,MAAA,CAAA,GAxKR,gBAwKQ,CAxKS,OAwKT,EAxKkB,SAwKlB,CAAA;KAtKL,kBAsKkC,CAAA,OAAA,CAAA,GAtKJ,OAsKI,SAtKY,WAsKZ,CAAA,OAAA,CAAA,GAAA,KAAA,GArKnC,OAqKmC;AAAO;AAiD9C;;AACiB,UAlNA,YAkNA,CAAA,gBAAA,MAAA,EAAA,kBAAA,MAAA,CAAA,CAAA;EAAO;;AAAR;AAoChB;EAAgC,QAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAAA;;;EAKV,KACJ,CAAA,EA/OR,OA+OQ,EAAA;EAAO;;;AACf;AAiDV;;;;;EAKsB,WACe,CAAA,EAAA,SAAA,GAAA,UAAA;EAAO;;;EACvB,OAAA,CAAA,EAxRT,SAwRS,EAAA;EAyJL;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AO;;;EACvB,OAAA,CAAA,EAnST,SAmSS,EAAA;EAyJL;AAOhB;AAYA;AAkBA;AAkCA;EAoKa,WAAA,CAAA,EAhqBG,QAgqBS,GAAQ,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAtiBX,oEAGZ,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDvB,wEACN,OAAO,SAAS;;;;;;;;;;;;;;iBAyCJ,8EAKZ,aAAa,SAAS,4BACd,UACf,QAAQ,QAAQ;;;;;;;;;;;;iBAiDH,kFAKN,aAAa,SAAS,4BACd,mBAAmB,WAClC,mBAAmB;;;;;iBAyJN,SAAA,CAAA,GAAa;;;;iBAOP,KAAA,CAAA,GAAS;;;;;;iBAYf,SAAA,CAAA;;;;iBAkBM,OAAA,CAAA,GAAW;;;;;;iBAkCjB,WAAA,CAAA;;;;cAoKH,WAAA,SAAoB,KAAK"}
package/dist/config.js CHANGED
@@ -9,6 +9,7 @@ import { getConsoleSink } from "./sink.js";
9
9
  */
10
10
  let currentConfig = null;
11
11
  let activeScopedConfigCount = 0;
12
+ let globalConfigMutationInProgress = false;
12
13
  /**
13
14
  * Strong references to the loggers.
14
15
  * This is to prevent the loggers from being garbage collected so that their
@@ -39,7 +40,7 @@ function isLoggerConfigMeta(cfg) {
39
40
  return category.length === 0 || category.length === 1 && category[0] === "logtape" || category.length === 2 && category[0] === "logtape" && category[1] === "meta";
40
41
  }
41
42
  function registerDisposeHook(allowAsync) {
42
- const handler = allowAsync ? dispose : disposeSync;
43
+ const handler = allowAsync ? disposeInternal : disposeSyncInternal;
43
44
  if (typeof globalThis.EdgeRuntime !== "string" && "process" in globalThis && !("Deno" in globalThis)) {
44
45
  const proc = globalThis.process;
45
46
  const onMethod = proc?.["on"];
@@ -93,15 +94,20 @@ function registerDisposeHook(allowAsync) {
93
94
  * @param config The configuration.
94
95
  */
95
96
  async function configure(config) {
96
- assertNoScopedConfig("configure()");
97
- if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
98
- await reset();
99
- try {
100
- configureInternal(config, true);
101
- } catch (e) {
102
- if (e instanceof ConfigError) await reset();
103
- throw e;
104
- }
97
+ await runGlobalConfigMutation("configure()", async () => {
98
+ if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
99
+ await disposeInternal();
100
+ resetInternal();
101
+ try {
102
+ configureInternal(config, true);
103
+ } catch (e) {
104
+ if (e instanceof ConfigError) {
105
+ await disposeInternal();
106
+ resetInternal();
107
+ }
108
+ throw e;
109
+ }
110
+ });
105
111
  }
106
112
  /**
107
113
  * Configure sync loggers with the specified configuration.
@@ -137,16 +143,21 @@ async function configure(config) {
137
143
  * @since 0.9.0
138
144
  */
139
145
  function configureSync(config) {
140
- assertNoScopedConfig("configureSync()");
141
- if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
142
- if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
143
- resetSync();
144
- try {
145
- configureInternal(config, false);
146
- } catch (e) {
147
- if (e instanceof ConfigError) resetSync();
148
- throw e;
149
- }
146
+ runGlobalConfigMutationSync("configureSync()", () => {
147
+ if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
148
+ if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
149
+ disposeSyncInternal();
150
+ resetInternal();
151
+ try {
152
+ configureInternal(config, false);
153
+ } catch (e) {
154
+ if (e instanceof ConfigError) {
155
+ disposeSyncInternal();
156
+ resetInternal();
157
+ }
158
+ throw e;
159
+ }
160
+ });
150
161
  }
151
162
  /**
152
163
  * Runs a callback with a LogTape configuration scoped to the current execution
@@ -289,9 +300,10 @@ function getConfig() {
289
300
  * Reset the configuration. Mostly for testing purposes.
290
301
  */
291
302
  async function reset() {
292
- assertNoScopedConfig("reset()");
293
- await dispose();
294
- resetInternal();
303
+ await runGlobalConfigMutation("reset()", async () => {
304
+ await disposeInternal();
305
+ resetInternal();
306
+ });
295
307
  }
296
308
  /**
297
309
  * Reset the configuration. Mostly for testing purposes. Will not clear async
@@ -299,9 +311,10 @@ async function reset() {
299
311
  * @since 0.9.0
300
312
  */
301
313
  function resetSync() {
302
- assertNoScopedConfig("resetSync()");
303
- disposeSync();
304
- resetInternal();
314
+ runGlobalConfigMutationSync("resetSync()", () => {
315
+ disposeSyncInternal();
316
+ resetInternal();
317
+ });
305
318
  }
306
319
  function resetInternal() {
307
320
  const rootLogger = LoggerImpl.getLogger([]);
@@ -314,7 +327,9 @@ function resetInternal() {
314
327
  * Dispose of the disposables.
315
328
  */
316
329
  async function dispose() {
317
- assertNoScopedConfig("dispose()");
330
+ await runGlobalConfigMutation("dispose()", disposeInternal);
331
+ }
332
+ async function disposeInternal() {
318
333
  const errors = [];
319
334
  try {
320
335
  disposeSyncFilters();
@@ -344,7 +359,9 @@ async function dispose() {
344
359
  * @since 0.9.0
345
360
  */
346
361
  function disposeSync() {
347
- assertNoScopedConfig("disposeSync()");
362
+ runGlobalConfigMutationSync("disposeSync()", disposeSyncInternal);
363
+ }
364
+ function disposeSyncInternal() {
348
365
  const errors = [];
349
366
  try {
350
367
  disposeSyncFilters();
@@ -359,11 +376,34 @@ function disposeSync() {
359
376
  throwDisposeErrors(errors);
360
377
  }
361
378
  function getConfiguredContextLocalStorage(functionName) {
379
+ if (globalConfigMutationInProgress) throw new ConfigError(`${functionName} cannot be called while LogTape is being reconfigured.`);
362
380
  if (currentConfig == null) throw new ConfigError(`${functionName} requires LogTape to be configured first.`);
363
381
  const contextLocalStorage = LoggerImpl.getLogger().contextLocalStorage;
364
382
  if (contextLocalStorage == null) throw new ConfigError(`${functionName} requires Config.contextLocalStorage to be configured.`);
365
383
  return contextLocalStorage;
366
384
  }
385
+ async function runGlobalConfigMutation(functionName, callback) {
386
+ assertCanMutateGlobalConfig(functionName);
387
+ globalConfigMutationInProgress = true;
388
+ try {
389
+ return await callback();
390
+ } finally {
391
+ globalConfigMutationInProgress = false;
392
+ }
393
+ }
394
+ function runGlobalConfigMutationSync(functionName, callback) {
395
+ assertCanMutateGlobalConfig(functionName);
396
+ globalConfigMutationInProgress = true;
397
+ try {
398
+ return callback();
399
+ } finally {
400
+ globalConfigMutationInProgress = false;
401
+ }
402
+ }
403
+ function assertCanMutateGlobalConfig(functionName) {
404
+ if (globalConfigMutationInProgress) throw new ConfigError(`${functionName} cannot be called while LogTape is being reconfigured.`);
405
+ assertNoScopedConfig(functionName);
406
+ }
367
407
  function assertNoScopedConfig(functionName) {
368
408
  if (activeScopedConfigCount > 0) throw new ConfigError(`${functionName} cannot be called while a scoped configuration is active. Use nested withConfig() instead.`);
369
409
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":["currentConfig: Config<string, string> | null","strongRefs: Set<LoggerImpl>","filterDisposables: Set<Disposable>","sinkDisposables: Set<Disposable>","asyncFilterDisposables: Set<AsyncDisposable>","asyncSinkDisposables: Set<AsyncDisposable>","cfg: LoggerConfig<TSinkId, TFilterId>","allowAsync: boolean","config: Config<TSinkId, TFilterId>","config: ScopedConfig<TSinkId, TFilterId>","callback: () => TResult","result: Awaited<TResult>","callbackError: unknown","callback: () => SyncCallbackResult<TResult>","result: SyncCallbackResult<TResult>","value: unknown","errors: unknown[]","functionName: string","disposables: Set<Disposable>","disposables: Set<AsyncDisposable>","promises: PromiseLike<void>[]","promises: readonly PromiseLike<void>[]","errors: readonly unknown[]","message: string"],"sources":["../src/config.ts"],"sourcesContent":["import type { ContextLocalStorage } from \"./context.ts\";\nimport { type FilterLike, toFilter } from \"./filter.ts\";\nimport type { LogLevel } from \"./level.ts\";\nimport { LoggerImpl } from \"./logger.ts\";\nimport {\n compileScopedConfig,\n disposeScopedConfig,\n disposeScopedConfigSync,\n runWithScopedConfig,\n type ScopedConfigLike,\n throwCombinedErrors,\n} from \"./scoped-config.ts\";\nimport { getConsoleSink, type Sink } from \"./sink.ts\";\n\n/**\n * A configuration for the loggers.\n */\nexport interface Config<TSinkId extends string, TFilterId extends string> {\n /**\n * The sinks to use. The keys are the sink identifiers, and the values are\n * {@link Sink}s.\n */\n sinks: Record<TSinkId, Sink>;\n /**\n * The filters to use. The keys are the filter identifiers, and the values\n * are either {@link Filter}s or {@link LogLevel}s.\n */\n filters?: Record<TFilterId, FilterLike>;\n\n /**\n * The loggers to configure.\n */\n loggers: LoggerConfig<TSinkId, TFilterId>[];\n\n /**\n * The context-local storage to use for implicit contexts.\n * @since 0.7.0\n */\n contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;\n\n /**\n * Whether to reset the configuration before applying this one.\n */\n reset?: boolean;\n}\n\n/**\n * A scoped configuration for the current execution context.\n *\n * Unlike {@link Config}, this type does not include `reset` or\n * `contextLocalStorage`. Scoped configuration changes only the logging policy\n * for a callback; the context-local storage must already be initialized by the\n * process-global configuration.\n *\n * @since 2.3.0\n */\nexport type ScopedConfig<TSinkId extends string, TFilterId extends string> =\n ScopedConfigLike<TSinkId, TFilterId>;\n\ntype SyncCallbackResult<TResult> = TResult extends PromiseLike<unknown> ? never\n : TResult;\n\n/**\n * A logger configuration.\n */\nexport interface LoggerConfig<\n TSinkId extends string,\n TFilterId extends string,\n> {\n /**\n * The category of the logger. If a string, it is equivalent to an array\n * with one element.\n */\n category: string | string[];\n\n /**\n * The sink identifiers to use.\n */\n sinks?: TSinkId[];\n\n /**\n * Whether to inherit the parent's sinks. If `inherit`, the parent's sinks\n * are used along with the specified sinks. If `override`, the parent's\n * sinks are not used, and only the specified sinks are used.\n *\n * The default is `inherit`.\n * @default `\"inherit\"\n * @since 0.6.0\n */\n parentSinks?: \"inherit\" | \"override\";\n\n /**\n * The filter identifiers to use.\n */\n filters?: TFilterId[];\n\n /**\n * The lowest log level to accept. If `null`, the logger will reject all\n * records.\n * @since 0.8.0\n */\n lowestLevel?: LogLevel | null;\n}\n\n/**\n * The current configuration, if any. Otherwise, `null`.\n */\nlet currentConfig: Config<string, string> | null = null;\nlet activeScopedConfigCount = 0;\n\n/**\n * Strong references to the loggers.\n * This is to prevent the loggers from being garbage collected so that their\n * sinks and filters are not removed.\n */\nconst strongRefs: Set<LoggerImpl> = new Set();\n\n/**\n * Sync filter disposables to dispose when resetting the configuration.\n */\nconst filterDisposables: Set<Disposable> = new Set();\n\n/**\n * Sync sink disposables to dispose when resetting the configuration.\n */\nconst sinkDisposables: Set<Disposable> = new Set();\n\n/**\n * Async filter disposables to dispose when resetting the configuration.\n */\nconst asyncFilterDisposables: Set<AsyncDisposable> = new Set();\n\n/**\n * Async sink disposables to dispose when resetting the configuration.\n */\nconst asyncSinkDisposables: Set<AsyncDisposable> = new Set();\n\n/**\n * Check if a config is for the meta logger.\n */\nfunction isLoggerConfigMeta<TSinkId extends string, TFilterId extends string>(\n cfg: LoggerConfig<TSinkId, TFilterId>,\n): boolean {\n const category = Array.isArray(cfg.category) ? cfg.category : [cfg.category];\n return category.length === 0 ||\n (category.length === 1 && category[0] === \"logtape\") ||\n (category.length === 2 &&\n category[0] === \"logtape\" &&\n category[1] === \"meta\");\n}\n\nfunction registerDisposeHook(allowAsync: boolean): void {\n const handler = allowAsync ? dispose : disposeSync;\n\n if (\n // deno-lint-ignore no-explicit-any\n typeof (globalThis as any).EdgeRuntime !== \"string\" &&\n \"process\" in globalThis &&\n !(\"Deno\" in globalThis)\n ) {\n // deno-lint-ignore no-explicit-any\n const proc = (globalThis as any).process;\n // Use bracket notation to avoid static analysis detection in Edge Runtime.\n const onMethod = proc?.[\"on\"];\n if (typeof onMethod === \"function\") {\n onMethod.call(proc, \"exit\", handler);\n return;\n }\n }\n\n // Some edge runtimes expose neither process.on() nor addEventListener().\n // In those environments users can still call dispose()/disposeSync() manually.\n // deno-lint-ignore no-explicit-any\n const addEventListenerMethod = (globalThis as any).addEventListener;\n if (typeof addEventListenerMethod !== \"function\") return;\n\n if (\"Deno\" in globalThis) {\n addEventListenerMethod.call(globalThis, \"unload\", handler);\n } else {\n addEventListenerMethod.call(globalThis, \"pagehide\", handler);\n }\n}\n\n/**\n * Configure the loggers with the specified configuration.\n *\n * Note that if the given sinks or filters are disposable, they will be\n * disposed when the configuration is reset, or when the process exits.\n *\n * @example\n * ```typescript\n * await configure({\n * sinks: {\n * console: getConsoleSink(),\n * },\n * filters: {\n * slow: (log) =>\n * \"duration\" in log.properties &&\n * log.properties.duration as number > 1000,\n * },\n * loggers: [\n * {\n * category: \"my-app\",\n * sinks: [\"console\"],\n * lowestLevel: \"info\",\n * },\n * {\n * category: [\"my-app\", \"sql\"],\n * filters: [\"slow\"],\n * lowestLevel: \"debug\",\n * },\n * {\n * category: \"logtape\",\n * sinks: [\"console\"],\n * lowestLevel: \"error\",\n * },\n * ],\n * });\n * ```\n *\n * @param config The configuration.\n */\nexport async function configure<\n TSinkId extends string,\n TFilterId extends string,\n>(config: Config<TSinkId, TFilterId>): Promise<void> {\n assertNoScopedConfig(\"configure()\");\n if (currentConfig != null && !config.reset) {\n throw new ConfigError(\n \"Already configured; if you want to reset, turn on the reset flag.\",\n );\n }\n await reset();\n try {\n configureInternal(config, true);\n } catch (e) {\n if (e instanceof ConfigError) await reset();\n throw e;\n }\n}\n\n/**\n * Configure sync loggers with the specified configuration.\n *\n * Note that if the given sinks or filters are disposable, they will be\n * disposed when the configuration is reset, or when the process exits.\n *\n * Also note that passing async sinks or filters will throw. If\n * necessary use {@link resetSync} or {@link disposeSync}.\n *\n * @example\n * ```typescript\n * configureSync({\n * sinks: {\n * console: getConsoleSink(),\n * },\n * loggers: [\n * {\n * category: \"my-app\",\n * sinks: [\"console\"],\n * lowestLevel: \"info\",\n * },\n * {\n * category: \"logtape\",\n * sinks: [\"console\"],\n * lowestLevel: \"error\",\n * },\n * ],\n * });\n * ```\n *\n * @param config The configuration.\n * @since 0.9.0\n */\nexport function configureSync<TSinkId extends string, TFilterId extends string>(\n config: Config<TSinkId, TFilterId>,\n): void {\n assertNoScopedConfig(\"configureSync()\");\n if (currentConfig != null && !config.reset) {\n throw new ConfigError(\n \"Already configured; if you want to reset, turn on the reset flag.\",\n );\n }\n if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) {\n throw new ConfigError(\n \"Previously configured async disposables are still active. \" +\n \"Use configure() instead or explicitly dispose them using dispose().\",\n );\n }\n resetSync();\n try {\n configureInternal(config, false);\n } catch (e) {\n if (e instanceof ConfigError) resetSync();\n throw e;\n }\n}\n\n/**\n * Runs a callback with a LogTape configuration scoped to the current execution\n * context.\n *\n * The process-global configuration must already provide\n * `contextLocalStorage`. The scoped configuration fully overrides global\n * logger routing while the callback and its async work run.\n *\n * @param config The scoped configuration.\n * @param callback The callback to run.\n * @returns The callback's resolved return value.\n * @since 2.3.0\n */\nexport async function withConfig<\n TSinkId extends string,\n TFilterId extends string,\n TResult,\n>(\n config: ScopedConfig<TSinkId, TFilterId>,\n callback: () => TResult,\n): Promise<Awaited<TResult>> {\n const contextLocalStorage = getConfiguredContextLocalStorage(\"withConfig()\");\n const scopedConfig = compileScopedConfig(\n config,\n true,\n (message) => new ConfigError(message),\n );\n\n let result: Awaited<TResult>;\n let callbackError: unknown;\n let callbackFailed = false;\n activeScopedConfigCount++;\n try {\n result = await runWithScopedConfig(\n contextLocalStorage,\n scopedConfig,\n callback,\n );\n } catch (error) {\n callbackFailed = true;\n callbackError = error;\n }\n\n try {\n await disposeScopedConfig(scopedConfig);\n } catch (disposeError) {\n if (callbackFailed) {\n throwCombinedErrors(callbackError, disposeError);\n }\n throw disposeError;\n } finally {\n activeScopedConfigCount--;\n }\n\n if (callbackFailed) throw callbackError;\n return result!;\n}\n\n/**\n * Runs a synchronous callback with a LogTape configuration scoped to the\n * current execution context.\n *\n * The scoped configuration must not contain async disposable sinks or filters.\n *\n * @param config The scoped configuration.\n * @param callback The callback to run.\n * @returns The callback's return value.\n * @since 2.3.0\n */\nexport function withConfigSync<\n TSinkId extends string,\n TFilterId extends string,\n TResult,\n>(\n config: ScopedConfig<TSinkId, TFilterId>,\n callback: () => SyncCallbackResult<TResult>,\n): SyncCallbackResult<TResult> {\n const contextLocalStorage = getConfiguredContextLocalStorage(\n \"withConfigSync()\",\n );\n const scopedConfig = compileScopedConfig(\n config,\n false,\n (message) => new ConfigError(message),\n );\n\n let result: SyncCallbackResult<TResult>;\n let callbackError: unknown;\n let callbackFailed = false;\n activeScopedConfigCount++;\n try {\n result = runWithScopedConfig(contextLocalStorage, scopedConfig, callback);\n if (isThenable(result)) {\n void Promise.resolve(result).catch(() => {});\n callbackFailed = true;\n callbackError = new ConfigError(\n \"withConfigSync() callback must not return a promise. \" +\n \"Use withConfig() for async callbacks.\",\n );\n }\n } catch (error) {\n callbackFailed = true;\n callbackError = error;\n }\n\n try {\n disposeScopedConfigSync(scopedConfig);\n } catch (disposeError) {\n if (callbackFailed) {\n throwCombinedErrors(callbackError, disposeError);\n }\n throw disposeError;\n } finally {\n activeScopedConfigCount--;\n }\n\n if (callbackFailed) throw callbackError;\n return result!;\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n \"then\" in value &&\n typeof value.then === \"function\";\n}\n\nfunction configureInternal<\n TSinkId extends string,\n TFilterId extends string,\n>(config: Config<TSinkId, TFilterId>, allowAsync: boolean): void {\n currentConfig = config;\n\n let metaConfigured = false;\n const configuredCategories = new Set<string>();\n\n for (const cfg of config.loggers) {\n if (isLoggerConfigMeta(cfg)) {\n metaConfigured = true;\n }\n\n // Check for duplicate logger categories\n const categoryKey = Array.isArray(cfg.category)\n ? JSON.stringify(cfg.category)\n : JSON.stringify([cfg.category]);\n if (configuredCategories.has(categoryKey)) {\n throw new ConfigError(\n `Duplicate logger configuration for category: ${categoryKey}. ` +\n `Each category can only be configured once.`,\n );\n }\n configuredCategories.add(categoryKey);\n\n const logger = LoggerImpl.getLogger(cfg.category);\n for (const sinkId of cfg.sinks ?? []) {\n const sink = config.sinks[sinkId];\n if (!sink) {\n throw new ConfigError(`Sink not found: ${sinkId}.`);\n }\n logger.sinks.push(sink);\n }\n logger.parentSinks = cfg.parentSinks ?? \"inherit\";\n if (cfg.lowestLevel !== undefined) {\n logger.lowestLevel = cfg.lowestLevel;\n }\n for (const filterId of cfg.filters ?? []) {\n const filter = config.filters?.[filterId];\n if (filter === undefined) {\n throw new ConfigError(`Filter not found: ${filterId}.`);\n }\n logger.filters.push(toFilter(filter));\n }\n strongRefs.add(logger);\n }\n\n LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;\n\n for (const sink of Object.values<Sink>(config.sinks)) {\n if (Symbol.asyncDispose in sink) {\n if (allowAsync) asyncSinkDisposables.add(sink as AsyncDisposable);\n else {\n throw new ConfigError(\n \"Async disposables cannot be used with configureSync().\",\n );\n }\n }\n if (Symbol.dispose in sink) sinkDisposables.add(sink as Disposable);\n }\n\n for (const filter of Object.values<FilterLike>(config.filters ?? {})) {\n if (filter == null || typeof filter === \"string\") continue;\n if (Symbol.asyncDispose in filter) {\n if (allowAsync) asyncFilterDisposables.add(filter as AsyncDisposable);\n else {\n throw new ConfigError(\n \"Async disposables cannot be used with configureSync().\",\n );\n }\n asyncSinkDisposables.delete(filter as AsyncDisposable);\n }\n if (Symbol.dispose in filter) {\n filterDisposables.add(filter as Disposable);\n sinkDisposables.delete(filter as Disposable);\n }\n }\n\n registerDisposeHook(allowAsync);\n const meta = LoggerImpl.getLogger([\"logtape\", \"meta\"]);\n if (!metaConfigured) {\n meta.sinks.push(getConsoleSink());\n }\n\n meta.info(\n \"LogTape loggers are configured. Note that LogTape itself uses the meta \" +\n \"logger, which has category {metaLoggerCategory}. The meta logger is \" +\n \"used to log internal diagnostics such as sink exceptions. \" +\n \"It's recommended to configure the meta logger with a separate sink \" +\n \"so that you can easily notice if logging itself fails or is \" +\n \"misconfigured. To turn off this message, configure the meta logger \" +\n \"with higher log levels than {dismissLevel}. See also \" +\n \"<https://logtape.org/manual/categories#meta-logger>.\",\n { metaLoggerCategory: [\"logtape\", \"meta\"], dismissLevel: \"info\" },\n );\n}\n\n/**\n * Get the current configuration, if any. Otherwise, `null`.\n * @returns The current configuration, if any. Otherwise, `null`.\n */\nexport function getConfig(): Config<string, string> | null {\n return currentConfig;\n}\n\n/**\n * Reset the configuration. Mostly for testing purposes.\n */\nexport async function reset(): Promise<void> {\n assertNoScopedConfig(\"reset()\");\n await dispose();\n resetInternal();\n}\n\n/**\n * Reset the configuration. Mostly for testing purposes. Will not clear async\n * sinks, only use with sync sinks. Use {@link reset} if you have async sinks.\n * @since 0.9.0\n */\nexport function resetSync(): void {\n assertNoScopedConfig(\"resetSync()\");\n disposeSync();\n resetInternal();\n}\n\nfunction resetInternal(): void {\n const rootLogger = LoggerImpl.getLogger([]);\n rootLogger.resetDescendants();\n delete rootLogger.contextLocalStorage;\n strongRefs.clear();\n currentConfig = null;\n}\n\n/**\n * Dispose of the disposables.\n */\nexport async function dispose(): Promise<void> {\n assertNoScopedConfig(\"dispose()\");\n const errors: unknown[] = [];\n try {\n disposeSyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n await disposeAsyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n disposeSyncSinks();\n } catch (error) {\n errors.push(error);\n }\n try {\n await disposeAsyncSinks();\n } catch (error) {\n errors.push(error);\n }\n throwDisposeErrors(errors);\n}\n\n/**\n * Dispose of the sync disposables. Async disposables will be untouched,\n * use {@link dispose} if you have async sinks.\n * @since 0.9.0\n */\nexport function disposeSync(): void {\n assertNoScopedConfig(\"disposeSync()\");\n const errors: unknown[] = [];\n try {\n disposeSyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n disposeSyncSinks();\n } catch (error) {\n errors.push(error);\n }\n throwDisposeErrors(errors);\n}\n\nfunction getConfiguredContextLocalStorage(\n functionName: string,\n): ContextLocalStorage<Record<string, unknown>> {\n if (currentConfig == null) {\n throw new ConfigError(\n `${functionName} requires LogTape to be configured first.`,\n );\n }\n const contextLocalStorage = LoggerImpl.getLogger().contextLocalStorage;\n if (contextLocalStorage == null) {\n throw new ConfigError(\n `${functionName} requires Config.contextLocalStorage to be configured.`,\n );\n }\n return contextLocalStorage;\n}\n\nfunction assertNoScopedConfig(functionName: string): void {\n if (activeScopedConfigCount > 0) {\n throw new ConfigError(\n `${functionName} cannot be called while a scoped configuration is ` +\n \"active. Use nested withConfig() instead.\",\n );\n }\n}\n\nfunction disposeSyncFilters(): void {\n disposeSyncDisposables(filterDisposables);\n}\n\nfunction disposeSyncSinks(): void {\n disposeSyncDisposables(sinkDisposables);\n}\n\nfunction disposeSyncDisposables(disposables: Set<Disposable>): void {\n const errors: unknown[] = [];\n try {\n for (const disposable of disposables) {\n try {\n disposable[Symbol.dispose]();\n } catch (error) {\n errors.push(error);\n } finally {\n disposables.delete(disposable);\n }\n }\n } finally {\n disposables.clear();\n }\n throwDisposeErrors(errors);\n}\n\nasync function disposeAsyncFilters(): Promise<void> {\n await disposeAsyncDisposables(asyncFilterDisposables);\n}\n\nasync function disposeAsyncSinks(): Promise<void> {\n await disposeAsyncDisposables(asyncSinkDisposables);\n}\n\nasync function disposeAsyncDisposables(\n disposables: Set<AsyncDisposable>,\n): Promise<void> {\n const promises: PromiseLike<void>[] = [];\n try {\n for (const disposable of disposables) {\n try {\n promises.push(Promise.resolve(disposable[Symbol.asyncDispose]()));\n } catch (error) {\n promises.push(Promise.reject(error));\n } finally {\n disposables.delete(disposable);\n }\n }\n } finally {\n disposables.clear();\n }\n await settleDisposePromises(promises);\n}\n\nasync function settleDisposePromises(\n promises: readonly PromiseLike<void>[],\n): Promise<void> {\n const results = await Promise.allSettled(promises);\n throwDisposeErrors(\n results\n .filter((result): result is PromiseRejectedResult =>\n result.status === \"rejected\"\n )\n .map((result) => result.reason),\n );\n}\n\nfunction throwDisposeErrors(errors: readonly unknown[]): void {\n if (errors.length < 1) return;\n if (errors.length === 1) throw errors[0];\n throw new AggregateError(\n errors,\n \"Multiple errors occurred while disposing LogTape resources.\",\n );\n}\n\n/**\n * A configuration error.\n */\nexport class ConfigError extends Error {\n /**\n * Constructs a new configuration error.\n * @param message The error message.\n */\n constructor(message: string) {\n super(message);\n this.name = \"ConfigError\";\n }\n}\n"],"mappings":";;;;;;;;;AA2GA,IAAIA,gBAA+C;AACnD,IAAI,0BAA0B;;;;;;AAO9B,MAAMC,6BAA8B,IAAI;;;;AAKxC,MAAMC,oCAAqC,IAAI;;;;AAK/C,MAAMC,kCAAmC,IAAI;;;;AAK7C,MAAMC,yCAA+C,IAAI;;;;AAKzD,MAAMC,uCAA6C,IAAI;;;;AAKvD,SAAS,mBACPC,KACS;CACT,MAAM,WAAW,MAAM,QAAQ,IAAI,SAAS,GAAG,IAAI,WAAW,CAAC,IAAI,QAAS;AAC5E,QAAO,SAAS,WAAW,KACxB,SAAS,WAAW,KAAK,SAAS,OAAO,aACzC,SAAS,WAAW,KACnB,SAAS,OAAO,aAChB,SAAS,OAAO;AACrB;AAED,SAAS,oBAAoBC,YAA2B;CACtD,MAAM,UAAU,aAAa,UAAU;AAEvC,YAEU,WAAmB,gBAAgB,YAC3C,aAAa,gBACX,UAAU,aACZ;EAEA,MAAM,OAAQ,WAAmB;EAEjC,MAAM,WAAW,OAAO;AACxB,aAAW,aAAa,YAAY;AAClC,YAAS,KAAK,MAAM,QAAQ,QAAQ;AACpC;EACD;CACF;CAKD,MAAM,yBAA0B,WAAmB;AACnD,YAAW,2BAA2B,WAAY;AAElD,KAAI,UAAU,WACZ,wBAAuB,KAAK,YAAY,UAAU,QAAQ;KAE1D,wBAAuB,KAAK,YAAY,YAAY,QAAQ;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,eAAsB,UAGpBC,QAAmD;AACnD,sBAAqB,cAAc;AACnC,KAAI,iBAAiB,SAAS,OAAO,MACnC,OAAM,IAAI,YACR;AAGJ,OAAM,OAAO;AACb,KAAI;AACF,oBAAkB,Q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;AAED,eAAe,sBAAqC;AAClD,OAAM,wBAAwB,uBAAuB;AACtD;AAED,eAAe,oBAAmC;AAChD,OAAM,wBAAwB,qBAAqB;AACpD;AAED,eAAe,wBACbG,aACe;CACf,MAAMC,WAAgC,CAAE;AACxC,KAAI;AACF,OAAK,MAAM,cAAc,YACvB,KAAI;AACF,YAAS,KAAK,QAAQ,QAAQ,WAAW,OAAO,eAAe,CAAC,CAAC;EAClE,SAAQ,OAAO;AACd,YAAS,KAAK,QAAQ,OAAO,MAAM,CAAC;EACrC,UAAS;AACR,eAAY,OAAO,WAAW;EAC/B;CAEJ,UAAS;AACR,cAAY,OAAO;CACpB;AACD,OAAM,sBAAsB,SAAS;AACtC;AAED,eAAe,sBACbC,UACe;CACf,MAAM,UAAU,MAAM,QAAQ,WAAW,SAAS;AAClD,oBACE,QACG,OAAO,CAAC,WACP,OAAO,WAAW,WACnB,CACA,IAAI,CAAC,WAAW,OAAO,OAAO,CAClC;AACF;AAED,SAAS,mBAAmBC,QAAkC;AAC5D,KAAI,OAAO,SAAS,EAAG;AACvB,KAAI,OAAO,WAAW,EAAG,OAAM,OAAO;AACtC,OAAM,IAAI,eACR,QACA;AAEH;;;;AAKD,IAAa,cAAb,cAAiC,MAAM;;;;;CAKrC,YAAYC,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;CACb;AACF"}
1
+ {"version":3,"file":"config.js","names":["currentConfig: Config<string, string> | null","strongRefs: Set<LoggerImpl>","filterDisposables: Set<Disposable>","sinkDisposables: Set<Disposable>","asyncFilterDisposables: Set<AsyncDisposable>","asyncSinkDisposables: Set<AsyncDisposable>","cfg: LoggerConfig<TSinkId, TFilterId>","allowAsync: boolean","config: Config<TSinkId, TFilterId>","config: ScopedConfig<TSinkId, TFilterId>","callback: () => TResult","result: Awaited<TResult>","callbackError: unknown","callback: () => SyncCallbackResult<TResult>","result: SyncCallbackResult<TResult>","value: unknown","errors: unknown[]","functionName: string","callback: () => Promise<T>","callback: () => T","disposables: Set<Disposable>","disposables: Set<AsyncDisposable>","promises: PromiseLike<void>[]","promises: readonly PromiseLike<void>[]","errors: readonly unknown[]","message: string"],"sources":["../src/config.ts"],"sourcesContent":["import type { ContextLocalStorage } from \"./context.ts\";\nimport { type FilterLike, toFilter } from \"./filter.ts\";\nimport type { LogLevel } from \"./level.ts\";\nimport { LoggerImpl } from \"./logger.ts\";\nimport {\n compileScopedConfig,\n disposeScopedConfig,\n disposeScopedConfigSync,\n runWithScopedConfig,\n type ScopedConfigLike,\n throwCombinedErrors,\n} from \"./scoped-config.ts\";\nimport { getConsoleSink, type Sink } from \"./sink.ts\";\n\n/**\n * A configuration for the loggers.\n */\nexport interface Config<TSinkId extends string, TFilterId extends string> {\n /**\n * The sinks to use. The keys are the sink identifiers, and the values are\n * {@link Sink}s.\n */\n sinks: Record<TSinkId, Sink>;\n /**\n * The filters to use. The keys are the filter identifiers, and the values\n * are either {@link Filter}s or {@link LogLevel}s.\n */\n filters?: Record<TFilterId, FilterLike>;\n\n /**\n * The loggers to configure.\n */\n loggers: LoggerConfig<TSinkId, TFilterId>[];\n\n /**\n * The context-local storage to use for implicit contexts.\n * @since 0.7.0\n */\n contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;\n\n /**\n * Whether to reset the configuration before applying this one.\n */\n reset?: boolean;\n}\n\n/**\n * A scoped configuration for the current execution context.\n *\n * Unlike {@link Config}, this type does not include `reset` or\n * `contextLocalStorage`. Scoped configuration changes only the logging policy\n * for a callback; the context-local storage must already be initialized by the\n * process-global configuration.\n *\n * @since 2.3.0\n */\nexport type ScopedConfig<TSinkId extends string, TFilterId extends string> =\n ScopedConfigLike<TSinkId, TFilterId>;\n\ntype SyncCallbackResult<TResult> = TResult extends PromiseLike<unknown> ? never\n : TResult;\n\n/**\n * A logger configuration.\n */\nexport interface LoggerConfig<\n TSinkId extends string,\n TFilterId extends string,\n> {\n /**\n * The category of the logger. If a string, it is equivalent to an array\n * with one element.\n */\n category: string | string[];\n\n /**\n * The sink identifiers to use.\n */\n sinks?: TSinkId[];\n\n /**\n * Whether to inherit the parent's sinks. If `inherit`, the parent's sinks\n * are used along with the specified sinks. If `override`, the parent's\n * sinks are not used, and only the specified sinks are used.\n *\n * The default is `inherit`.\n * @default `\"inherit\"\n * @since 0.6.0\n */\n parentSinks?: \"inherit\" | \"override\";\n\n /**\n * The filter identifiers to use.\n */\n filters?: TFilterId[];\n\n /**\n * The lowest log level to accept. If `null`, the logger will reject all\n * records.\n * @since 0.8.0\n */\n lowestLevel?: LogLevel | null;\n}\n\n/**\n * The current configuration, if any. Otherwise, `null`.\n */\nlet currentConfig: Config<string, string> | null = null;\nlet activeScopedConfigCount = 0;\nlet globalConfigMutationInProgress = false;\n\n/**\n * Strong references to the loggers.\n * This is to prevent the loggers from being garbage collected so that their\n * sinks and filters are not removed.\n */\nconst strongRefs: Set<LoggerImpl> = new Set();\n\n/**\n * Sync filter disposables to dispose when resetting the configuration.\n */\nconst filterDisposables: Set<Disposable> = new Set();\n\n/**\n * Sync sink disposables to dispose when resetting the configuration.\n */\nconst sinkDisposables: Set<Disposable> = new Set();\n\n/**\n * Async filter disposables to dispose when resetting the configuration.\n */\nconst asyncFilterDisposables: Set<AsyncDisposable> = new Set();\n\n/**\n * Async sink disposables to dispose when resetting the configuration.\n */\nconst asyncSinkDisposables: Set<AsyncDisposable> = new Set();\n\n/**\n * Check if a config is for the meta logger.\n */\nfunction isLoggerConfigMeta<TSinkId extends string, TFilterId extends string>(\n cfg: LoggerConfig<TSinkId, TFilterId>,\n): boolean {\n const category = Array.isArray(cfg.category) ? cfg.category : [cfg.category];\n return category.length === 0 ||\n (category.length === 1 && category[0] === \"logtape\") ||\n (category.length === 2 &&\n category[0] === \"logtape\" &&\n category[1] === \"meta\");\n}\n\nfunction registerDisposeHook(allowAsync: boolean): void {\n const handler = allowAsync ? disposeInternal : disposeSyncInternal;\n\n if (\n // deno-lint-ignore no-explicit-any\n typeof (globalThis as any).EdgeRuntime !== \"string\" &&\n \"process\" in globalThis &&\n !(\"Deno\" in globalThis)\n ) {\n // deno-lint-ignore no-explicit-any\n const proc = (globalThis as any).process;\n // Use bracket notation to avoid static analysis detection in Edge Runtime.\n const onMethod = proc?.[\"on\"];\n if (typeof onMethod === \"function\") {\n onMethod.call(proc, \"exit\", handler);\n return;\n }\n }\n\n // Some edge runtimes expose neither process.on() nor addEventListener().\n // In those environments users can still call dispose()/disposeSync() manually.\n // deno-lint-ignore no-explicit-any\n const addEventListenerMethod = (globalThis as any).addEventListener;\n if (typeof addEventListenerMethod !== \"function\") return;\n\n if (\"Deno\" in globalThis) {\n addEventListenerMethod.call(globalThis, \"unload\", handler);\n } else {\n addEventListenerMethod.call(globalThis, \"pagehide\", handler);\n }\n}\n\n/**\n * Configure the loggers with the specified configuration.\n *\n * Note that if the given sinks or filters are disposable, they will be\n * disposed when the configuration is reset, or when the process exits.\n *\n * @example\n * ```typescript\n * await configure({\n * sinks: {\n * console: getConsoleSink(),\n * },\n * filters: {\n * slow: (log) =>\n * \"duration\" in log.properties &&\n * log.properties.duration as number > 1000,\n * },\n * loggers: [\n * {\n * category: \"my-app\",\n * sinks: [\"console\"],\n * lowestLevel: \"info\",\n * },\n * {\n * category: [\"my-app\", \"sql\"],\n * filters: [\"slow\"],\n * lowestLevel: \"debug\",\n * },\n * {\n * category: \"logtape\",\n * sinks: [\"console\"],\n * lowestLevel: \"error\",\n * },\n * ],\n * });\n * ```\n *\n * @param config The configuration.\n */\nexport async function configure<\n TSinkId extends string,\n TFilterId extends string,\n>(config: Config<TSinkId, TFilterId>): Promise<void> {\n await runGlobalConfigMutation(\"configure()\", async () => {\n if (currentConfig != null && !config.reset) {\n throw new ConfigError(\n \"Already configured; if you want to reset, turn on the reset flag.\",\n );\n }\n await disposeInternal();\n resetInternal();\n try {\n configureInternal(config, true);\n } catch (e) {\n if (e instanceof ConfigError) {\n await disposeInternal();\n resetInternal();\n }\n throw e;\n }\n });\n}\n\n/**\n * Configure sync loggers with the specified configuration.\n *\n * Note that if the given sinks or filters are disposable, they will be\n * disposed when the configuration is reset, or when the process exits.\n *\n * Also note that passing async sinks or filters will throw. If\n * necessary use {@link resetSync} or {@link disposeSync}.\n *\n * @example\n * ```typescript\n * configureSync({\n * sinks: {\n * console: getConsoleSink(),\n * },\n * loggers: [\n * {\n * category: \"my-app\",\n * sinks: [\"console\"],\n * lowestLevel: \"info\",\n * },\n * {\n * category: \"logtape\",\n * sinks: [\"console\"],\n * lowestLevel: \"error\",\n * },\n * ],\n * });\n * ```\n *\n * @param config The configuration.\n * @since 0.9.0\n */\nexport function configureSync<TSinkId extends string, TFilterId extends string>(\n config: Config<TSinkId, TFilterId>,\n): void {\n runGlobalConfigMutationSync(\"configureSync()\", () => {\n if (currentConfig != null && !config.reset) {\n throw new ConfigError(\n \"Already configured; if you want to reset, turn on the reset flag.\",\n );\n }\n if (asyncFilterDisposables.size > 0 || asyncSinkDisposables.size > 0) {\n throw new ConfigError(\n \"Previously configured async disposables are still active. \" +\n \"Use configure() instead or explicitly dispose them using dispose().\",\n );\n }\n disposeSyncInternal();\n resetInternal();\n try {\n configureInternal(config, false);\n } catch (e) {\n if (e instanceof ConfigError) {\n disposeSyncInternal();\n resetInternal();\n }\n throw e;\n }\n });\n}\n\n/**\n * Runs a callback with a LogTape configuration scoped to the current execution\n * context.\n *\n * The process-global configuration must already provide\n * `contextLocalStorage`. The scoped configuration fully overrides global\n * logger routing while the callback and its async work run.\n *\n * @param config The scoped configuration.\n * @param callback The callback to run.\n * @returns The callback's resolved return value.\n * @since 2.3.0\n */\nexport async function withConfig<\n TSinkId extends string,\n TFilterId extends string,\n TResult,\n>(\n config: ScopedConfig<TSinkId, TFilterId>,\n callback: () => TResult,\n): Promise<Awaited<TResult>> {\n const contextLocalStorage = getConfiguredContextLocalStorage(\"withConfig()\");\n const scopedConfig = compileScopedConfig(\n config,\n true,\n (message) => new ConfigError(message),\n );\n\n let result: Awaited<TResult>;\n let callbackError: unknown;\n let callbackFailed = false;\n activeScopedConfigCount++;\n try {\n result = await runWithScopedConfig(\n contextLocalStorage,\n scopedConfig,\n callback,\n );\n } catch (error) {\n callbackFailed = true;\n callbackError = error;\n }\n\n try {\n await disposeScopedConfig(scopedConfig);\n } catch (disposeError) {\n if (callbackFailed) {\n throwCombinedErrors(callbackError, disposeError);\n }\n throw disposeError;\n } finally {\n activeScopedConfigCount--;\n }\n\n if (callbackFailed) throw callbackError;\n return result!;\n}\n\n/**\n * Runs a synchronous callback with a LogTape configuration scoped to the\n * current execution context.\n *\n * The scoped configuration must not contain async disposable sinks or filters.\n *\n * @param config The scoped configuration.\n * @param callback The callback to run.\n * @returns The callback's return value.\n * @since 2.3.0\n */\nexport function withConfigSync<\n TSinkId extends string,\n TFilterId extends string,\n TResult,\n>(\n config: ScopedConfig<TSinkId, TFilterId>,\n callback: () => SyncCallbackResult<TResult>,\n): SyncCallbackResult<TResult> {\n const contextLocalStorage = getConfiguredContextLocalStorage(\n \"withConfigSync()\",\n );\n const scopedConfig = compileScopedConfig(\n config,\n false,\n (message) => new ConfigError(message),\n );\n\n let result: SyncCallbackResult<TResult>;\n let callbackError: unknown;\n let callbackFailed = false;\n activeScopedConfigCount++;\n try {\n result = runWithScopedConfig(contextLocalStorage, scopedConfig, callback);\n if (isThenable(result)) {\n void Promise.resolve(result).catch(() => {});\n callbackFailed = true;\n callbackError = new ConfigError(\n \"withConfigSync() callback must not return a promise. \" +\n \"Use withConfig() for async callbacks.\",\n );\n }\n } catch (error) {\n callbackFailed = true;\n callbackError = error;\n }\n\n try {\n disposeScopedConfigSync(scopedConfig);\n } catch (disposeError) {\n if (callbackFailed) {\n throwCombinedErrors(callbackError, disposeError);\n }\n throw disposeError;\n } finally {\n activeScopedConfigCount--;\n }\n\n if (callbackFailed) throw callbackError;\n return result!;\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return value != null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n \"then\" in value &&\n typeof value.then === \"function\";\n}\n\nfunction configureInternal<\n TSinkId extends string,\n TFilterId extends string,\n>(config: Config<TSinkId, TFilterId>, allowAsync: boolean): void {\n currentConfig = config;\n\n let metaConfigured = false;\n const configuredCategories = new Set<string>();\n\n for (const cfg of config.loggers) {\n if (isLoggerConfigMeta(cfg)) {\n metaConfigured = true;\n }\n\n // Check for duplicate logger categories\n const categoryKey = Array.isArray(cfg.category)\n ? JSON.stringify(cfg.category)\n : JSON.stringify([cfg.category]);\n if (configuredCategories.has(categoryKey)) {\n throw new ConfigError(\n `Duplicate logger configuration for category: ${categoryKey}. ` +\n `Each category can only be configured once.`,\n );\n }\n configuredCategories.add(categoryKey);\n\n const logger = LoggerImpl.getLogger(cfg.category);\n for (const sinkId of cfg.sinks ?? []) {\n const sink = config.sinks[sinkId];\n if (!sink) {\n throw new ConfigError(`Sink not found: ${sinkId}.`);\n }\n logger.sinks.push(sink);\n }\n logger.parentSinks = cfg.parentSinks ?? \"inherit\";\n if (cfg.lowestLevel !== undefined) {\n logger.lowestLevel = cfg.lowestLevel;\n }\n for (const filterId of cfg.filters ?? []) {\n const filter = config.filters?.[filterId];\n if (filter === undefined) {\n throw new ConfigError(`Filter not found: ${filterId}.`);\n }\n logger.filters.push(toFilter(filter));\n }\n strongRefs.add(logger);\n }\n\n LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;\n\n for (const sink of Object.values<Sink>(config.sinks)) {\n if (Symbol.asyncDispose in sink) {\n if (allowAsync) asyncSinkDisposables.add(sink as AsyncDisposable);\n else {\n throw new ConfigError(\n \"Async disposables cannot be used with configureSync().\",\n );\n }\n }\n if (Symbol.dispose in sink) sinkDisposables.add(sink as Disposable);\n }\n\n for (const filter of Object.values<FilterLike>(config.filters ?? {})) {\n if (filter == null || typeof filter === \"string\") continue;\n if (Symbol.asyncDispose in filter) {\n if (allowAsync) asyncFilterDisposables.add(filter as AsyncDisposable);\n else {\n throw new ConfigError(\n \"Async disposables cannot be used with configureSync().\",\n );\n }\n asyncSinkDisposables.delete(filter as AsyncDisposable);\n }\n if (Symbol.dispose in filter) {\n filterDisposables.add(filter as Disposable);\n sinkDisposables.delete(filter as Disposable);\n }\n }\n\n registerDisposeHook(allowAsync);\n const meta = LoggerImpl.getLogger([\"logtape\", \"meta\"]);\n if (!metaConfigured) {\n meta.sinks.push(getConsoleSink());\n }\n\n meta.info(\n \"LogTape loggers are configured. Note that LogTape itself uses the meta \" +\n \"logger, which has category {metaLoggerCategory}. The meta logger is \" +\n \"used to log internal diagnostics such as sink exceptions. \" +\n \"It's recommended to configure the meta logger with a separate sink \" +\n \"so that you can easily notice if logging itself fails or is \" +\n \"misconfigured. To turn off this message, configure the meta logger \" +\n \"with higher log levels than {dismissLevel}. See also \" +\n \"<https://logtape.org/manual/categories#meta-logger>.\",\n { metaLoggerCategory: [\"logtape\", \"meta\"], dismissLevel: \"info\" },\n );\n}\n\n/**\n * Get the current configuration, if any. Otherwise, `null`.\n * @returns The current configuration, if any. Otherwise, `null`.\n */\nexport function getConfig(): Config<string, string> | null {\n return currentConfig;\n}\n\n/**\n * Reset the configuration. Mostly for testing purposes.\n */\nexport async function reset(): Promise<void> {\n await runGlobalConfigMutation(\"reset()\", async () => {\n await disposeInternal();\n resetInternal();\n });\n}\n\n/**\n * Reset the configuration. Mostly for testing purposes. Will not clear async\n * sinks, only use with sync sinks. Use {@link reset} if you have async sinks.\n * @since 0.9.0\n */\nexport function resetSync(): void {\n runGlobalConfigMutationSync(\"resetSync()\", () => {\n disposeSyncInternal();\n resetInternal();\n });\n}\n\nfunction resetInternal(): void {\n const rootLogger = LoggerImpl.getLogger([]);\n rootLogger.resetDescendants();\n delete rootLogger.contextLocalStorage;\n strongRefs.clear();\n currentConfig = null;\n}\n\n/**\n * Dispose of the disposables.\n */\nexport async function dispose(): Promise<void> {\n await runGlobalConfigMutation(\"dispose()\", disposeInternal);\n}\n\nasync function disposeInternal(): Promise<void> {\n const errors: unknown[] = [];\n try {\n disposeSyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n await disposeAsyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n disposeSyncSinks();\n } catch (error) {\n errors.push(error);\n }\n try {\n await disposeAsyncSinks();\n } catch (error) {\n errors.push(error);\n }\n throwDisposeErrors(errors);\n}\n\n/**\n * Dispose of the sync disposables. Async disposables will be untouched,\n * use {@link dispose} if you have async sinks.\n * @since 0.9.0\n */\nexport function disposeSync(): void {\n runGlobalConfigMutationSync(\"disposeSync()\", disposeSyncInternal);\n}\n\nfunction disposeSyncInternal(): void {\n const errors: unknown[] = [];\n try {\n disposeSyncFilters();\n } catch (error) {\n errors.push(error);\n }\n try {\n disposeSyncSinks();\n } catch (error) {\n errors.push(error);\n }\n throwDisposeErrors(errors);\n}\n\nfunction getConfiguredContextLocalStorage(\n functionName: string,\n): ContextLocalStorage<Record<string, unknown>> {\n if (globalConfigMutationInProgress) {\n throw new ConfigError(\n `${functionName} cannot be called while LogTape is being reconfigured.`,\n );\n }\n if (currentConfig == null) {\n throw new ConfigError(\n `${functionName} requires LogTape to be configured first.`,\n );\n }\n const contextLocalStorage = LoggerImpl.getLogger().contextLocalStorage;\n if (contextLocalStorage == null) {\n throw new ConfigError(\n `${functionName} requires Config.contextLocalStorage to be configured.`,\n );\n }\n return contextLocalStorage;\n}\n\nasync function runGlobalConfigMutation<T>(\n functionName: string,\n callback: () => Promise<T>,\n): Promise<T> {\n assertCanMutateGlobalConfig(functionName);\n globalConfigMutationInProgress = true;\n try {\n return await callback();\n } finally {\n globalConfigMutationInProgress = false;\n }\n}\n\nfunction runGlobalConfigMutationSync<T>(\n functionName: string,\n callback: () => T,\n): T {\n assertCanMutateGlobalConfig(functionName);\n globalConfigMutationInProgress = true;\n try {\n return callback();\n } finally {\n globalConfigMutationInProgress = false;\n }\n}\n\nfunction assertCanMutateGlobalConfig(functionName: string): void {\n if (globalConfigMutationInProgress) {\n throw new ConfigError(\n `${functionName} cannot be called while LogTape is being reconfigured.`,\n );\n }\n assertNoScopedConfig(functionName);\n}\n\nfunction assertNoScopedConfig(functionName: string): void {\n if (activeScopedConfigCount > 0) {\n throw new ConfigError(\n `${functionName} cannot be called while a scoped configuration is ` +\n \"active. Use nested withConfig() instead.\",\n );\n }\n}\n\nfunction disposeSyncFilters(): void {\n disposeSyncDisposables(filterDisposables);\n}\n\nfunction disposeSyncSinks(): void {\n disposeSyncDisposables(sinkDisposables);\n}\n\nfunction disposeSyncDisposables(disposables: Set<Disposable>): void {\n const errors: unknown[] = [];\n try {\n for (const disposable of disposables) {\n try {\n disposable[Symbol.dispose]();\n } catch (error) {\n errors.push(error);\n } finally {\n disposables.delete(disposable);\n }\n }\n } finally {\n disposables.clear();\n }\n throwDisposeErrors(errors);\n}\n\nasync function disposeAsyncFilters(): Promise<void> {\n await disposeAsyncDisposables(asyncFilterDisposables);\n}\n\nasync function disposeAsyncSinks(): Promise<void> {\n await disposeAsyncDisposables(asyncSinkDisposables);\n}\n\nasync function disposeAsyncDisposables(\n disposables: Set<AsyncDisposable>,\n): Promise<void> {\n const promises: PromiseLike<void>[] = [];\n try {\n for (const disposable of disposables) {\n try {\n promises.push(Promise.resolve(disposable[Symbol.asyncDispose]()));\n } catch (error) {\n promises.push(Promise.reject(error));\n } finally {\n disposables.delete(disposable);\n }\n }\n } finally {\n disposables.clear();\n }\n await settleDisposePromises(promises);\n}\n\nasync function settleDisposePromises(\n promises: readonly PromiseLike<void>[],\n): Promise<void> {\n const results = await Promise.allSettled(promises);\n throwDisposeErrors(\n results\n .filter((result): result is PromiseRejectedResult =>\n result.status === \"rejected\"\n )\n .map((result) => result.reason),\n );\n}\n\nfunction throwDisposeErrors(errors: readonly unknown[]): void {\n if (errors.length < 1) return;\n if (errors.length === 1) throw errors[0];\n throw new AggregateError(\n errors,\n \"Multiple errors occurred while disposing LogTape resources.\",\n );\n}\n\n/**\n * A configuration error.\n */\nexport class ConfigError extends Error {\n /**\n * Constructs a new configuration error.\n * @param message The error message.\n */\n constructor(message: string) {\n super(message);\n this.name = \"ConfigError\";\n }\n}\n"],"mappings":";;;;;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