@logtape/logtape 2.3.0-dev.791 → 2.3.0-dev.792
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -7
- package/dist/config.cjs +100 -1
- package/dist/config.d.cts +40 -2
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.ts +40 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +98 -1
- package/dist/config.js.map +1 -1
- package/dist/logger.cjs +29 -0
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +29 -0
- package/dist/logger.js.map +1 -1
- package/dist/mod.cjs +2 -0
- package/dist/mod.d.cts +2 -2
- package/dist/mod.d.ts +2 -2
- package/dist/mod.js +2 -2
- package/dist/scoped-config.cjs +227 -0
- package/dist/scoped-config.d.cts +21 -0
- package/dist/scoped-config.d.cts.map +1 -0
- package/dist/scoped-config.d.ts +21 -0
- package/dist/scoped-config.d.ts.map +1 -0
- package/dist/scoped-config.js +221 -0
- package/dist/scoped-config.js.map +1 -0
- package/package.json +1 -1
- package/skills/logtape/SKILL.md +8 -9
package/README.md
CHANGED
|
@@ -47,9 +47,8 @@ The highlights of LogTape are:
|
|
|
47
47
|
- *[Dead simple sinks]*: You can easily add your own sinks to LogTape.
|
|
48
48
|
|
|
49
49
|
- *[Framework integrations]*: First-class support for popular frameworks
|
|
50
|
-
like [Express], [Fastify], [
|
|
51
|
-
|
|
52
|
-
query logging.
|
|
50
|
+
like [Express], [Fastify], [Hono], [Koa], and [Drizzle ORM] with automatic
|
|
51
|
+
HTTP request logging and database query logging.
|
|
53
52
|
|
|
54
53
|

|
|
55
54
|

|
|
@@ -74,7 +73,6 @@ The highlights of LogTape are:
|
|
|
74
73
|
[Framework integrations]: https://logtape.org/manual/integrations
|
|
75
74
|
[Express]: https://expressjs.com/
|
|
76
75
|
[Fastify]: https://fastify.dev/
|
|
77
|
-
[GraphQL Yoga]: https://the-guild.dev/graphql/yoga-server
|
|
78
76
|
[Hono]: https://hono.dev/
|
|
79
77
|
[Koa]: https://koajs.com/
|
|
80
78
|
[Drizzle ORM]: https://orm.drizzle.team/
|
|
@@ -118,7 +116,6 @@ list of the packages in the LogTape monorepo:
|
|
|
118
116
|
| [*@logtape/elysia*](/packages/elysia/) | [JSR][jsr:@logtape/elysia] | [npm][npm:@logtape/elysia] | [Elysia] integration |
|
|
119
117
|
| [*@logtape/express*](/packages/express/) | [JSR][jsr:@logtape/express] | [npm][npm:@logtape/express] | [Express] integration |
|
|
120
118
|
| [*@logtape/fastify*](/packages/fastify/) | [JSR][jsr:@logtape/fastify] | [npm][npm:@logtape/fastify] | [Fastify] integration |
|
|
121
|
-
| [*@logtape/graphql-yoga*](/packages/graphql-yoga/) | [JSR][jsr:@logtape/graphql-yoga] | [npm][npm:@logtape/graphql-yoga] | [GraphQL Yoga] integration |
|
|
122
119
|
| [*@logtape/hono*](/packages/hono/) | [JSR][jsr:@logtape/hono] | [npm][npm:@logtape/hono] | [Hono] integration |
|
|
123
120
|
| [*@logtape/koa*](/packages/koa/) | [JSR][jsr:@logtape/koa] | [npm][npm:@logtape/koa] | [Koa] integration |
|
|
124
121
|
| [*@logtape/lint*](/packages/lint/) | [JSR][jsr:@logtape/lint] | [npm][npm:@logtape/lint] | ESLint/Oxlint/Deno Lint rules |
|
|
@@ -159,8 +156,6 @@ list of the packages in the LogTape monorepo:
|
|
|
159
156
|
[npm:@logtape/express]: https://www.npmjs.com/package/@logtape/express
|
|
160
157
|
[jsr:@logtape/fastify]: https://jsr.io/@logtape/fastify
|
|
161
158
|
[npm:@logtape/fastify]: https://www.npmjs.com/package/@logtape/fastify
|
|
162
|
-
[jsr:@logtape/graphql-yoga]: https://jsr.io/@logtape/graphql-yoga
|
|
163
|
-
[npm:@logtape/graphql-yoga]: https://www.npmjs.com/package/@logtape/graphql-yoga
|
|
164
159
|
[jsr:@logtape/hono]: https://jsr.io/@logtape/hono
|
|
165
160
|
[npm:@logtape/hono]: https://www.npmjs.com/package/@logtape/hono
|
|
166
161
|
[jsr:@logtape/koa]: https://jsr.io/@logtape/koa
|
package/dist/config.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_filter = require('./filter.cjs');
|
|
2
|
+
const require_scoped_config = require('./scoped-config.cjs');
|
|
2
3
|
const require_logger = require('./logger.cjs');
|
|
3
4
|
const require_sink = require('./sink.cjs');
|
|
4
5
|
|
|
@@ -7,6 +8,7 @@ const require_sink = require('./sink.cjs');
|
|
|
7
8
|
* The current configuration, if any. Otherwise, `null`.
|
|
8
9
|
*/
|
|
9
10
|
let currentConfig = null;
|
|
11
|
+
let activeScopedConfigCount = 0;
|
|
10
12
|
/**
|
|
11
13
|
* Strong references to the loggers.
|
|
12
14
|
* This is to prevent the loggers from being garbage collected so that their
|
|
@@ -91,6 +93,7 @@ function registerDisposeHook(allowAsync) {
|
|
|
91
93
|
* @param config The configuration.
|
|
92
94
|
*/
|
|
93
95
|
async function configure(config) {
|
|
96
|
+
assertNoScopedConfig("configure()");
|
|
94
97
|
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
95
98
|
await reset();
|
|
96
99
|
try {
|
|
@@ -134,6 +137,7 @@ async function configure(config) {
|
|
|
134
137
|
* @since 0.9.0
|
|
135
138
|
*/
|
|
136
139
|
function configureSync(config) {
|
|
140
|
+
assertNoScopedConfig("configureSync()");
|
|
137
141
|
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
138
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().");
|
|
139
143
|
resetSync();
|
|
@@ -144,6 +148,86 @@ function configureSync(config) {
|
|
|
144
148
|
throw e;
|
|
145
149
|
}
|
|
146
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Runs a callback with a LogTape configuration scoped to the current execution
|
|
153
|
+
* context.
|
|
154
|
+
*
|
|
155
|
+
* The process-global configuration must already provide
|
|
156
|
+
* `contextLocalStorage`. The scoped configuration fully overrides global
|
|
157
|
+
* logger routing while the callback and its async work run.
|
|
158
|
+
*
|
|
159
|
+
* @param config The scoped configuration.
|
|
160
|
+
* @param callback The callback to run.
|
|
161
|
+
* @returns The callback's resolved return value.
|
|
162
|
+
* @since 2.3.0
|
|
163
|
+
*/
|
|
164
|
+
async function withConfig(config, callback) {
|
|
165
|
+
const contextLocalStorage = getConfiguredContextLocalStorage("withConfig()");
|
|
166
|
+
const scopedConfig = require_scoped_config.compileScopedConfig(config, true, (message) => new ConfigError(message));
|
|
167
|
+
let result;
|
|
168
|
+
let callbackError;
|
|
169
|
+
let callbackFailed = false;
|
|
170
|
+
activeScopedConfigCount++;
|
|
171
|
+
try {
|
|
172
|
+
result = await require_scoped_config.runWithScopedConfig(contextLocalStorage, scopedConfig, callback);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
callbackFailed = true;
|
|
175
|
+
callbackError = error;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await require_scoped_config.disposeScopedConfig(scopedConfig);
|
|
179
|
+
} catch (disposeError) {
|
|
180
|
+
if (callbackFailed) require_scoped_config.throwCombinedErrors(callbackError, disposeError);
|
|
181
|
+
throw disposeError;
|
|
182
|
+
} finally {
|
|
183
|
+
activeScopedConfigCount--;
|
|
184
|
+
}
|
|
185
|
+
if (callbackFailed) throw callbackError;
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Runs a synchronous callback with a LogTape configuration scoped to the
|
|
190
|
+
* current execution context.
|
|
191
|
+
*
|
|
192
|
+
* The scoped configuration must not contain async disposable sinks or filters.
|
|
193
|
+
*
|
|
194
|
+
* @param config The scoped configuration.
|
|
195
|
+
* @param callback The callback to run.
|
|
196
|
+
* @returns The callback's return value.
|
|
197
|
+
* @since 2.3.0
|
|
198
|
+
*/
|
|
199
|
+
function withConfigSync(config, callback) {
|
|
200
|
+
const contextLocalStorage = getConfiguredContextLocalStorage("withConfigSync()");
|
|
201
|
+
const scopedConfig = require_scoped_config.compileScopedConfig(config, false, (message) => new ConfigError(message));
|
|
202
|
+
let result;
|
|
203
|
+
let callbackError;
|
|
204
|
+
let callbackFailed = false;
|
|
205
|
+
activeScopedConfigCount++;
|
|
206
|
+
try {
|
|
207
|
+
result = require_scoped_config.runWithScopedConfig(contextLocalStorage, scopedConfig, callback);
|
|
208
|
+
if (isThenable(result)) {
|
|
209
|
+
Promise.resolve(result).catch(() => {});
|
|
210
|
+
callbackFailed = true;
|
|
211
|
+
callbackError = new ConfigError("withConfigSync() callback must not return a promise. Use withConfig() for async callbacks.");
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
callbackFailed = true;
|
|
215
|
+
callbackError = error;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
require_scoped_config.disposeScopedConfigSync(scopedConfig);
|
|
219
|
+
} catch (disposeError) {
|
|
220
|
+
if (callbackFailed) require_scoped_config.throwCombinedErrors(callbackError, disposeError);
|
|
221
|
+
throw disposeError;
|
|
222
|
+
} finally {
|
|
223
|
+
activeScopedConfigCount--;
|
|
224
|
+
}
|
|
225
|
+
if (callbackFailed) throw callbackError;
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
function isThenable(value) {
|
|
229
|
+
return value != null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
230
|
+
}
|
|
147
231
|
function configureInternal(config, allowAsync) {
|
|
148
232
|
currentConfig = config;
|
|
149
233
|
let metaConfigured = false;
|
|
@@ -205,6 +289,7 @@ function getConfig() {
|
|
|
205
289
|
* Reset the configuration. Mostly for testing purposes.
|
|
206
290
|
*/
|
|
207
291
|
async function reset() {
|
|
292
|
+
assertNoScopedConfig("reset()");
|
|
208
293
|
await dispose();
|
|
209
294
|
resetInternal();
|
|
210
295
|
}
|
|
@@ -214,6 +299,7 @@ async function reset() {
|
|
|
214
299
|
* @since 0.9.0
|
|
215
300
|
*/
|
|
216
301
|
function resetSync() {
|
|
302
|
+
assertNoScopedConfig("resetSync()");
|
|
217
303
|
disposeSync();
|
|
218
304
|
resetInternal();
|
|
219
305
|
}
|
|
@@ -228,6 +314,7 @@ function resetInternal() {
|
|
|
228
314
|
* Dispose of the disposables.
|
|
229
315
|
*/
|
|
230
316
|
async function dispose() {
|
|
317
|
+
assertNoScopedConfig("dispose()");
|
|
231
318
|
const errors = [];
|
|
232
319
|
try {
|
|
233
320
|
disposeSyncFilters();
|
|
@@ -257,6 +344,7 @@ async function dispose() {
|
|
|
257
344
|
* @since 0.9.0
|
|
258
345
|
*/
|
|
259
346
|
function disposeSync() {
|
|
347
|
+
assertNoScopedConfig("disposeSync()");
|
|
260
348
|
const errors = [];
|
|
261
349
|
try {
|
|
262
350
|
disposeSyncFilters();
|
|
@@ -270,6 +358,15 @@ function disposeSync() {
|
|
|
270
358
|
}
|
|
271
359
|
throwDisposeErrors(errors);
|
|
272
360
|
}
|
|
361
|
+
function getConfiguredContextLocalStorage(functionName) {
|
|
362
|
+
if (currentConfig == null) throw new ConfigError(`${functionName} requires LogTape to be configured first.`);
|
|
363
|
+
const contextLocalStorage = require_logger.LoggerImpl.getLogger().contextLocalStorage;
|
|
364
|
+
if (contextLocalStorage == null) throw new ConfigError(`${functionName} requires Config.contextLocalStorage to be configured.`);
|
|
365
|
+
return contextLocalStorage;
|
|
366
|
+
}
|
|
367
|
+
function assertNoScopedConfig(functionName) {
|
|
368
|
+
if (activeScopedConfigCount > 0) throw new ConfigError(`${functionName} cannot be called while a scoped configuration is active. Use nested withConfig() instead.`);
|
|
369
|
+
}
|
|
273
370
|
function disposeSyncFilters() {
|
|
274
371
|
disposeSyncDisposables(filterDisposables);
|
|
275
372
|
}
|
|
@@ -343,4 +440,6 @@ exports.dispose = dispose;
|
|
|
343
440
|
exports.disposeSync = disposeSync;
|
|
344
441
|
exports.getConfig = getConfig;
|
|
345
442
|
exports.reset = reset;
|
|
346
|
-
exports.resetSync = resetSync;
|
|
443
|
+
exports.resetSync = resetSync;
|
|
444
|
+
exports.withConfig = withConfig;
|
|
445
|
+
exports.withConfigSync = withConfigSync;
|
package/dist/config.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import { ContextLocalStorage } from "./context.cjs";
|
|
|
2
2
|
import { LogLevel } from "./level.cjs";
|
|
3
3
|
import { FilterLike } from "./filter.cjs";
|
|
4
4
|
import { Sink } from "./sink.cjs";
|
|
5
|
+
import { ScopedConfigLike } from "./scoped-config.cjs";
|
|
5
6
|
|
|
6
7
|
//#region src/config.d.ts
|
|
7
8
|
|
|
@@ -33,6 +34,18 @@ interface Config<TSinkId extends string, TFilterId extends string> {
|
|
|
33
34
|
*/
|
|
34
35
|
reset?: boolean;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* A scoped configuration for the current execution context.
|
|
39
|
+
*
|
|
40
|
+
* Unlike {@link Config}, this type does not include `reset` or
|
|
41
|
+
* `contextLocalStorage`. Scoped configuration changes only the logging policy
|
|
42
|
+
* for a callback; the context-local storage must already be initialized by the
|
|
43
|
+
* process-global configuration.
|
|
44
|
+
*
|
|
45
|
+
* @since 2.3.0
|
|
46
|
+
*/
|
|
47
|
+
type ScopedConfig<TSinkId extends string, TFilterId extends string> = ScopedConfigLike<TSinkId, TFilterId>;
|
|
48
|
+
type SyncCallbackResult<TResult> = TResult extends PromiseLike<unknown> ? never : TResult;
|
|
36
49
|
/**
|
|
37
50
|
* A logger configuration.
|
|
38
51
|
*/
|
|
@@ -141,6 +154,32 @@ declare function configure<TSinkId extends string, TFilterId extends string>(con
|
|
|
141
154
|
* @since 0.9.0
|
|
142
155
|
*/
|
|
143
156
|
declare function configureSync<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
|
|
157
|
+
/**
|
|
158
|
+
* Runs a callback with a LogTape configuration scoped to the current execution
|
|
159
|
+
* context.
|
|
160
|
+
*
|
|
161
|
+
* The process-global configuration must already provide
|
|
162
|
+
* `contextLocalStorage`. The scoped configuration fully overrides global
|
|
163
|
+
* logger routing while the callback and its async work run.
|
|
164
|
+
*
|
|
165
|
+
* @param config The scoped configuration.
|
|
166
|
+
* @param callback The callback to run.
|
|
167
|
+
* @returns The callback's resolved return value.
|
|
168
|
+
* @since 2.3.0
|
|
169
|
+
*/
|
|
170
|
+
declare function withConfig<TSinkId extends string, TFilterId extends string, TResult>(config: ScopedConfig<TSinkId, TFilterId>, callback: () => TResult): Promise<Awaited<TResult>>;
|
|
171
|
+
/**
|
|
172
|
+
* Runs a synchronous callback with a LogTape configuration scoped to the
|
|
173
|
+
* current execution context.
|
|
174
|
+
*
|
|
175
|
+
* The scoped configuration must not contain async disposable sinks or filters.
|
|
176
|
+
*
|
|
177
|
+
* @param config The scoped configuration.
|
|
178
|
+
* @param callback The callback to run.
|
|
179
|
+
* @returns The callback's return value.
|
|
180
|
+
* @since 2.3.0
|
|
181
|
+
*/
|
|
182
|
+
declare function withConfigSync<TSinkId extends string, TFilterId extends string, TResult>(config: ScopedConfig<TSinkId, TFilterId>, callback: () => SyncCallbackResult<TResult>): SyncCallbackResult<TResult>;
|
|
144
183
|
/**
|
|
145
184
|
* Get the current configuration, if any. Otherwise, `null`.
|
|
146
185
|
* @returns The current configuration, if any. Otherwise, `null`.
|
|
@@ -176,7 +215,6 @@ declare class ConfigError extends Error {
|
|
|
176
215
|
*/
|
|
177
216
|
constructor(message: string);
|
|
178
217
|
}
|
|
179
|
-
//# sourceMappingURL=config.d.ts.map
|
|
180
218
|
//#endregion
|
|
181
|
-
export { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync };
|
|
219
|
+
export { Config, ConfigError, LoggerConfig, ScopedConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync, withConfig, withConfigSync };
|
|
182
220
|
//# sourceMappingURL=config.d.cts.map
|
package/dist/config.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.cts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":"
|
|
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;AAOhB;AAWA;AAiBA;AA+BA;EAyHa,WAAA,CAAA,EArmBG,QAqmBS,GAAQ,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA5eX,oEAGZ,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDvB,wEACN,OAAO,SAAS;;;;;;;;;;;;;;iBAoCJ,8EAKZ,aAAa,SAAS,4BACd,UACf,QAAQ,QAAQ;;;;;;;;;;;;iBAiDH,kFAKN,aAAa,SAAS,4BACd,mBAAmB,WAClC,mBAAmB;;;;;iBAyJN,SAAA,CAAA,GAAa;;;;iBAOP,KAAA,CAAA,GAAS;;;;;;iBAWf,SAAA,CAAA;;;;iBAiBM,OAAA,CAAA,GAAW;;;;;;iBA+BjB,WAAA,CAAA;;;;cAyHH,WAAA,SAAoB,KAAK"}
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ContextLocalStorage } from "./context.js";
|
|
|
2
2
|
import { LogLevel } from "./level.js";
|
|
3
3
|
import { FilterLike } from "./filter.js";
|
|
4
4
|
import { Sink } from "./sink.js";
|
|
5
|
+
import { ScopedConfigLike } from "./scoped-config.js";
|
|
5
6
|
|
|
6
7
|
//#region src/config.d.ts
|
|
7
8
|
|
|
@@ -33,6 +34,18 @@ interface Config<TSinkId extends string, TFilterId extends string> {
|
|
|
33
34
|
*/
|
|
34
35
|
reset?: boolean;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* A scoped configuration for the current execution context.
|
|
39
|
+
*
|
|
40
|
+
* Unlike {@link Config}, this type does not include `reset` or
|
|
41
|
+
* `contextLocalStorage`. Scoped configuration changes only the logging policy
|
|
42
|
+
* for a callback; the context-local storage must already be initialized by the
|
|
43
|
+
* process-global configuration.
|
|
44
|
+
*
|
|
45
|
+
* @since 2.3.0
|
|
46
|
+
*/
|
|
47
|
+
type ScopedConfig<TSinkId extends string, TFilterId extends string> = ScopedConfigLike<TSinkId, TFilterId>;
|
|
48
|
+
type SyncCallbackResult<TResult> = TResult extends PromiseLike<unknown> ? never : TResult;
|
|
36
49
|
/**
|
|
37
50
|
* A logger configuration.
|
|
38
51
|
*/
|
|
@@ -141,6 +154,32 @@ declare function configure<TSinkId extends string, TFilterId extends string>(con
|
|
|
141
154
|
* @since 0.9.0
|
|
142
155
|
*/
|
|
143
156
|
declare function configureSync<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
|
|
157
|
+
/**
|
|
158
|
+
* Runs a callback with a LogTape configuration scoped to the current execution
|
|
159
|
+
* context.
|
|
160
|
+
*
|
|
161
|
+
* The process-global configuration must already provide
|
|
162
|
+
* `contextLocalStorage`. The scoped configuration fully overrides global
|
|
163
|
+
* logger routing while the callback and its async work run.
|
|
164
|
+
*
|
|
165
|
+
* @param config The scoped configuration.
|
|
166
|
+
* @param callback The callback to run.
|
|
167
|
+
* @returns The callback's resolved return value.
|
|
168
|
+
* @since 2.3.0
|
|
169
|
+
*/
|
|
170
|
+
declare function withConfig<TSinkId extends string, TFilterId extends string, TResult>(config: ScopedConfig<TSinkId, TFilterId>, callback: () => TResult): Promise<Awaited<TResult>>;
|
|
171
|
+
/**
|
|
172
|
+
* Runs a synchronous callback with a LogTape configuration scoped to the
|
|
173
|
+
* current execution context.
|
|
174
|
+
*
|
|
175
|
+
* The scoped configuration must not contain async disposable sinks or filters.
|
|
176
|
+
*
|
|
177
|
+
* @param config The scoped configuration.
|
|
178
|
+
* @param callback The callback to run.
|
|
179
|
+
* @returns The callback's return value.
|
|
180
|
+
* @since 2.3.0
|
|
181
|
+
*/
|
|
182
|
+
declare function withConfigSync<TSinkId extends string, TFilterId extends string, TResult>(config: ScopedConfig<TSinkId, TFilterId>, callback: () => SyncCallbackResult<TResult>): SyncCallbackResult<TResult>;
|
|
144
183
|
/**
|
|
145
184
|
* Get the current configuration, if any. Otherwise, `null`.
|
|
146
185
|
* @returns The current configuration, if any. Otherwise, `null`.
|
|
@@ -176,7 +215,6 @@ declare class ConfigError extends Error {
|
|
|
176
215
|
*/
|
|
177
216
|
constructor(message: string);
|
|
178
217
|
}
|
|
179
|
-
//# sourceMappingURL=config.d.ts.map
|
|
180
218
|
//#endregion
|
|
181
|
-
export { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync };
|
|
219
|
+
export { Config, ConfigError, LoggerConfig, ScopedConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync, withConfig, withConfigSync };
|
|
182
220
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","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;AAOhB;AAWA;AAiBA;AA+BA;EAyHa,WAAA,CAAA,EArmBG,QAqmBS,GAAQ,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA5eX,oEAGZ,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiDvB,wEACN,OAAO,SAAS;;;;;;;;;;;;;;iBAoCJ,8EAKZ,aAAa,SAAS,4BACd,UACf,QAAQ,QAAQ;;;;;;;;;;;;iBAiDH,kFAKN,aAAa,SAAS,4BACd,mBAAmB,WAClC,mBAAmB;;;;;iBAyJN,SAAA,CAAA,GAAa;;;;iBAOP,KAAA,CAAA,GAAS;;;;;;iBAWf,SAAA,CAAA;;;;iBAiBM,OAAA,CAAA,GAAW;;;;;;iBA+BjB,WAAA,CAAA;;;;cAyHH,WAAA,SAAoB,KAAK"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toFilter } from "./filter.js";
|
|
2
|
+
import { compileScopedConfig, disposeScopedConfig, disposeScopedConfigSync, runWithScopedConfig, throwCombinedErrors } from "./scoped-config.js";
|
|
2
3
|
import { LoggerImpl } from "./logger.js";
|
|
3
4
|
import { getConsoleSink } from "./sink.js";
|
|
4
5
|
|
|
@@ -7,6 +8,7 @@ import { getConsoleSink } from "./sink.js";
|
|
|
7
8
|
* The current configuration, if any. Otherwise, `null`.
|
|
8
9
|
*/
|
|
9
10
|
let currentConfig = null;
|
|
11
|
+
let activeScopedConfigCount = 0;
|
|
10
12
|
/**
|
|
11
13
|
* Strong references to the loggers.
|
|
12
14
|
* This is to prevent the loggers from being garbage collected so that their
|
|
@@ -91,6 +93,7 @@ function registerDisposeHook(allowAsync) {
|
|
|
91
93
|
* @param config The configuration.
|
|
92
94
|
*/
|
|
93
95
|
async function configure(config) {
|
|
96
|
+
assertNoScopedConfig("configure()");
|
|
94
97
|
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
95
98
|
await reset();
|
|
96
99
|
try {
|
|
@@ -134,6 +137,7 @@ async function configure(config) {
|
|
|
134
137
|
* @since 0.9.0
|
|
135
138
|
*/
|
|
136
139
|
function configureSync(config) {
|
|
140
|
+
assertNoScopedConfig("configureSync()");
|
|
137
141
|
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
138
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().");
|
|
139
143
|
resetSync();
|
|
@@ -144,6 +148,86 @@ function configureSync(config) {
|
|
|
144
148
|
throw e;
|
|
145
149
|
}
|
|
146
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Runs a callback with a LogTape configuration scoped to the current execution
|
|
153
|
+
* context.
|
|
154
|
+
*
|
|
155
|
+
* The process-global configuration must already provide
|
|
156
|
+
* `contextLocalStorage`. The scoped configuration fully overrides global
|
|
157
|
+
* logger routing while the callback and its async work run.
|
|
158
|
+
*
|
|
159
|
+
* @param config The scoped configuration.
|
|
160
|
+
* @param callback The callback to run.
|
|
161
|
+
* @returns The callback's resolved return value.
|
|
162
|
+
* @since 2.3.0
|
|
163
|
+
*/
|
|
164
|
+
async function withConfig(config, callback) {
|
|
165
|
+
const contextLocalStorage = getConfiguredContextLocalStorage("withConfig()");
|
|
166
|
+
const scopedConfig = compileScopedConfig(config, true, (message) => new ConfigError(message));
|
|
167
|
+
let result;
|
|
168
|
+
let callbackError;
|
|
169
|
+
let callbackFailed = false;
|
|
170
|
+
activeScopedConfigCount++;
|
|
171
|
+
try {
|
|
172
|
+
result = await runWithScopedConfig(contextLocalStorage, scopedConfig, callback);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
callbackFailed = true;
|
|
175
|
+
callbackError = error;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await disposeScopedConfig(scopedConfig);
|
|
179
|
+
} catch (disposeError) {
|
|
180
|
+
if (callbackFailed) throwCombinedErrors(callbackError, disposeError);
|
|
181
|
+
throw disposeError;
|
|
182
|
+
} finally {
|
|
183
|
+
activeScopedConfigCount--;
|
|
184
|
+
}
|
|
185
|
+
if (callbackFailed) throw callbackError;
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Runs a synchronous callback with a LogTape configuration scoped to the
|
|
190
|
+
* current execution context.
|
|
191
|
+
*
|
|
192
|
+
* The scoped configuration must not contain async disposable sinks or filters.
|
|
193
|
+
*
|
|
194
|
+
* @param config The scoped configuration.
|
|
195
|
+
* @param callback The callback to run.
|
|
196
|
+
* @returns The callback's return value.
|
|
197
|
+
* @since 2.3.0
|
|
198
|
+
*/
|
|
199
|
+
function withConfigSync(config, callback) {
|
|
200
|
+
const contextLocalStorage = getConfiguredContextLocalStorage("withConfigSync()");
|
|
201
|
+
const scopedConfig = compileScopedConfig(config, false, (message) => new ConfigError(message));
|
|
202
|
+
let result;
|
|
203
|
+
let callbackError;
|
|
204
|
+
let callbackFailed = false;
|
|
205
|
+
activeScopedConfigCount++;
|
|
206
|
+
try {
|
|
207
|
+
result = runWithScopedConfig(contextLocalStorage, scopedConfig, callback);
|
|
208
|
+
if (isThenable(result)) {
|
|
209
|
+
Promise.resolve(result).catch(() => {});
|
|
210
|
+
callbackFailed = true;
|
|
211
|
+
callbackError = new ConfigError("withConfigSync() callback must not return a promise. Use withConfig() for async callbacks.");
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
callbackFailed = true;
|
|
215
|
+
callbackError = error;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
disposeScopedConfigSync(scopedConfig);
|
|
219
|
+
} catch (disposeError) {
|
|
220
|
+
if (callbackFailed) throwCombinedErrors(callbackError, disposeError);
|
|
221
|
+
throw disposeError;
|
|
222
|
+
} finally {
|
|
223
|
+
activeScopedConfigCount--;
|
|
224
|
+
}
|
|
225
|
+
if (callbackFailed) throw callbackError;
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
function isThenable(value) {
|
|
229
|
+
return value != null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
230
|
+
}
|
|
147
231
|
function configureInternal(config, allowAsync) {
|
|
148
232
|
currentConfig = config;
|
|
149
233
|
let metaConfigured = false;
|
|
@@ -205,6 +289,7 @@ function getConfig() {
|
|
|
205
289
|
* Reset the configuration. Mostly for testing purposes.
|
|
206
290
|
*/
|
|
207
291
|
async function reset() {
|
|
292
|
+
assertNoScopedConfig("reset()");
|
|
208
293
|
await dispose();
|
|
209
294
|
resetInternal();
|
|
210
295
|
}
|
|
@@ -214,6 +299,7 @@ async function reset() {
|
|
|
214
299
|
* @since 0.9.0
|
|
215
300
|
*/
|
|
216
301
|
function resetSync() {
|
|
302
|
+
assertNoScopedConfig("resetSync()");
|
|
217
303
|
disposeSync();
|
|
218
304
|
resetInternal();
|
|
219
305
|
}
|
|
@@ -228,6 +314,7 @@ function resetInternal() {
|
|
|
228
314
|
* Dispose of the disposables.
|
|
229
315
|
*/
|
|
230
316
|
async function dispose() {
|
|
317
|
+
assertNoScopedConfig("dispose()");
|
|
231
318
|
const errors = [];
|
|
232
319
|
try {
|
|
233
320
|
disposeSyncFilters();
|
|
@@ -257,6 +344,7 @@ async function dispose() {
|
|
|
257
344
|
* @since 0.9.0
|
|
258
345
|
*/
|
|
259
346
|
function disposeSync() {
|
|
347
|
+
assertNoScopedConfig("disposeSync()");
|
|
260
348
|
const errors = [];
|
|
261
349
|
try {
|
|
262
350
|
disposeSyncFilters();
|
|
@@ -270,6 +358,15 @@ function disposeSync() {
|
|
|
270
358
|
}
|
|
271
359
|
throwDisposeErrors(errors);
|
|
272
360
|
}
|
|
361
|
+
function getConfiguredContextLocalStorage(functionName) {
|
|
362
|
+
if (currentConfig == null) throw new ConfigError(`${functionName} requires LogTape to be configured first.`);
|
|
363
|
+
const contextLocalStorage = LoggerImpl.getLogger().contextLocalStorage;
|
|
364
|
+
if (contextLocalStorage == null) throw new ConfigError(`${functionName} requires Config.contextLocalStorage to be configured.`);
|
|
365
|
+
return contextLocalStorage;
|
|
366
|
+
}
|
|
367
|
+
function assertNoScopedConfig(functionName) {
|
|
368
|
+
if (activeScopedConfigCount > 0) throw new ConfigError(`${functionName} cannot be called while a scoped configuration is active. Use nested withConfig() instead.`);
|
|
369
|
+
}
|
|
273
370
|
function disposeSyncFilters() {
|
|
274
371
|
disposeSyncDisposables(filterDisposables);
|
|
275
372
|
}
|
|
@@ -336,5 +433,5 @@ var ConfigError = class extends Error {
|
|
|
336
433
|
};
|
|
337
434
|
|
|
338
435
|
//#endregion
|
|
339
|
-
export { ConfigError, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync };
|
|
436
|
+
export { ConfigError, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync, withConfig, withConfigSync };
|
|
340
437
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -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>","errors: unknown[]","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 { 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 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;\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 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 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\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 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 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 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 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 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":";;;;;;;;AAmFA,IAAIA,gBAA+C;;;;;;AAOnD,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,KAAI,iBAAiB,SAAS,OAAO,MACnC,OAAM,IAAI,YACR;AAGJ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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","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,QAAQ,KAAK;CAChC,SAAQ,GAAG;AACV,MA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