@logtape/logtape 0.11.0 → 0.12.0-dev.182
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/config.test.ts +591 -0
- package/config.ts +421 -0
- package/context.test.ts +187 -0
- package/context.ts +55 -0
- package/deno.json +36 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/config.cjs +247 -0
- package/dist/config.d.cts +189 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.ts +189 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +241 -0
- package/dist/config.js.map +1 -0
- package/dist/context.cjs +30 -0
- package/dist/context.d.cts +39 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.ts +39 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +31 -0
- package/dist/context.js.map +1 -0
- package/dist/filter.cjs +32 -0
- package/dist/filter.d.cts +37 -0
- package/dist/filter.d.cts.map +1 -0
- package/{types → dist}/filter.d.ts +12 -6
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +31 -0
- package/dist/filter.js.map +1 -0
- package/dist/formatter.cjs +281 -0
- package/dist/formatter.d.cts +338 -0
- package/dist/formatter.d.cts.map +1 -0
- package/dist/formatter.d.ts +338 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +275 -0
- package/dist/formatter.js.map +1 -0
- package/dist/level.cjs +64 -0
- package/dist/level.d.cts +34 -0
- package/dist/level.d.cts.map +1 -0
- package/{types → dist}/level.d.ts +7 -5
- package/dist/level.d.ts.map +1 -0
- package/dist/level.js +62 -0
- package/dist/level.js.map +1 -0
- package/dist/logger.cjs +351 -0
- package/dist/logger.d.cts +501 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.ts +501 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +351 -0
- package/dist/logger.js.map +1 -0
- package/dist/mod.cjs +33 -0
- package/dist/mod.d.cts +9 -0
- package/dist/mod.d.ts +9 -0
- package/dist/mod.js +9 -0
- package/dist/record.d.cts +50 -0
- package/dist/record.d.cts.map +1 -0
- package/dist/record.d.ts +50 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/sink.cjs +95 -0
- package/dist/sink.d.cts +112 -0
- package/dist/sink.d.cts.map +1 -0
- package/{types → dist}/sink.d.ts +49 -45
- package/dist/sink.d.ts.map +1 -0
- package/dist/sink.js +94 -0
- package/dist/sink.js.map +1 -0
- package/dist/util.cjs +9 -0
- package/dist/util.d.cts +12 -0
- package/dist/util.d.cts.map +1 -0
- package/dist/util.d.ts +12 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.deno.cjs +16 -0
- package/dist/util.deno.d.cts +12 -0
- package/dist/util.deno.d.cts.map +1 -0
- package/dist/util.deno.d.ts +12 -0
- package/dist/util.deno.d.ts.map +1 -0
- package/dist/util.deno.js +16 -0
- package/dist/util.deno.js.map +1 -0
- package/dist/util.js +9 -0
- package/dist/util.js.map +1 -0
- package/dist/util.node.cjs +10 -0
- package/dist/util.node.d.cts +12 -0
- package/dist/util.node.d.cts.map +1 -0
- package/dist/util.node.d.ts +12 -0
- package/dist/util.node.d.ts.map +1 -0
- package/dist/util.node.js +10 -0
- package/dist/util.node.js.map +1 -0
- package/filter.test.ts +70 -0
- package/filter.ts +57 -0
- package/fixtures.ts +30 -0
- package/formatter.test.ts +530 -0
- package/formatter.ts +724 -0
- package/level.test.ts +47 -0
- package/level.ts +67 -0
- package/logger.test.ts +823 -0
- package/logger.ts +1124 -0
- package/mod.ts +54 -0
- package/package.json +35 -23
- package/record.ts +49 -0
- package/sink.test.ts +219 -0
- package/sink.ts +167 -0
- package/tsdown.config.ts +24 -0
- package/util.deno.ts +19 -0
- package/util.node.ts +12 -0
- package/util.ts +11 -0
- package/esm/_dnt.shims.js +0 -57
- package/esm/config.js +0 -297
- package/esm/context.js +0 -23
- package/esm/filter.js +0 -42
- package/esm/formatter.js +0 -370
- package/esm/level.js +0 -59
- package/esm/logger.js +0 -517
- package/esm/mod.js +0 -8
- package/esm/nodeUtil.cjs +0 -20
- package/esm/nodeUtil.js +0 -2
- package/esm/package.json +0 -3
- package/esm/record.js +0 -1
- package/esm/sink.js +0 -96
- package/script/_dnt.shims.js +0 -60
- package/script/config.js +0 -331
- package/script/context.js +0 -26
- package/script/filter.js +0 -46
- package/script/formatter.js +0 -380
- package/script/level.js +0 -64
- package/script/logger.js +0 -548
- package/script/mod.js +0 -36
- package/script/nodeUtil.js +0 -20
- package/script/package.json +0 -3
- package/script/record.js +0 -2
- package/script/sink.js +0 -101
- package/types/_dnt.shims.d.ts +0 -2
- package/types/_dnt.shims.d.ts.map +0 -1
- package/types/_dnt.test_shims.d.ts.map +0 -1
- package/types/config.d.ts +0 -183
- package/types/config.d.ts.map +0 -1
- package/types/config.test.d.ts.map +0 -1
- package/types/context.d.ts +0 -35
- package/types/context.d.ts.map +0 -1
- package/types/context.test.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/_constants.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/_diff.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/_format.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_equals.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_false.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_greater_or_equal.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_is_error.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_less_or_equal.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_rejects.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_strict_equals.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_throws.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/assertion_error.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/assert/0.222.1/equal.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/async/0.222.1/delay.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/fmt/0.222.1/colors.d.ts.map +0 -1
- package/types/filter.d.ts.map +0 -1
- package/types/filter.test.d.ts.map +0 -1
- package/types/fixtures.d.ts.map +0 -1
- package/types/formatter.d.ts +0 -332
- package/types/formatter.d.ts.map +0 -1
- package/types/formatter.test.d.ts.map +0 -1
- package/types/level.d.ts.map +0 -1
- package/types/level.test.d.ts.map +0 -1
- package/types/logger.d.ts +0 -573
- package/types/logger.d.ts.map +0 -1
- package/types/logger.test.d.ts.map +0 -1
- package/types/mod.d.ts +0 -9
- package/types/mod.d.ts.map +0 -1
- package/types/nodeUtil.d.ts +0 -12
- package/types/nodeUtil.d.ts.map +0 -1
- package/types/record.d.ts +0 -44
- package/types/record.d.ts.map +0 -1
- package/types/sink.d.ts.map +0 -1
- package/types/sink.test.d.ts.map +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
const require_filter = require('./filter.cjs');
|
|
2
|
+
const require_logger = require('./logger.cjs');
|
|
3
|
+
const require_sink = require('./sink.cjs');
|
|
4
|
+
|
|
5
|
+
//#region config.ts
|
|
6
|
+
/**
|
|
7
|
+
* The current configuration, if any. Otherwise, `null`.
|
|
8
|
+
*/
|
|
9
|
+
let currentConfig = null;
|
|
10
|
+
/**
|
|
11
|
+
* Strong references to the loggers.
|
|
12
|
+
* This is to prevent the loggers from being garbage collected so that their
|
|
13
|
+
* sinks and filters are not removed.
|
|
14
|
+
*/
|
|
15
|
+
const strongRefs = /* @__PURE__ */ new Set();
|
|
16
|
+
/**
|
|
17
|
+
* Disposables to dispose when resetting the configuration.
|
|
18
|
+
*/
|
|
19
|
+
const disposables = /* @__PURE__ */ new Set();
|
|
20
|
+
/**
|
|
21
|
+
* Async disposables to dispose when resetting the configuration.
|
|
22
|
+
*/
|
|
23
|
+
const asyncDisposables = /* @__PURE__ */ new Set();
|
|
24
|
+
/**
|
|
25
|
+
* Check if a config is for the meta logger.
|
|
26
|
+
*/
|
|
27
|
+
function isLoggerConfigMeta(cfg) {
|
|
28
|
+
return cfg.category.length === 0 || cfg.category.length === 1 && cfg.category[0] === "logtape" || cfg.category.length === 2 && cfg.category[0] === "logtape" && cfg.category[1] === "meta";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Configure the loggers with the specified configuration.
|
|
32
|
+
*
|
|
33
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
34
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* await configure({
|
|
39
|
+
* sinks: {
|
|
40
|
+
* console: getConsoleSink(),
|
|
41
|
+
* },
|
|
42
|
+
* filters: {
|
|
43
|
+
* slow: (log) =>
|
|
44
|
+
* "duration" in log.properties &&
|
|
45
|
+
* log.properties.duration as number > 1000,
|
|
46
|
+
* },
|
|
47
|
+
* loggers: [
|
|
48
|
+
* {
|
|
49
|
+
* category: "my-app",
|
|
50
|
+
* sinks: ["console"],
|
|
51
|
+
* level: "info",
|
|
52
|
+
* },
|
|
53
|
+
* {
|
|
54
|
+
* category: ["my-app", "sql"],
|
|
55
|
+
* filters: ["slow"],
|
|
56
|
+
* level: "debug",
|
|
57
|
+
* },
|
|
58
|
+
* {
|
|
59
|
+
* category: "logtape",
|
|
60
|
+
* sinks: ["console"],
|
|
61
|
+
* level: "error",
|
|
62
|
+
* },
|
|
63
|
+
* ],
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param config The configuration.
|
|
68
|
+
*/
|
|
69
|
+
async function configure(config) {
|
|
70
|
+
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
71
|
+
await reset();
|
|
72
|
+
try {
|
|
73
|
+
configureInternal(config, true);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e instanceof ConfigError) await reset();
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Configure sync loggers with the specified configuration.
|
|
81
|
+
*
|
|
82
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
83
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
84
|
+
*
|
|
85
|
+
* Also note that passing async sinks or filters will throw. If
|
|
86
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* configureSync({
|
|
91
|
+
* sinks: {
|
|
92
|
+
* console: getConsoleSink(),
|
|
93
|
+
* },
|
|
94
|
+
* loggers: [
|
|
95
|
+
* {
|
|
96
|
+
* category: "my-app",
|
|
97
|
+
* sinks: ["console"],
|
|
98
|
+
* level: "info",
|
|
99
|
+
* },
|
|
100
|
+
* {
|
|
101
|
+
* category: "logtape",
|
|
102
|
+
* sinks: ["console"],
|
|
103
|
+
* level: "error",
|
|
104
|
+
* },
|
|
105
|
+
* ],
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param config The configuration.
|
|
110
|
+
* @since 0.9.0
|
|
111
|
+
*/
|
|
112
|
+
function configureSync(config) {
|
|
113
|
+
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
114
|
+
if (asyncDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
|
|
115
|
+
resetSync();
|
|
116
|
+
try {
|
|
117
|
+
configureInternal(config, false);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
if (e instanceof ConfigError) resetSync();
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function configureInternal(config, allowAsync) {
|
|
124
|
+
currentConfig = config;
|
|
125
|
+
let metaConfigured = false;
|
|
126
|
+
let levelUsed = false;
|
|
127
|
+
const configuredCategories = /* @__PURE__ */ new Set();
|
|
128
|
+
for (const cfg of config.loggers) {
|
|
129
|
+
if (isLoggerConfigMeta(cfg)) metaConfigured = true;
|
|
130
|
+
const categoryKey = Array.isArray(cfg.category) ? JSON.stringify(cfg.category) : JSON.stringify([cfg.category]);
|
|
131
|
+
if (configuredCategories.has(categoryKey)) throw new ConfigError(`Duplicate logger configuration for category: ${categoryKey}. Each category can only be configured once.`);
|
|
132
|
+
configuredCategories.add(categoryKey);
|
|
133
|
+
const logger = require_logger.LoggerImpl.getLogger(cfg.category);
|
|
134
|
+
for (const sinkId of cfg.sinks ?? []) {
|
|
135
|
+
const sink = config.sinks[sinkId];
|
|
136
|
+
if (!sink) throw new ConfigError(`Sink not found: ${sinkId}.`);
|
|
137
|
+
logger.sinks.push(sink);
|
|
138
|
+
}
|
|
139
|
+
logger.parentSinks = cfg.parentSinks ?? "inherit";
|
|
140
|
+
if (cfg.lowestLevel !== void 0) logger.lowestLevel = cfg.lowestLevel;
|
|
141
|
+
if (cfg.level !== void 0) {
|
|
142
|
+
levelUsed = true;
|
|
143
|
+
logger.filters.push(require_filter.toFilter(cfg.level));
|
|
144
|
+
}
|
|
145
|
+
for (const filterId of cfg.filters ?? []) {
|
|
146
|
+
const filter = config.filters?.[filterId];
|
|
147
|
+
if (filter === void 0) throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
148
|
+
logger.filters.push(require_filter.toFilter(filter));
|
|
149
|
+
}
|
|
150
|
+
strongRefs.add(logger);
|
|
151
|
+
}
|
|
152
|
+
require_logger.LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
153
|
+
for (const sink of Object.values(config.sinks)) {
|
|
154
|
+
if (Symbol.asyncDispose in sink) if (allowAsync) asyncDisposables.add(sink);
|
|
155
|
+
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
156
|
+
if (Symbol.dispose in sink) disposables.add(sink);
|
|
157
|
+
}
|
|
158
|
+
for (const filter of Object.values(config.filters ?? {})) {
|
|
159
|
+
if (filter == null || typeof filter === "string") continue;
|
|
160
|
+
if (Symbol.asyncDispose in filter) if (allowAsync) asyncDisposables.add(filter);
|
|
161
|
+
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
162
|
+
if (Symbol.dispose in filter) disposables.add(filter);
|
|
163
|
+
}
|
|
164
|
+
if ("process" in globalThis && !("Deno" in globalThis)) process.on("exit", allowAsync ? dispose : disposeSync);
|
|
165
|
+
else addEventListener("unload", allowAsync ? dispose : disposeSync);
|
|
166
|
+
const meta = require_logger.LoggerImpl.getLogger(["logtape", "meta"]);
|
|
167
|
+
if (!metaConfigured) meta.sinks.push(require_sink.getConsoleSink());
|
|
168
|
+
meta.info("LogTape loggers are configured. Note that LogTape itself uses the meta logger, which has category {metaLoggerCategory}. The meta logger purposes to log internal errors such as sink exceptions. If you are seeing this message, the meta logger is automatically configured. It's recommended to configure the meta logger with a separate sink so that you can easily notice if logging itself fails or is misconfigured. To turn off this message, configure the meta logger with higher log levels than {dismissLevel}. See also <https://logtape.org/manual/categories#meta-logger>.", {
|
|
169
|
+
metaLoggerCategory: ["logtape", "meta"],
|
|
170
|
+
dismissLevel: "info"
|
|
171
|
+
});
|
|
172
|
+
if (levelUsed) meta.warn("The level option is deprecated in favor of lowestLevel option. Please update your configuration. See also <https://logtape.org/manual/levels#configuring-severity-levels>.");
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
176
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
177
|
+
*/
|
|
178
|
+
function getConfig() {
|
|
179
|
+
return currentConfig;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reset the configuration. Mostly for testing purposes.
|
|
183
|
+
*/
|
|
184
|
+
async function reset() {
|
|
185
|
+
await dispose();
|
|
186
|
+
resetInternal();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
190
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
191
|
+
* @since 0.9.0
|
|
192
|
+
*/
|
|
193
|
+
function resetSync() {
|
|
194
|
+
disposeSync();
|
|
195
|
+
resetInternal();
|
|
196
|
+
}
|
|
197
|
+
function resetInternal() {
|
|
198
|
+
const rootLogger = require_logger.LoggerImpl.getLogger([]);
|
|
199
|
+
rootLogger.resetDescendants();
|
|
200
|
+
delete rootLogger.contextLocalStorage;
|
|
201
|
+
strongRefs.clear();
|
|
202
|
+
currentConfig = null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Dispose of the disposables.
|
|
206
|
+
*/
|
|
207
|
+
async function dispose() {
|
|
208
|
+
disposeSync();
|
|
209
|
+
const promises = [];
|
|
210
|
+
for (const disposable of asyncDisposables) {
|
|
211
|
+
promises.push(disposable[Symbol.asyncDispose]());
|
|
212
|
+
asyncDisposables.delete(disposable);
|
|
213
|
+
}
|
|
214
|
+
await Promise.all(promises);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
218
|
+
* use {@link dispose} if you have async sinks.
|
|
219
|
+
* @since 0.9.0
|
|
220
|
+
*/
|
|
221
|
+
function disposeSync() {
|
|
222
|
+
for (const disposable of disposables) disposable[Symbol.dispose]();
|
|
223
|
+
disposables.clear();
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* A configuration error.
|
|
227
|
+
*/
|
|
228
|
+
var ConfigError = class extends Error {
|
|
229
|
+
/**
|
|
230
|
+
* Constructs a new configuration error.
|
|
231
|
+
* @param message The error message.
|
|
232
|
+
*/
|
|
233
|
+
constructor(message) {
|
|
234
|
+
super(message);
|
|
235
|
+
this.name = "ConfigureError";
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
exports.ConfigError = ConfigError;
|
|
241
|
+
exports.configure = configure;
|
|
242
|
+
exports.configureSync = configureSync;
|
|
243
|
+
exports.dispose = dispose;
|
|
244
|
+
exports.disposeSync = disposeSync;
|
|
245
|
+
exports.getConfig = getConfig;
|
|
246
|
+
exports.reset = reset;
|
|
247
|
+
exports.resetSync = resetSync;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ContextLocalStorage } from "./context.cjs";
|
|
2
|
+
import { LogLevel } from "./level.cjs";
|
|
3
|
+
import { FilterLike } from "./filter.cjs";
|
|
4
|
+
import { Sink } from "./sink.cjs";
|
|
5
|
+
|
|
6
|
+
//#region config.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A configuration for the loggers.
|
|
10
|
+
*/
|
|
11
|
+
interface Config<TSinkId extends string, TFilterId extends string> {
|
|
12
|
+
/**
|
|
13
|
+
* The sinks to use. The keys are the sink identifiers, and the values are
|
|
14
|
+
* {@link Sink}s.
|
|
15
|
+
*/
|
|
16
|
+
sinks: Record<TSinkId, Sink>;
|
|
17
|
+
/**
|
|
18
|
+
* The filters to use. The keys are the filter identifiers, and the values
|
|
19
|
+
* are either {@link Filter}s or {@link LogLevel}s.
|
|
20
|
+
*/
|
|
21
|
+
filters?: Record<TFilterId, FilterLike>;
|
|
22
|
+
/**
|
|
23
|
+
* The loggers to configure.
|
|
24
|
+
*/
|
|
25
|
+
loggers: LoggerConfig<TSinkId, TFilterId>[];
|
|
26
|
+
/**
|
|
27
|
+
* The context-local storage to use for implicit contexts.
|
|
28
|
+
* @since 0.7.0
|
|
29
|
+
*/
|
|
30
|
+
contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to reset the configuration before applying this one.
|
|
33
|
+
*/
|
|
34
|
+
reset?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A logger configuration.
|
|
38
|
+
*/
|
|
39
|
+
interface LoggerConfig<TSinkId extends string, TFilterId extends string> {
|
|
40
|
+
/**
|
|
41
|
+
* The category of the logger. If a string, it is equivalent to an array
|
|
42
|
+
* with one element.
|
|
43
|
+
*/
|
|
44
|
+
category: string | string[];
|
|
45
|
+
/**
|
|
46
|
+
* The sink identifiers to use.
|
|
47
|
+
*/
|
|
48
|
+
sinks?: TSinkId[];
|
|
49
|
+
/**
|
|
50
|
+
* Whether to inherit the parent's sinks. If `inherit`, the parent's sinks
|
|
51
|
+
* are used along with the specified sinks. If `override`, the parent's
|
|
52
|
+
* sinks are not used, and only the specified sinks are used.
|
|
53
|
+
*
|
|
54
|
+
* The default is `inherit`.
|
|
55
|
+
* @default `"inherit"
|
|
56
|
+
* @since 0.6.0
|
|
57
|
+
*/
|
|
58
|
+
parentSinks?: "inherit" | "override";
|
|
59
|
+
/**
|
|
60
|
+
* The filter identifiers to use.
|
|
61
|
+
*/
|
|
62
|
+
filters?: TFilterId[];
|
|
63
|
+
/**
|
|
64
|
+
* The log level to filter by. If `null`, the logger will reject all
|
|
65
|
+
* records.
|
|
66
|
+
* @deprecated Use `filters` instead for backward compatibility, or use
|
|
67
|
+
* `lowestLevel` for less-misleading behavior.
|
|
68
|
+
*/
|
|
69
|
+
level?: LogLevel | null;
|
|
70
|
+
/**
|
|
71
|
+
* The lowest log level to accept. If `null`, the logger will reject all
|
|
72
|
+
* records.
|
|
73
|
+
* @since 0.8.0
|
|
74
|
+
*/
|
|
75
|
+
lowestLevel?: LogLevel | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configure the loggers with the specified configuration.
|
|
79
|
+
*
|
|
80
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
81
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* await configure({
|
|
86
|
+
* sinks: {
|
|
87
|
+
* console: getConsoleSink(),
|
|
88
|
+
* },
|
|
89
|
+
* filters: {
|
|
90
|
+
* slow: (log) =>
|
|
91
|
+
* "duration" in log.properties &&
|
|
92
|
+
* log.properties.duration as number > 1000,
|
|
93
|
+
* },
|
|
94
|
+
* loggers: [
|
|
95
|
+
* {
|
|
96
|
+
* category: "my-app",
|
|
97
|
+
* sinks: ["console"],
|
|
98
|
+
* level: "info",
|
|
99
|
+
* },
|
|
100
|
+
* {
|
|
101
|
+
* category: ["my-app", "sql"],
|
|
102
|
+
* filters: ["slow"],
|
|
103
|
+
* level: "debug",
|
|
104
|
+
* },
|
|
105
|
+
* {
|
|
106
|
+
* category: "logtape",
|
|
107
|
+
* sinks: ["console"],
|
|
108
|
+
* level: "error",
|
|
109
|
+
* },
|
|
110
|
+
* ],
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param config The configuration.
|
|
115
|
+
*/
|
|
116
|
+
declare function configure<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Configure sync loggers with the specified configuration.
|
|
119
|
+
*
|
|
120
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
121
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
122
|
+
*
|
|
123
|
+
* Also note that passing async sinks or filters will throw. If
|
|
124
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* configureSync({
|
|
129
|
+
* sinks: {
|
|
130
|
+
* console: getConsoleSink(),
|
|
131
|
+
* },
|
|
132
|
+
* loggers: [
|
|
133
|
+
* {
|
|
134
|
+
* category: "my-app",
|
|
135
|
+
* sinks: ["console"],
|
|
136
|
+
* level: "info",
|
|
137
|
+
* },
|
|
138
|
+
* {
|
|
139
|
+
* category: "logtape",
|
|
140
|
+
* sinks: ["console"],
|
|
141
|
+
* level: "error",
|
|
142
|
+
* },
|
|
143
|
+
* ],
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @param config The configuration.
|
|
148
|
+
* @since 0.9.0
|
|
149
|
+
*/
|
|
150
|
+
declare function configureSync<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
153
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
154
|
+
*/
|
|
155
|
+
declare function getConfig(): Config<string, string> | null;
|
|
156
|
+
/**
|
|
157
|
+
* Reset the configuration. Mostly for testing purposes.
|
|
158
|
+
*/
|
|
159
|
+
declare function reset(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
162
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
163
|
+
* @since 0.9.0
|
|
164
|
+
*/
|
|
165
|
+
declare function resetSync(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Dispose of the disposables.
|
|
168
|
+
*/
|
|
169
|
+
declare function dispose(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
172
|
+
* use {@link dispose} if you have async sinks.
|
|
173
|
+
* @since 0.9.0
|
|
174
|
+
*/
|
|
175
|
+
declare function disposeSync(): void;
|
|
176
|
+
/**
|
|
177
|
+
* A configuration error.
|
|
178
|
+
*/
|
|
179
|
+
declare class ConfigError extends Error {
|
|
180
|
+
/**
|
|
181
|
+
* Constructs a new configuration error.
|
|
182
|
+
* @param message The error message.
|
|
183
|
+
*/
|
|
184
|
+
constructor(message: string);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=config.d.ts.map
|
|
187
|
+
//#endregion
|
|
188
|
+
export { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync };
|
|
189
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AASA;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;AAW3C;EAA6B,OAAA,EAjBlB,YAiBkB,CAjBL,OAiBK,EAjBI,SAiBJ,CAAA,EAAA;EAAA;;;;EA4CL,mBAAA,CAAA,EAvDA,mBAuDA,CAvDoB,MAuDpB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EA6EF;;;EAGE,KAAE,CAAA,EAAA,OAAA;;;AAAoB;AAgD9C;AAA6B,UA5KZ,YA4KY,CAAA,gBAAA,MAAA,EAAA,kBAAA,MAAA,CAAA,CAAA;EAAA;;;AACb;EA6IA,QAAA,EAAA,MAAS,GAAA,MAAI,EAAA;EAOP;AAUtB;AAgBA;EAegB,KAAA,CAAA,EA7VN,OA6ViB,EAAA;EAQd;;;;;;;;;;;;;YArVD;;;;;;;UAQF;;;;;;gBAOM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6EM,oEAGZ,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDvB,wEACN,OAAO,SAAS;;;;;iBA6IV,SAAA,CAAA,GAAa;;;;iBAOP,KAAA,CAAA,GAAS;;;;;;iBAUf,SAAA,CAAA;;;;iBAgBM,OAAA,CAAA,GAAW;;;;;;iBAejB,WAAA,CAAA;;;;cAQH,WAAA,SAAoB,KAAK"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { ContextLocalStorage } from "./context.js";
|
|
2
|
+
import { LogLevel } from "./level.js";
|
|
3
|
+
import { FilterLike } from "./filter.js";
|
|
4
|
+
import { Sink } from "./sink.js";
|
|
5
|
+
|
|
6
|
+
//#region config.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A configuration for the loggers.
|
|
10
|
+
*/
|
|
11
|
+
interface Config<TSinkId extends string, TFilterId extends string> {
|
|
12
|
+
/**
|
|
13
|
+
* The sinks to use. The keys are the sink identifiers, and the values are
|
|
14
|
+
* {@link Sink}s.
|
|
15
|
+
*/
|
|
16
|
+
sinks: Record<TSinkId, Sink>;
|
|
17
|
+
/**
|
|
18
|
+
* The filters to use. The keys are the filter identifiers, and the values
|
|
19
|
+
* are either {@link Filter}s or {@link LogLevel}s.
|
|
20
|
+
*/
|
|
21
|
+
filters?: Record<TFilterId, FilterLike>;
|
|
22
|
+
/**
|
|
23
|
+
* The loggers to configure.
|
|
24
|
+
*/
|
|
25
|
+
loggers: LoggerConfig<TSinkId, TFilterId>[];
|
|
26
|
+
/**
|
|
27
|
+
* The context-local storage to use for implicit contexts.
|
|
28
|
+
* @since 0.7.0
|
|
29
|
+
*/
|
|
30
|
+
contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to reset the configuration before applying this one.
|
|
33
|
+
*/
|
|
34
|
+
reset?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A logger configuration.
|
|
38
|
+
*/
|
|
39
|
+
interface LoggerConfig<TSinkId extends string, TFilterId extends string> {
|
|
40
|
+
/**
|
|
41
|
+
* The category of the logger. If a string, it is equivalent to an array
|
|
42
|
+
* with one element.
|
|
43
|
+
*/
|
|
44
|
+
category: string | string[];
|
|
45
|
+
/**
|
|
46
|
+
* The sink identifiers to use.
|
|
47
|
+
*/
|
|
48
|
+
sinks?: TSinkId[];
|
|
49
|
+
/**
|
|
50
|
+
* Whether to inherit the parent's sinks. If `inherit`, the parent's sinks
|
|
51
|
+
* are used along with the specified sinks. If `override`, the parent's
|
|
52
|
+
* sinks are not used, and only the specified sinks are used.
|
|
53
|
+
*
|
|
54
|
+
* The default is `inherit`.
|
|
55
|
+
* @default `"inherit"
|
|
56
|
+
* @since 0.6.0
|
|
57
|
+
*/
|
|
58
|
+
parentSinks?: "inherit" | "override";
|
|
59
|
+
/**
|
|
60
|
+
* The filter identifiers to use.
|
|
61
|
+
*/
|
|
62
|
+
filters?: TFilterId[];
|
|
63
|
+
/**
|
|
64
|
+
* The log level to filter by. If `null`, the logger will reject all
|
|
65
|
+
* records.
|
|
66
|
+
* @deprecated Use `filters` instead for backward compatibility, or use
|
|
67
|
+
* `lowestLevel` for less-misleading behavior.
|
|
68
|
+
*/
|
|
69
|
+
level?: LogLevel | null;
|
|
70
|
+
/**
|
|
71
|
+
* The lowest log level to accept. If `null`, the logger will reject all
|
|
72
|
+
* records.
|
|
73
|
+
* @since 0.8.0
|
|
74
|
+
*/
|
|
75
|
+
lowestLevel?: LogLevel | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configure the loggers with the specified configuration.
|
|
79
|
+
*
|
|
80
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
81
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* await configure({
|
|
86
|
+
* sinks: {
|
|
87
|
+
* console: getConsoleSink(),
|
|
88
|
+
* },
|
|
89
|
+
* filters: {
|
|
90
|
+
* slow: (log) =>
|
|
91
|
+
* "duration" in log.properties &&
|
|
92
|
+
* log.properties.duration as number > 1000,
|
|
93
|
+
* },
|
|
94
|
+
* loggers: [
|
|
95
|
+
* {
|
|
96
|
+
* category: "my-app",
|
|
97
|
+
* sinks: ["console"],
|
|
98
|
+
* level: "info",
|
|
99
|
+
* },
|
|
100
|
+
* {
|
|
101
|
+
* category: ["my-app", "sql"],
|
|
102
|
+
* filters: ["slow"],
|
|
103
|
+
* level: "debug",
|
|
104
|
+
* },
|
|
105
|
+
* {
|
|
106
|
+
* category: "logtape",
|
|
107
|
+
* sinks: ["console"],
|
|
108
|
+
* level: "error",
|
|
109
|
+
* },
|
|
110
|
+
* ],
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param config The configuration.
|
|
115
|
+
*/
|
|
116
|
+
declare function configure<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Configure sync loggers with the specified configuration.
|
|
119
|
+
*
|
|
120
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
121
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
122
|
+
*
|
|
123
|
+
* Also note that passing async sinks or filters will throw. If
|
|
124
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* configureSync({
|
|
129
|
+
* sinks: {
|
|
130
|
+
* console: getConsoleSink(),
|
|
131
|
+
* },
|
|
132
|
+
* loggers: [
|
|
133
|
+
* {
|
|
134
|
+
* category: "my-app",
|
|
135
|
+
* sinks: ["console"],
|
|
136
|
+
* level: "info",
|
|
137
|
+
* },
|
|
138
|
+
* {
|
|
139
|
+
* category: "logtape",
|
|
140
|
+
* sinks: ["console"],
|
|
141
|
+
* level: "error",
|
|
142
|
+
* },
|
|
143
|
+
* ],
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @param config The configuration.
|
|
148
|
+
* @since 0.9.0
|
|
149
|
+
*/
|
|
150
|
+
declare function configureSync<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
153
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
154
|
+
*/
|
|
155
|
+
declare function getConfig(): Config<string, string> | null;
|
|
156
|
+
/**
|
|
157
|
+
* Reset the configuration. Mostly for testing purposes.
|
|
158
|
+
*/
|
|
159
|
+
declare function reset(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
162
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
163
|
+
* @since 0.9.0
|
|
164
|
+
*/
|
|
165
|
+
declare function resetSync(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Dispose of the disposables.
|
|
168
|
+
*/
|
|
169
|
+
declare function dispose(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
172
|
+
* use {@link dispose} if you have async sinks.
|
|
173
|
+
* @since 0.9.0
|
|
174
|
+
*/
|
|
175
|
+
declare function disposeSync(): void;
|
|
176
|
+
/**
|
|
177
|
+
* A configuration error.
|
|
178
|
+
*/
|
|
179
|
+
declare class ConfigError extends Error {
|
|
180
|
+
/**
|
|
181
|
+
* Constructs a new configuration error.
|
|
182
|
+
* @param message The error message.
|
|
183
|
+
*/
|
|
184
|
+
constructor(message: string);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=config.d.ts.map
|
|
187
|
+
//#endregion
|
|
188
|
+
export { Config, ConfigError, LoggerConfig, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync };
|
|
189
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","names":[],"sources":["../config.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AASA;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;AAW3C;EAA6B,OAAA,EAjBlB,YAiBkB,CAjBL,OAiBK,EAjBI,SAiBJ,CAAA,EAAA;EAAA;;;;EA4CL,mBAAA,CAAA,EAvDA,mBAuDA,CAvDoB,MAuDpB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EA6EF;;;EAGE,KAAE,CAAA,EAAA,OAAA;;;AAAoB;AAgD9C;AAA6B,UA5KZ,YA4KY,CAAA,gBAAA,MAAA,EAAA,kBAAA,MAAA,CAAA,CAAA;EAAA;;;AACb;EA6IA,QAAA,EAAA,MAAS,GAAA,MAAI,EAAA;EAOP;AAUtB;AAgBA;EAegB,KAAA,CAAA,EA7VN,OA6ViB,EAAA;EAQd;;;;;;;;;;;;;YArVD;;;;;;;UAQF;;;;;;gBAOM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6EM,oEAGZ,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDvB,wEACN,OAAO,SAAS;;;;;iBA6IV,SAAA,CAAA,GAAa;;;;iBAOP,KAAA,CAAA,GAAS;;;;;;iBAUf,SAAA,CAAA;;;;iBAgBM,OAAA,CAAA,GAAW;;;;;;iBAejB,WAAA,CAAA;;;;cAQH,WAAA,SAAoB,KAAK"}
|