@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,30 @@
1
+ import type { LogLevel, LogRecord } from "./record.js";
2
+ /**
3
+ * A filter is a function that accepts a log record and returns `true` if the
4
+ * record should be passed to the sink.
5
+ *
6
+ * @param record The log record to filter.
7
+ * @returns `true` if the record should be passed to the sink.
8
+ */
9
+ export type Filter = (record: LogRecord) => boolean;
10
+ /**
11
+ * A filter-like value is either a {@link Filter} or a {@link LogLevel}.
12
+ * `null` is also allowed to represent a filter that rejects all records.
13
+ */
14
+ export type FilterLike = Filter | LogLevel | null;
15
+ /**
16
+ * Converts a {@link FilterLike} value to an actual {@link Filter}.
17
+ *
18
+ * @param filter The filter-like value to convert.
19
+ * @returns The actual filter.
20
+ */
21
+ export declare function toFilter(filter: FilterLike): Filter;
22
+ /**
23
+ * Returns a filter that accepts log records with the specified level.
24
+ *
25
+ * @param level The level to filter by. If `null`, the filter will reject all
26
+ * records.
27
+ * @returns The filter.
28
+ */
29
+ export declare function getLevelFilter(level: LogLevel | null): Filter;
30
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAGnD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,CAoB7D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.test.d.ts","sourceRoot":"","sources":["../src/filter.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,eAAO,MAAM,IAAI,EAAE,SAMlB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,SAGnB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,SAGrB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,SAGnB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,SAGnB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { LogRecord } from "./record.js";
2
+ /**
3
+ * A text formatter is a function that accepts a log record and returns
4
+ * a string.
5
+ *
6
+ * @param record The log record to format.
7
+ * @returns The formatted log record.
8
+ */
9
+ export type TextFormatter = (record: LogRecord) => string;
10
+ /**
11
+ * The default text formatter. This formatter formats log records as follows:
12
+ *
13
+ * ```
14
+ * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
15
+ * ```
16
+ *
17
+ * @param record The log record to format.
18
+ * @returns The formatted log record.
19
+ */
20
+ export declare function defaultTextFormatter(record: LogRecord): string;
21
+ /**
22
+ * A console formatter is a function that accepts a log record and returns
23
+ * an array of arguments to pass to {@link console.log}.
24
+ *
25
+ * @param record The log record to format.
26
+ * @returns The formatted log record, as an array of arguments for
27
+ * {@link console.log}.
28
+ */
29
+ export type ConsoleFormatter = (record: LogRecord) => readonly unknown[];
30
+ /**
31
+ * The default console formatter.
32
+ *
33
+ * @param record The log record to format.
34
+ * @returns The formatted log record, as an array of arguments for
35
+ * {@link console.log}.
36
+ */
37
+ export declare function defaultConsoleFormatter(record: LogRecord): readonly unknown[];
38
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAC;AA+B1D;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAW9D;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,SAAS,OAAO,EAAE,CAAC;AAazE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,OAAO,EAAE,CAoB7E"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.test.d.ts","sourceRoot":"","sources":["../src/formatter.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,363 @@
1
+ import type { Filter } from "./filter.js";
2
+ import type { LogLevel, LogRecord } from "./record.js";
3
+ import type { Sink } from "./sink.js";
4
+ /**
5
+ * A logger interface. It provides methods to log messages at different
6
+ * severity levels.
7
+ *
8
+ * ```typescript
9
+ * const logger = getLogger("category");
10
+ * logger.debug `A debug message with ${value}.`;
11
+ * logger.info `An info message with ${value}.`;
12
+ * logger.warn `A warning message with ${value}.`;
13
+ * logger.error `An error message with ${value}.`;
14
+ * logger.fatal `A fatal error message with ${value}.`;
15
+ * ```
16
+ */
17
+ export interface Logger {
18
+ /**
19
+ * The category of the logger. It is an array of strings.
20
+ */
21
+ readonly category: readonly string[];
22
+ /**
23
+ * The logger with the supercategory of the current logger. If the current
24
+ * logger is the root logger, this is `null`.
25
+ */
26
+ readonly parent: Logger | null;
27
+ /**
28
+ * Get a child logger with the given subcategory.
29
+ *
30
+ * ```typescript
31
+ * const logger = getLogger("category");
32
+ * const subLogger = logger.getChild("sub-category");
33
+ * ```
34
+ *
35
+ * The above code is equivalent to:
36
+ *
37
+ * ```typescript
38
+ * const logger = getLogger("category");
39
+ * const subLogger = getLogger(["category", "sub-category"]);
40
+ * ```
41
+ *
42
+ * @param subcategory The subcategory.
43
+ * @returns The child logger.
44
+ */
45
+ getChild(subcategory: string | readonly [string] | readonly [string, ...string[]]): Logger;
46
+ /**
47
+ * Log a debug message. Use this as a template string prefix.
48
+ *
49
+ * ```typescript
50
+ * logger.debug `A debug message with ${value}.`;
51
+ * ```
52
+ *
53
+ * @param message The message template strings array.
54
+ * @param values The message template values.
55
+ */
56
+ debug(message: TemplateStringsArray, ...values: readonly unknown[]): void;
57
+ /**
58
+ * Log a debug message with properties.
59
+ *
60
+ * ```typescript
61
+ * logger.debug('A debug message with {value}.', { value });
62
+ * ```
63
+ *
64
+ * If the properties are expensive to compute, you can pass a callback that
65
+ * returns the properties:
66
+ *
67
+ * ```typescript
68
+ * logger.debug(
69
+ * 'A debug message with {value}.',
70
+ * () => ({ value: expensiveComputation() })
71
+ * );
72
+ * ```
73
+ *
74
+ * @param message The message template. Placeholders to be replaced with
75
+ * `values` are indicated by keys in curly braces (e.g.,
76
+ * `{value}`).
77
+ * @param properties The values to replace placeholders with. For lazy
78
+ * evaluation, this can be a callback that returns the
79
+ * properties.
80
+ */
81
+ debug(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
82
+ /**
83
+ * Lazily log a debug message. Use this when the message values are expensive
84
+ * to compute and should only be computed if the message is actually logged.
85
+ *
86
+ * ```typescript
87
+ * logger.debug(l => l`A debug message with ${expensiveValue()}.`);
88
+ * ```
89
+ *
90
+ * @param callback A callback that returns the message template prefix.
91
+ */
92
+ debug(callback: LogCallback): void;
93
+ /**
94
+ * Log an informational message. Use this as a template string prefix.
95
+ *
96
+ * ```typescript
97
+ * logger.info `An info message with ${value}.`;
98
+ * ```
99
+ *
100
+ * @param message The message template strings array.
101
+ * @param values The message template values.
102
+ */
103
+ info(message: TemplateStringsArray, ...values: readonly unknown[]): void;
104
+ /**
105
+ * Log an informational message with properties.
106
+ *
107
+ * ```typescript
108
+ * logger.info('An info message with {value}.', { value });
109
+ * ```
110
+ *
111
+ * If the properties are expensive to compute, you can pass a callback that
112
+ * returns the properties:
113
+ *
114
+ * ```typescript
115
+ * logger.info(
116
+ * 'An info message with {value}.',
117
+ * () => ({ value: expensiveComputation() })
118
+ * );
119
+ * ```
120
+ *
121
+ * @param message The message template. Placeholders to be replaced with
122
+ * `values` are indicated by keys in curly braces (e.g.,
123
+ * `{value}`).
124
+ * @param properties The values to replace placeholders with. For lazy
125
+ * evaluation, this can be a callback that returns the
126
+ * properties.
127
+ */
128
+ info(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
129
+ /**
130
+ * Lazily log an informational message. Use this when the message values are
131
+ * expensive to compute and should only be computed if the message is actually
132
+ * logged.
133
+ *
134
+ * ```typescript
135
+ * logger.info(l => l`An info message with ${expensiveValue()}.`);
136
+ * ```
137
+ *
138
+ * @param callback A callback that returns the message template prefix.
139
+ */
140
+ info(callback: LogCallback): void;
141
+ /**
142
+ * Log a warning message. Use this as a template string prefix.
143
+ *
144
+ * ```typescript
145
+ * logger.warn `A warning message with ${value}.`;
146
+ * ```
147
+ *
148
+ * @param message The message template strings array.
149
+ * @param values The message template values.
150
+ */
151
+ warn(message: TemplateStringsArray, ...values: readonly unknown[]): void;
152
+ /**
153
+ * Log a warning message with properties.
154
+ *
155
+ * ```typescript
156
+ * logger.warn('A warning message with {value}.', { value });
157
+ * ```
158
+ *
159
+ * If the properties are expensive to compute, you can pass a callback that
160
+ * returns the properties:
161
+ *
162
+ * ```typescript
163
+ * logger.warn(
164
+ * 'A warning message with {value}.',
165
+ * () => ({ value: expensiveComputation() })
166
+ * );
167
+ * ```
168
+ *
169
+ * @param message The message template. Placeholders to be replaced with
170
+ * `values` are indicated by keys in curly braces (e.g.,
171
+ * `{value}`).
172
+ * @param properties The values to replace placeholders with. For lazy
173
+ * evaluation, this can be a callback that returns the
174
+ * properties.
175
+ */
176
+ warn(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
177
+ /**
178
+ * Lazily log a warning message. Use this when the message values are
179
+ * expensive to compute and should only be computed if the message is actually
180
+ * logged.
181
+ *
182
+ * ```typescript
183
+ * logger.warn(l => l`A warning message with ${expensiveValue()}.`);
184
+ * ```
185
+ *
186
+ * @param callback A callback that returns the message template prefix.
187
+ */
188
+ warn(callback: LogCallback): void;
189
+ /**
190
+ * Log an error message. Use this as a template string prefix.
191
+ *
192
+ * ```typescript
193
+ * logger.error `An error message with ${value}.`;
194
+ * ```
195
+ *
196
+ * @param message The message template strings array.
197
+ * @param values The message template values.
198
+ */
199
+ error(message: TemplateStringsArray, ...values: readonly unknown[]): void;
200
+ /**
201
+ * Log an error message with properties.
202
+ *
203
+ * ```typescript
204
+ * logger.warn('An error message with {value}.', { value });
205
+ * ```
206
+ *
207
+ * If the properties are expensive to compute, you can pass a callback that
208
+ * returns the properties:
209
+ *
210
+ * ```typescript
211
+ * logger.error(
212
+ * 'An error message with {value}.',
213
+ * () => ({ value: expensiveComputation() })
214
+ * );
215
+ * ```
216
+ *
217
+ * @param message The message template. Placeholders to be replaced with
218
+ * `values` are indicated by keys in curly braces (e.g.,
219
+ * `{value}`).
220
+ * @param properties The values to replace placeholders with. For lazy
221
+ * evaluation, this can be a callback that returns the
222
+ * properties.
223
+ */
224
+ error(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
225
+ /**
226
+ * Lazily log an error message. Use this when the message values are
227
+ * expensive to compute and should only be computed if the message is actually
228
+ * logged.
229
+ *
230
+ * ```typescript
231
+ * logger.error(l => l`An error message with ${expensiveValue()}.`);
232
+ * ```
233
+ *
234
+ * @param callback A callback that returns the message template prefix.
235
+ */
236
+ error(callback: LogCallback): void;
237
+ /**
238
+ * Log a fatal error message. Use this as a template string prefix.
239
+ *
240
+ * ```typescript
241
+ * logger.fatal `A fatal error message with ${value}.`;
242
+ * ```
243
+ *
244
+ * @param message The message template strings array.
245
+ * @param values The message template values.
246
+ */
247
+ fatal(message: TemplateStringsArray, ...values: readonly unknown[]): void;
248
+ /**
249
+ * Log a fatal error message with properties.
250
+ *
251
+ * ```typescript
252
+ * logger.warn('A fatal error message with {value}.', { value });
253
+ * ```
254
+ *
255
+ * If the properties are expensive to compute, you can pass a callback that
256
+ * returns the properties:
257
+ *
258
+ * ```typescript
259
+ * logger.fatal(
260
+ * 'A fatal error message with {value}.',
261
+ * () => ({ value: expensiveComputation() })
262
+ * );
263
+ * ```
264
+ *
265
+ * @param message The message template. Placeholders to be replaced with
266
+ * `values` are indicated by keys in curly braces (e.g.,
267
+ * `{value}`).
268
+ * @param properties The values to replace placeholders with. For lazy
269
+ * evaluation, this can be a callback that returns the
270
+ * properties.
271
+ */
272
+ fatal(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
273
+ /**
274
+ * Lazily log a fatal error message. Use this when the message values are
275
+ * expensive to compute and should only be computed if the message is actually
276
+ * logged.
277
+ *
278
+ * ```typescript
279
+ * logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);
280
+ * ```
281
+ *
282
+ * @param callback A callback that returns the message template prefix.
283
+ */
284
+ fatal(callback: LogCallback): void;
285
+ }
286
+ /**
287
+ * A logging callback function. It is used to defer the computation of a
288
+ * message template until it is actually logged.
289
+ * @param prefix The message template prefix.
290
+ * @returns The rendered message array.
291
+ */
292
+ export type LogCallback = (prefix: LogTemplatePrefix) => unknown[];
293
+ /**
294
+ * A logging template prefix function. It is used to log a message in
295
+ * a {@link LogCallback} function.
296
+ * @param message The message template strings array.
297
+ * @param values The message template values.
298
+ * @returns The rendered message array.
299
+ */
300
+ export type LogTemplatePrefix = (message: TemplateStringsArray, ...values: unknown[]) => unknown[];
301
+ /**
302
+ * Get a logger with the given category.
303
+ *
304
+ * ```typescript
305
+ * const logger = getLogger(["my-app"]);
306
+ * ```
307
+ *
308
+ * @param category The category of the logger. It can be a string or an array
309
+ * of strings. If it is a string, it is equivalent to an array
310
+ * with a single element.
311
+ * @returns The logger.
312
+ */
313
+ export declare function getLogger(category?: string | readonly string[]): Logger;
314
+ /**
315
+ * A logger implementation. Do not use this directly; use {@link getLogger}
316
+ * instead. This class is exported for testing purposes.
317
+ */
318
+ export declare class LoggerImpl implements Logger {
319
+ readonly parent: LoggerImpl | null;
320
+ readonly children: Record<string, WeakRef<LoggerImpl>>;
321
+ readonly category: readonly string[];
322
+ readonly sinks: Sink[];
323
+ readonly filters: Filter[];
324
+ static getLogger(category?: string | readonly string[]): LoggerImpl;
325
+ private constructor();
326
+ getChild(subcategory: string | readonly [string] | readonly [string, ...readonly string[]]): LoggerImpl;
327
+ /**
328
+ * Reset the logger. This removes all sinks and filters from the logger.
329
+ */
330
+ reset(): void;
331
+ /**
332
+ * Reset the logger and all its descendants. This removes all sinks and
333
+ * filters from the logger and all its descendants.
334
+ */
335
+ resetDescendants(): void;
336
+ filter(record: LogRecord): boolean;
337
+ getSinks(): Iterable<Sink>;
338
+ emit(record: LogRecord, bypassSinks?: Set<Sink>): void;
339
+ log(level: LogLevel, message: string, properties: Record<string, unknown> | (() => Record<string, unknown>), bypassSinks?: Set<Sink>): void;
340
+ logLazily(level: LogLevel, callback: LogCallback): void;
341
+ logTemplate(level: LogLevel, messageTemplate: TemplateStringsArray, values: unknown[]): void;
342
+ debug(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
343
+ info(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
344
+ warn(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
345
+ error(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
346
+ fatal(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
347
+ }
348
+ /**
349
+ * Parse a message template into a message template array and a values array.
350
+ * @param template The message template.
351
+ * @param properties The values to replace placeholders with.
352
+ * @returns The message template array and the values array.
353
+ */
354
+ export declare function parseMessageTemplate(template: string, properties: Record<string, unknown>): readonly unknown[];
355
+ /**
356
+ * Render a message template with values.
357
+ * @param template The message template.
358
+ * @param values The message template values.
359
+ * @returns The message template values interleaved between the substitution
360
+ * values.
361
+ */
362
+ export declare function renderMessage(template: TemplateStringsArray, values: readonly unknown[]): unknown[];
363
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAErC;;;OAGG;IACH,QAAQ,C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KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,WAAW,GACpB,IAAI;IAgBP,WAAW,CACT,KAAK,EAAE,QAAQ,EACf,eAAe,EAAE,oBAAoB,EACrC,MAAM,EAAE,OAAO,EAAE,GAChB,IAAI;IAUP,KAAK,CACH,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,WAAW,EACpD,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,IAAI;IAUP,IAAI,CACF,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,WAAW,EACpD,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,IAAI;IAUP,IAAI,CACF,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,WAAW,EACpD,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,IAAI;IAcP,KAAK,CACH,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,WAAW,EACpD,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,IAAI;IAUP,KAAK,CACH,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,WAAW,EACpD,GAAG,MAAM,EAAE,OAAO,EAAE,GACnB,IAAI;CASR;AASD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,SAAS,OAAO,EAAE,CAepB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,SAAS,OAAO,EAAE,GACzB,OAAO,EAAE,CAOX"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.test.d.ts","sourceRoot":"","sources":["../src/logger.test.ts"],"names":[],"mappings":""}
package/types/mod.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { type Config, ConfigError, configure, type LoggerConfig, } from "./config.js";
2
+ export { type Filter, type FilterLike, getLevelFilter, toFilter, } from "./filter.js";
3
+ export { type ConsoleFormatter, defaultConsoleFormatter, type TextFormatter, } from "./formatter.js";
4
+ export { getLogger, type Logger } from "./logger.js";
5
+ export type { LogLevel, LogRecord } from "./record.js";
6
+ export { getConsoleSink, type Sink } from "./sink.js";
7
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,WAAW,EACX,SAAS,EACT,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The severity level of a {@link LogRecord}.
3
+ */
4
+ export type LogLevel = "debug" | "info" | "warning" | "error" | "fatal";
5
+ /**
6
+ * A log record.
7
+ */
8
+ export interface LogRecord {
9
+ /**
10
+ * The category of the logger that produced the log record.
11
+ */
12
+ readonly category: readonly string[];
13
+ /**
14
+ * The log level.
15
+ */
16
+ readonly level: LogLevel;
17
+ /**
18
+ * The log message. This is the result of substituting the message template
19
+ * with the values. The number of elements in this array is always odd,
20
+ * with the message template values interleaved between the substitution
21
+ * values.
22
+ */
23
+ readonly message: readonly unknown[];
24
+ /**
25
+ * The timestamp of the log record in milliseconds since the Unix epoch.
26
+ */
27
+ readonly timestamp: number;
28
+ /**
29
+ * The extra properties of the log record.
30
+ */
31
+ readonly properties: Record<string, unknown>;
32
+ }
33
+ //# sourceMappingURL=record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C"}
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import * as dntShim from "./_dnt.shims.js";
4
+ import { type ConsoleFormatter, type TextFormatter } from "./formatter.js";
5
+ import type { LogRecord } from "./record.js";
6
+ /**
7
+ * A sink is a function that accepts a log record and prints it somewhere.
8
+ * Thrown exceptions will be suppressed and then logged to the meta logger,
9
+ * a {@link Logger} with the category `["logtape", "meta"]`. (In that case,
10
+ * the meta log record will not be passed to the sink to avoid infinite
11
+ * recursion.)
12
+ *
13
+ * @param record The log record to sink.
14
+ */
15
+ export type Sink = (record: LogRecord) => void;
16
+ /**
17
+ * A factory that returns a sink that writes to a {@link WritableStream}.
18
+ *
19
+ * Note that the `stream` is of Web Streams API, which is different from
20
+ * Node.js streams. You can convert a Node.js stream to a Web Streams API
21
+ * stream using [`stream.Writable.toWeb()`] method.
22
+ *
23
+ * [`stream.Writable.toWeb()`]: https://nodejs.org/api/stream.html#streamwritabletowebstreamwritable
24
+ *
25
+ * @example Sink to the standard error in Deno
26
+ * ```typescript
27
+ * const stderrSink = getStreamSink(Deno.stderr.writable);
28
+ * ```
29
+ *
30
+ * @example Sink to the standard error in Node.js
31
+ * ```typescript
32
+ * import stream from "node:stream";
33
+ * const stderrSink = getStreamSink(stream.Writable.toWeb(process.stderr));
34
+ * ```
35
+ *
36
+ * @param stream The stream to write to.
37
+ * @param formatter The text formatter to use. Defaults to
38
+ * {@link defaultTextFormatter}.
39
+ * @param encoder The text encoder to use. Defaults to an instance of
40
+ * {@link TextEncoder}.
41
+ * @returns A sink that writes to the stream.
42
+ */
43
+ export declare function getStreamSink(stream: dntShim.WritableStream, formatter?: TextFormatter, encoder?: {
44
+ encode(text: string): Uint8Array;
45
+ }): Sink;
46
+ /**
47
+ * A console sink factory that returns a sink that logs to the console.
48
+ *
49
+ * @param formatter A console formatter. Defaults to
50
+ * {@link defaultConsoleFormatter}.
51
+ * @param console The console to log to. Defaults to {@link console}.
52
+ * @returns A sink that logs to the console.
53
+ */
54
+ export declare function getConsoleSink(formatter?: ConsoleFormatter, console?: Console): Sink;
55
+ //# sourceMappingURL=sink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../src/sink.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,KAAK,gBAAgB,EAGrB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,CAAC,cAAc,EAC9B,SAAS,GAAE,aAAoC,EAC/C,OAAO,GAAE;IAAE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;CAAsB,GAChE,IAAI,CAMN;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,SAAS,GAAE,gBAA0C,EACrD,OAAO,GAAE,OAA4B,GACpC,IAAI,CAUN"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink.test.d.ts","sourceRoot":"","sources":["../src/sink.test.ts"],"names":[],"mappings":""}