@logtape/logtape 0.1.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +194 -0
  3. package/esm/_dnt.shims.js +61 -0
  4. package/esm/config.js +108 -0
  5. package/esm/filter.js +42 -0
  6. package/esm/formatter.js +86 -0
  7. package/esm/logger.js +285 -0
  8. package/esm/mod.js +5 -0
  9. package/esm/package.json +3 -0
  10. package/esm/record.js +1 -0
  11. package/esm/sink.js +59 -0
  12. package/package.json +49 -0
  13. package/script/_dnt.shims.js +65 -0
  14. package/script/config.js +114 -0
  15. package/script/filter.js +47 -0
  16. package/script/formatter.js +91 -0
  17. package/script/logger.js +292 -0
  18. package/script/mod.js +15 -0
  19. package/script/package.json +3 -0
  20. package/script/record.js +2 -0
  21. package/script/sink.js +64 -0
  22. package/types/_dnt.shims.d.ts +10 -0
  23. package/types/_dnt.shims.d.ts.map +1 -0
  24. package/types/_dnt.test_shims.d.ts.map +1 -0
  25. package/types/config.d.ts +101 -0
  26. package/types/config.d.ts.map +1 -0
  27. package/types/config.test.d.ts.map +1 -0
  28. package/types/deps/jsr.io/@std/assert/0.222.1/_constants.d.ts.map +1 -0
  29. package/types/deps/jsr.io/@std/assert/0.222.1/_diff.d.ts.map +1 -0
  30. package/types/deps/jsr.io/@std/assert/0.222.1/_format.d.ts.map +1 -0
  31. package/types/deps/jsr.io/@std/assert/0.222.1/assert.d.ts.map +1 -0
  32. package/types/deps/jsr.io/@std/assert/0.222.1/assert_equals.d.ts.map +1 -0
  33. package/types/deps/jsr.io/@std/assert/0.222.1/assert_false.d.ts.map +1 -0
  34. package/types/deps/jsr.io/@std/assert/0.222.1/assert_greater_or_equal.d.ts.map +1 -0
  35. package/types/deps/jsr.io/@std/assert/0.222.1/assert_is_error.d.ts.map +1 -0
  36. package/types/deps/jsr.io/@std/assert/0.222.1/assert_less_or_equal.d.ts.map +1 -0
  37. package/types/deps/jsr.io/@std/assert/0.222.1/assert_strict_equals.d.ts.map +1 -0
  38. package/types/deps/jsr.io/@std/assert/0.222.1/assert_throws.d.ts.map +1 -0
  39. package/types/deps/jsr.io/@std/assert/0.222.1/assertion_error.d.ts.map +1 -0
  40. package/types/deps/jsr.io/@std/assert/0.222.1/equal.d.ts.map +1 -0
  41. package/types/deps/jsr.io/@std/async/0.222.1/delay.d.ts.map +1 -0
  42. package/types/deps/jsr.io/@std/fmt/0.222.1/colors.d.ts.map +1 -0
  43. package/types/filter.d.ts +30 -0
  44. package/types/filter.d.ts.map +1 -0
  45. package/types/filter.test.d.ts.map +1 -0
  46. package/types/fixtures.d.ts.map +1 -0
  47. package/types/formatter.d.ts +38 -0
  48. package/types/formatter.d.ts.map +1 -0
  49. package/types/formatter.test.d.ts.map +1 -0
  50. package/types/logger.d.ts +363 -0
  51. package/types/logger.d.ts.map +1 -0
  52. package/types/logger.test.d.ts.map +1 -0
  53. package/types/mod.d.ts +7 -0
  54. package/types/mod.d.ts.map +1 -0
  55. package/types/record.d.ts +33 -0
  56. package/types/record.d.ts.map +1 -0
  57. package/types/sink.d.ts +55 -0
  58. package/types/sink.d.ts.map +1 -0
  59. package/types/sink.test.d.ts.map +1 -0
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultConsoleFormatter = exports.defaultTextFormatter = void 0;
4
+ /**
5
+ * The severity level abbreviations.
6
+ */
7
+ const levelAbbreviations = {
8
+ "debug": "DBG",
9
+ "info": "INF",
10
+ "warning": "WRN",
11
+ "error": "ERR",
12
+ "fatal": "FTL",
13
+ };
14
+ /**
15
+ * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
16
+ * and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
17
+ * falls back to {@link JSON.stringify}.
18
+ *
19
+ * @param value The value to inspect.
20
+ * @returns The string representation of the value.
21
+ */
22
+ const inspect = eval(`(
23
+ "Deno" in globalThis && "inspect" in globalThis.Deno &&
24
+ typeof globalThis.Deno.inspect === "function"
25
+ ? globalThis.Deno.inspect
26
+ : "util" in globalThis && "inspect" in globalThis.util &&
27
+ globalThis.util.inspect === "function"
28
+ ? globalThis.util.inspect
29
+ : JSON.stringify
30
+ )`);
31
+ /**
32
+ * The default text formatter. This formatter formats log records as follows:
33
+ *
34
+ * ```
35
+ * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
36
+ * ```
37
+ *
38
+ * @param record The log record to format.
39
+ * @returns The formatted log record.
40
+ */
41
+ function defaultTextFormatter(record) {
42
+ const ts = new Date(record.timestamp);
43
+ let msg = "";
44
+ for (let i = 0; i < record.message.length; i++) {
45
+ if (i % 2 === 0)
46
+ msg += record.message[i];
47
+ else
48
+ msg += inspect(record.message[i]);
49
+ }
50
+ const category = record.category.join("\xb7");
51
+ return `${ts.toISOString().replace("T", " ").replace("Z", " +00:00")} [${levelAbbreviations[record.level]}] ${category}: ${msg}\n`;
52
+ }
53
+ exports.defaultTextFormatter = defaultTextFormatter;
54
+ /**
55
+ * The styles for the log level in the console.
56
+ */
57
+ const logLevelStyles = {
58
+ "debug": "background-color: gray; color: white;",
59
+ "info": "background-color: white; color: black;",
60
+ "warning": "background-color: orange;",
61
+ "error": "background-color: red;",
62
+ "fatal": "background-color: maroon;",
63
+ };
64
+ /**
65
+ * The default console formatter.
66
+ *
67
+ * @param record The log record to format.
68
+ * @returns The formatted log record, as an array of arguments for
69
+ * {@link console.log}.
70
+ */
71
+ function defaultConsoleFormatter(record) {
72
+ let msg = "";
73
+ const values = [];
74
+ for (let i = 0; i < record.message.length; i++) {
75
+ if (i % 2 === 0)
76
+ msg += record.message[i];
77
+ else {
78
+ msg += "%o";
79
+ values.push(record.message[i]);
80
+ }
81
+ }
82
+ return [
83
+ `%c${record.level.toUpperCase()}%c %c${record.category.join("\xb7")} %c${msg}`,
84
+ logLevelStyles[record.level],
85
+ "background-color: default;",
86
+ "color: gray;",
87
+ "color: default;",
88
+ ...values,
89
+ ];
90
+ }
91
+ exports.defaultConsoleFormatter = defaultConsoleFormatter;
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderMessage = exports.parseMessageTemplate = exports.LoggerImpl = exports.getLogger = void 0;
4
+ /**
5
+ * Get a logger with the given category.
6
+ *
7
+ * ```typescript
8
+ * const logger = getLogger(["my-app"]);
9
+ * ```
10
+ *
11
+ * @param category The category of the logger. It can be a string or an array
12
+ * of strings. If it is a string, it is equivalent to an array
13
+ * with a single element.
14
+ * @returns The logger.
15
+ */
16
+ function getLogger(category = []) {
17
+ return LoggerImpl.getLogger(category);
18
+ }
19
+ exports.getLogger = getLogger;
20
+ /**
21
+ * The root logger.
22
+ */
23
+ let rootLogger = null;
24
+ /**
25
+ * A logger implementation. Do not use this directly; use {@link getLogger}
26
+ * instead. This class is exported for testing purposes.
27
+ */
28
+ class LoggerImpl {
29
+ static getLogger(category = []) {
30
+ if (rootLogger == null) {
31
+ rootLogger = new LoggerImpl(null, []);
32
+ }
33
+ if (typeof category === "string")
34
+ return rootLogger.getChild(category);
35
+ if (category.length === 0)
36
+ return rootLogger;
37
+ return rootLogger.getChild(category);
38
+ }
39
+ constructor(parent, category) {
40
+ Object.defineProperty(this, "parent", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ Object.defineProperty(this, "children", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: void 0
51
+ });
52
+ Object.defineProperty(this, "category", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: void 0
57
+ });
58
+ Object.defineProperty(this, "sinks", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: void 0
63
+ });
64
+ Object.defineProperty(this, "filters", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: void 0
69
+ });
70
+ this.parent = parent;
71
+ this.children = {};
72
+ this.category = category;
73
+ this.sinks = [];
74
+ this.filters = [];
75
+ }
76
+ getChild(subcategory) {
77
+ const name = typeof subcategory === "string" ? subcategory : subcategory[0];
78
+ let child = this.children[name]?.deref();
79
+ if (child == null) {
80
+ child = new LoggerImpl(this, [...this.category, name]);
81
+ this.children[name] = new WeakRef(child);
82
+ }
83
+ if (typeof subcategory === "string" || subcategory.length === 1) {
84
+ return child;
85
+ }
86
+ return child.getChild(subcategory.slice(1));
87
+ }
88
+ /**
89
+ * Reset the logger. This removes all sinks and filters from the logger.
90
+ */
91
+ reset() {
92
+ while (this.sinks.length > 0)
93
+ this.sinks.shift();
94
+ while (this.filters.length > 0)
95
+ this.filters.shift();
96
+ }
97
+ /**
98
+ * Reset the logger and all its descendants. This removes all sinks and
99
+ * filters from the logger and all its descendants.
100
+ */
101
+ resetDescendants() {
102
+ for (const child of Object.values(this.children)) {
103
+ const logger = child.deref();
104
+ if (logger != null)
105
+ logger.resetDescendants();
106
+ }
107
+ this.reset();
108
+ }
109
+ filter(record) {
110
+ for (const filter of this.filters) {
111
+ if (!filter(record))
112
+ return false;
113
+ }
114
+ if (this.filters.length < 1)
115
+ return this.parent?.filter(record) ?? true;
116
+ return true;
117
+ }
118
+ *getSinks() {
119
+ if (this.parent != null) {
120
+ for (const sink of this.parent.getSinks())
121
+ yield sink;
122
+ }
123
+ for (const sink of this.sinks)
124
+ yield sink;
125
+ }
126
+ emit(record, bypassSinks) {
127
+ if (!this.filter(record))
128
+ return;
129
+ for (const sink of this.getSinks()) {
130
+ if (bypassSinks?.has(sink))
131
+ continue;
132
+ try {
133
+ sink(record);
134
+ }
135
+ catch (error) {
136
+ const bypassSinks2 = new Set(bypassSinks);
137
+ bypassSinks2.add(sink);
138
+ metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", { sink, error, record }, bypassSinks2);
139
+ }
140
+ }
141
+ }
142
+ log(level, message, properties, bypassSinks) {
143
+ let cachedProps = undefined;
144
+ const record = typeof properties === "function"
145
+ ? {
146
+ category: this.category,
147
+ level,
148
+ timestamp: Date.now(),
149
+ get message() {
150
+ return parseMessageTemplate(message, this.properties);
151
+ },
152
+ get properties() {
153
+ if (cachedProps == null)
154
+ cachedProps = properties();
155
+ return cachedProps;
156
+ },
157
+ }
158
+ : {
159
+ category: this.category,
160
+ level,
161
+ timestamp: Date.now(),
162
+ message: parseMessageTemplate(message, properties),
163
+ properties,
164
+ };
165
+ this.emit(record, bypassSinks);
166
+ }
167
+ logLazily(level, callback) {
168
+ let msg = undefined;
169
+ this.emit({
170
+ category: this.category,
171
+ level,
172
+ get message() {
173
+ if (msg == null) {
174
+ msg = callback((tpl, ...values) => renderMessage(tpl, values));
175
+ }
176
+ return msg;
177
+ },
178
+ timestamp: Date.now(),
179
+ properties: {},
180
+ });
181
+ }
182
+ logTemplate(level, messageTemplate, values) {
183
+ this.emit({
184
+ category: this.category,
185
+ level,
186
+ message: renderMessage(messageTemplate, values),
187
+ timestamp: Date.now(),
188
+ properties: {},
189
+ });
190
+ }
191
+ debug(message, ...values) {
192
+ if (typeof message === "string") {
193
+ this.log("debug", message, (values[0] ?? {}));
194
+ }
195
+ else if (typeof message === "function") {
196
+ this.logLazily("debug", message);
197
+ }
198
+ else {
199
+ this.logTemplate("debug", message, values);
200
+ }
201
+ }
202
+ info(message, ...values) {
203
+ if (typeof message === "string") {
204
+ this.log("info", message, (values[0] ?? {}));
205
+ }
206
+ else if (typeof message === "function") {
207
+ this.logLazily("info", message);
208
+ }
209
+ else {
210
+ this.logTemplate("info", message, values);
211
+ }
212
+ }
213
+ warn(message, ...values) {
214
+ if (typeof message === "string") {
215
+ this.log("warning", message, (values[0] ?? {}));
216
+ }
217
+ else if (typeof message === "function") {
218
+ this.logLazily("warning", message);
219
+ }
220
+ else {
221
+ this.logTemplate("warning", message, values);
222
+ }
223
+ }
224
+ error(message, ...values) {
225
+ if (typeof message === "string") {
226
+ this.log("error", message, (values[0] ?? {}));
227
+ }
228
+ else if (typeof message === "function") {
229
+ this.logLazily("error", message);
230
+ }
231
+ else {
232
+ this.logTemplate("error", message, values);
233
+ }
234
+ }
235
+ fatal(message, ...values) {
236
+ if (typeof message === "string") {
237
+ this.log("fatal", message, (values[0] ?? {}));
238
+ }
239
+ else if (typeof message === "function") {
240
+ this.logLazily("fatal", message);
241
+ }
242
+ else {
243
+ this.logTemplate("fatal", message, values);
244
+ }
245
+ }
246
+ }
247
+ exports.LoggerImpl = LoggerImpl;
248
+ /**
249
+ * The meta logger. It is a logger with the category `["logtape", "meta"]`.
250
+ */
251
+ const metaLogger = LoggerImpl.getLogger(["logtape", "meta"]);
252
+ const MESSAGE_TEMPLATE_PATTERN = /\{([^}]*)\}/g;
253
+ /**
254
+ * Parse a message template into a message template array and a values array.
255
+ * @param template The message template.
256
+ * @param properties The values to replace placeholders with.
257
+ * @returns The message template array and the values array.
258
+ */
259
+ function parseMessageTemplate(template, properties) {
260
+ let lastPos = 0;
261
+ const message = [];
262
+ while (true) {
263
+ const match = MESSAGE_TEMPLATE_PATTERN.exec(template);
264
+ if (match == null) {
265
+ message.push(template.substring(lastPos));
266
+ break;
267
+ }
268
+ message.push(template.substring(lastPos, match.index));
269
+ const key = match[1];
270
+ message.push(properties[key]);
271
+ lastPos = match.index + match[0].length;
272
+ }
273
+ return message;
274
+ }
275
+ exports.parseMessageTemplate = parseMessageTemplate;
276
+ /**
277
+ * Render a message template with values.
278
+ * @param template The message template.
279
+ * @param values The message template values.
280
+ * @returns The message template values interleaved between the substitution
281
+ * values.
282
+ */
283
+ function renderMessage(template, values) {
284
+ const args = [];
285
+ for (let i = 0; i < template.length; i++) {
286
+ args.push(template[i]);
287
+ if (i < values.length)
288
+ args.push(values[i]);
289
+ }
290
+ return args;
291
+ }
292
+ exports.renderMessage = renderMessage;
package/script/mod.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConsoleSink = exports.getLogger = exports.defaultConsoleFormatter = exports.toFilter = exports.getLevelFilter = exports.configure = exports.ConfigError = void 0;
4
+ var config_js_1 = require("./config.js");
5
+ Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_js_1.ConfigError; } });
6
+ Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return config_js_1.configure; } });
7
+ var filter_js_1 = require("./filter.js");
8
+ Object.defineProperty(exports, "getLevelFilter", { enumerable: true, get: function () { return filter_js_1.getLevelFilter; } });
9
+ Object.defineProperty(exports, "toFilter", { enumerable: true, get: function () { return filter_js_1.toFilter; } });
10
+ var formatter_js_1 = require("./formatter.js");
11
+ Object.defineProperty(exports, "defaultConsoleFormatter", { enumerable: true, get: function () { return formatter_js_1.defaultConsoleFormatter; } });
12
+ var logger_js_1 = require("./logger.js");
13
+ Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_js_1.getLogger; } });
14
+ var sink_js_1 = require("./sink.js");
15
+ Object.defineProperty(exports, "getConsoleSink", { enumerable: true, get: function () { return sink_js_1.getConsoleSink; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/script/sink.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConsoleSink = exports.getStreamSink = void 0;
4
+ const formatter_js_1 = require("./formatter.js");
5
+ /**
6
+ * A factory that returns a sink that writes to a {@link WritableStream}.
7
+ *
8
+ * Note that the `stream` is of Web Streams API, which is different from
9
+ * Node.js streams. You can convert a Node.js stream to a Web Streams API
10
+ * stream using [`stream.Writable.toWeb()`] method.
11
+ *
12
+ * [`stream.Writable.toWeb()`]: https://nodejs.org/api/stream.html#streamwritabletowebstreamwritable
13
+ *
14
+ * @example Sink to the standard error in Deno
15
+ * ```typescript
16
+ * const stderrSink = getStreamSink(Deno.stderr.writable);
17
+ * ```
18
+ *
19
+ * @example Sink to the standard error in Node.js
20
+ * ```typescript
21
+ * import stream from "node:stream";
22
+ * const stderrSink = getStreamSink(stream.Writable.toWeb(process.stderr));
23
+ * ```
24
+ *
25
+ * @param stream The stream to write to.
26
+ * @param formatter The text formatter to use. Defaults to
27
+ * {@link defaultTextFormatter}.
28
+ * @param encoder The text encoder to use. Defaults to an instance of
29
+ * {@link TextEncoder}.
30
+ * @returns A sink that writes to the stream.
31
+ */
32
+ function getStreamSink(stream, formatter = formatter_js_1.defaultTextFormatter, encoder = new TextEncoder()) {
33
+ const writer = stream.getWriter();
34
+ return (record) => {
35
+ const bytes = encoder.encode(formatter(record));
36
+ writer.ready.then(() => writer.write(bytes));
37
+ };
38
+ }
39
+ exports.getStreamSink = getStreamSink;
40
+ /**
41
+ * A console sink factory that returns a sink that logs to the console.
42
+ *
43
+ * @param formatter A console formatter. Defaults to
44
+ * {@link defaultConsoleFormatter}.
45
+ * @param console The console to log to. Defaults to {@link console}.
46
+ * @returns A sink that logs to the console.
47
+ */
48
+ function getConsoleSink(formatter = formatter_js_1.defaultConsoleFormatter, console = globalThis.console) {
49
+ return (record) => {
50
+ const args = formatter(record);
51
+ if (record.level === "debug")
52
+ console.debug(...args);
53
+ else if (record.level === "info")
54
+ console.info(...args);
55
+ else if (record.level === "warning")
56
+ console.warn(...args);
57
+ else if (record.level === "error" || record.level === "fatal") {
58
+ console.error(...args);
59
+ }
60
+ else
61
+ throw new TypeError(`Invalid log level: ${record.level}.`);
62
+ };
63
+ }
64
+ exports.getConsoleSink = getConsoleSink;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import { WritableStream } from "node:stream/web";
3
+ export { WritableStream } from "node:stream/web";
4
+ export declare const dntGlobalThis: Omit<typeof globalThis, "WritableStream"> & {
5
+ WritableStream: {
6
+ new <W = any>(underlyingSink?: import("stream/web").UnderlyingSink<W> | undefined, strategy?: import("stream/web").QueuingStrategy<W> | undefined): WritableStream<W>;
7
+ prototype: WritableStream<any>;
8
+ };
9
+ };
10
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKjD,eAAO,MAAM,aAAa;;;;;CAA2C,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.test_shims.d.ts","sourceRoot":"","sources":["../src/_dnt.test_shims.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMjD,eAAO,MAAM,aAAa;;;;;;CAA2C,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { type FilterLike } from "./filter.js";
2
+ import type { LogLevel } from "./record.js";
3
+ import { type Sink } from "./sink.js";
4
+ /**
5
+ * A configuration for the loggers.
6
+ */
7
+ export interface Config<TSinkId extends string, TFilterId extends string> {
8
+ /**
9
+ * The sinks to use. The keys are the sink identifiers, and the values are
10
+ * {@link Sink}s.
11
+ */
12
+ sinks: Record<TSinkId, Sink>;
13
+ /**
14
+ * The filters to use. The keys are the filter identifiers, and the values
15
+ * are either {@link Filter}s or {@link LogLevel}s.
16
+ */
17
+ filters: Record<TFilterId, FilterLike>;
18
+ /**
19
+ * The loggers to configure.
20
+ */
21
+ loggers: LoggerConfig<TSinkId, TFilterId>[];
22
+ /**
23
+ * Whether to reset the configuration before applying this one.
24
+ */
25
+ reset?: boolean;
26
+ }
27
+ /**
28
+ * A logger configuration.
29
+ */
30
+ export interface LoggerConfig<TSinkId extends string, TFilterId extends string> {
31
+ /**
32
+ * The category of the logger. If a string, it is equivalent to an array
33
+ * with one element.
34
+ */
35
+ category: string | string[];
36
+ /**
37
+ * The sink identifiers to use.
38
+ */
39
+ sinks?: TSinkId[];
40
+ /**
41
+ * The filter identifiers to use.
42
+ */
43
+ filters?: TFilterId[];
44
+ /**
45
+ * The log level to filter by. If `null`, the logger will reject all
46
+ * records.
47
+ */
48
+ level?: LogLevel | null;
49
+ }
50
+ /**
51
+ * Configure the loggers with the specified configuration.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * configure({
56
+ * sinks: {
57
+ * console: getConsoleSink(),
58
+ * },
59
+ * filters: {
60
+ * slow: (log) =>
61
+ * "duration" in log.properties &&
62
+ * log.properties.duration as number > 1000,
63
+ * },
64
+ * loggers: [
65
+ * {
66
+ * category: "my-app",
67
+ * sinks: ["console"],
68
+ * level: "info",
69
+ * },
70
+ * {
71
+ * category: ["my-app", "sql"],
72
+ * filters: ["slow"],
73
+ * level: "debug",
74
+ * },
75
+ * {
76
+ * category: "logtape",
77
+ * sinks: ["console"],
78
+ * level: "error",
79
+ * },
80
+ * ],
81
+ * });
82
+ * ```
83
+ *
84
+ * @param config The configuration.
85
+ */
86
+ export declare function configure<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
87
+ /**
88
+ * Reset the configuration. Mostly for testing purposes.
89
+ */
90
+ export declare function reset(): void;
91
+ /**
92
+ * A configuration error.
93
+ */
94
+ export declare class ConfigError extends Error {
95
+ /**
96
+ * Constructs a new configuration error.
97
+ * @param message The error message.
98
+ */
99
+ constructor(message: string);
100
+ }
101
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,MAAM,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IACtE;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAEvC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IAE5C;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,OAAO,SAAS,MAAM,EACtB,SAAS,SAAS,MAAM;IAExB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CACzB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,SAAS,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM,EACxE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,QA0DnC;AAED;;GAEG;AACH,wBAAgB,KAAK,SAGpB;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../src/config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_constants.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_diff.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_diff.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,QAAQ,CAAC;AAE7C,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC;AA4BD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA+L5D;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,wBAsI3C;AAwCD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAC7C,EAAE,UAAkB,EAAE;;CAAK,GAC1B,MAAM,EAAE,CAyBV"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_format.ts"],"names":[],"mappings":"AAYA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAezC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,SAAK,GAAG,OAAO,CAAC,IAAI,CAI5D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_equals.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_equals.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,EACX,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;CAAO,QAuBzD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_false.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_false.ts"],"names":[],"mappings":"AAIA,uDAAuD;AACvD,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,SAAK,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,CAI1E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_greater_or_equal.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_greater_or_equal.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,EACX,GAAG,CAAC,EAAE,MAAM,QASb"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_is_error.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_is_error.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EACnD,KAAK,EAAE,OAAO,EAEd,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACtC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAC5B,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,CAmCpB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_less_or_equal.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_less_or_equal.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,EACX,GAAG,CAAC,EAAE,MAAM,QASb"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_strict_equals.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_strict_equals.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,CAAC,EACX,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,IAAI,CAAC,CAmCrB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_throws.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_throws.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;AACX;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAClD,EAAE,EAAE,MAAM,OAAO,EAEjB,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACrC,WAAW,CAAC,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertion_error.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assertion_error.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,iCAAiC;gBACrB,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equal.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/equal.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CA8FrD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/0.222.1/delay.ts"],"names":[],"mappings":";AAMA,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0B3E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/fmt/0.222.1/colors.ts"],"names":[],"mappings":"AAkEA,qEAAqE;AACrE,MAAM,WAAW,GAAG;IAClB,0BAA0B;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,4BAA4B;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,2BAA2B;IAC3B,CAAC,EAAE,MAAM,CAAC;CACX;AAID;;;GAGG;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