@logtape/file 0.9.0-dev.1
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/LICENSE +20 -0
- package/README.md +43 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/file/filesink.base.js +78 -0
- package/esm/file/filesink.node.js +47 -0
- package/esm/file/mod.js +1 -0
- package/esm/logtape/config.js +287 -0
- package/esm/logtape/context.js +23 -0
- package/esm/logtape/filter.js +42 -0
- package/esm/logtape/formatter.js +261 -0
- package/esm/logtape/level.js +59 -0
- package/esm/logtape/logger.js +480 -0
- package/esm/logtape/mod.js +8 -0
- package/esm/logtape/nodeUtil.js +2 -0
- package/esm/logtape/record.js +1 -0
- package/esm/logtape/sink.js +96 -0
- package/esm/package.json +3 -0
- package/package.json +55 -0
- package/script/_dnt.shims.js +60 -0
- package/script/file/filesink.base.js +82 -0
- package/script/file/filesink.node.js +55 -0
- package/script/file/mod.js +6 -0
- package/script/logtape/config.js +321 -0
- package/script/logtape/context.js +26 -0
- package/script/logtape/filter.js +46 -0
- package/script/logtape/formatter.js +270 -0
- package/script/logtape/level.js +64 -0
- package/script/logtape/logger.js +511 -0
- package/script/logtape/mod.js +34 -0
- package/script/logtape/nodeUtil.js +7 -0
- package/script/logtape/record.js +2 -0
- package/script/logtape/sink.js +101 -0
- package/script/package.json +3 -0
- package/types/_dnt.shims.d.ts +2 -0
- package/types/_dnt.shims.d.ts.map +1 -0
- package/types/_dnt.test_shims.d.ts.map +1 -0
- package/types/deps/jsr.io/@david/which-runtime/0.2.1/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_constants.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_diff.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_format.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/assertion_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/fmt/0.222.1/colors.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/assert_path.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/constants.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/normalize.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/normalize_string.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_os.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/_util.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/normalize.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/_util.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/normalize.d.ts.map +1 -0
- package/types/file/filesink.base.d.ts +89 -0
- package/types/file/filesink.base.d.ts.map +1 -0
- package/types/file/filesink.node.d.ts +34 -0
- package/types/file/filesink.node.d.ts.map +1 -0
- package/types/file/filesink.test.d.ts.map +1 -0
- package/types/file/mod.d.ts +3 -0
- package/types/file/mod.d.ts.map +1 -0
- package/types/logtape/config.d.ts +183 -0
- package/types/logtape/config.d.ts.map +1 -0
- package/types/logtape/context.d.ts +35 -0
- package/types/logtape/context.d.ts.map +1 -0
- package/types/logtape/filter.d.ts +31 -0
- package/types/logtape/filter.d.ts.map +1 -0
- package/types/logtape/fixtures.d.ts.map +1 -0
- package/types/logtape/formatter.d.ts +260 -0
- package/types/logtape/formatter.d.ts.map +1 -0
- package/types/logtape/level.d.ts +32 -0
- package/types/logtape/level.d.ts.map +1 -0
- package/types/logtape/logger.d.ts +423 -0
- package/types/logtape/logger.d.ts.map +1 -0
- package/types/logtape/mod.d.ts +9 -0
- package/types/logtape/mod.d.ts.map +1 -0
- package/types/logtape/nodeUtil.d.ts +3 -0
- package/types/logtape/nodeUtil.d.ts.map +1 -0
- package/types/logtape/record.d.ts +44 -0
- package/types/logtape/record.d.ts.map +1 -0
- package/types/logtape/sink.d.ts +108 -0
- package/types/logtape/sink.d.ts.map +1 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import type { ContextLocalStorage } from "./context.js";
|
|
2
|
+
import type { Filter } from "./filter.js";
|
|
3
|
+
import { type LogLevel } from "./level.js";
|
|
4
|
+
import type { LogRecord } from "./record.js";
|
|
5
|
+
import type { Sink } from "./sink.js";
|
|
6
|
+
/**
|
|
7
|
+
* A logger interface. It provides methods to log messages at different
|
|
8
|
+
* severity levels.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const logger = getLogger("category");
|
|
12
|
+
* logger.debug `A debug message with ${value}.`;
|
|
13
|
+
* logger.info `An info message with ${value}.`;
|
|
14
|
+
* logger.warn `A warning message with ${value}.`;
|
|
15
|
+
* logger.error `An error message with ${value}.`;
|
|
16
|
+
* logger.fatal `A fatal error message with ${value}.`;
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface Logger {
|
|
20
|
+
/**
|
|
21
|
+
* The category of the logger. It is an array of strings.
|
|
22
|
+
*/
|
|
23
|
+
readonly category: readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* The logger with the supercategory of the current logger. If the current
|
|
26
|
+
* logger is the root logger, this is `null`.
|
|
27
|
+
*/
|
|
28
|
+
readonly parent: Logger | null;
|
|
29
|
+
/**
|
|
30
|
+
* Get a child logger with the given subcategory.
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const logger = getLogger("category");
|
|
34
|
+
* const subLogger = logger.getChild("sub-category");
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* The above code is equivalent to:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const logger = getLogger("category");
|
|
41
|
+
* const subLogger = getLogger(["category", "sub-category"]);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param subcategory The subcategory.
|
|
45
|
+
* @returns The child logger.
|
|
46
|
+
*/
|
|
47
|
+
getChild(subcategory: string | readonly [string] | readonly [string, ...string[]]): Logger;
|
|
48
|
+
/**
|
|
49
|
+
* Get a logger with contextual properties. This is useful for
|
|
50
|
+
* log multiple messages with the shared set of properties.
|
|
51
|
+
*
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const logger = getLogger("category");
|
|
54
|
+
* const ctx = logger.with({ foo: 123, bar: "abc" });
|
|
55
|
+
* ctx.info("A message with {foo} and {bar}.");
|
|
56
|
+
* ctx.warn("Another message with {foo}, {bar}, and {baz}.", { baz: true });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* The above code is equivalent to:
|
|
60
|
+
*
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const logger = getLogger("category");
|
|
63
|
+
* logger.info("A message with {foo} and {bar}.", { foo: 123, bar: "abc" });
|
|
64
|
+
* logger.warn(
|
|
65
|
+
* "Another message with {foo}, {bar}, and {baz}.",
|
|
66
|
+
* { foo: 123, bar: "abc", baz: true },
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param properties
|
|
71
|
+
* @returns
|
|
72
|
+
* @since 0.5.0
|
|
73
|
+
*/
|
|
74
|
+
with(properties: Record<string, unknown>): Logger;
|
|
75
|
+
/**
|
|
76
|
+
* Log a debug message. Use this as a template string prefix.
|
|
77
|
+
*
|
|
78
|
+
* ```typescript
|
|
79
|
+
* logger.debug `A debug message with ${value}.`;
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param message The message template strings array.
|
|
83
|
+
* @param values The message template values.
|
|
84
|
+
*/
|
|
85
|
+
debug(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Log a debug message with properties.
|
|
88
|
+
*
|
|
89
|
+
* ```typescript
|
|
90
|
+
* logger.debug('A debug message with {value}.', { value });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
94
|
+
* returns the properties:
|
|
95
|
+
*
|
|
96
|
+
* ```typescript
|
|
97
|
+
* logger.debug(
|
|
98
|
+
* 'A debug message with {value}.',
|
|
99
|
+
* () => ({ value: expensiveComputation() })
|
|
100
|
+
* );
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param message The message template. Placeholders to be replaced with
|
|
104
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
105
|
+
* `{value}`).
|
|
106
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
107
|
+
* evaluation, this can be a callback that returns the
|
|
108
|
+
* properties.
|
|
109
|
+
*/
|
|
110
|
+
debug(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
111
|
+
/**
|
|
112
|
+
* Lazily log a debug message. Use this when the message values are expensive
|
|
113
|
+
* to compute and should only be computed if the message is actually logged.
|
|
114
|
+
*
|
|
115
|
+
* ```typescript
|
|
116
|
+
* logger.debug(l => l`A debug message with ${expensiveValue()}.`);
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @param callback A callback that returns the message template prefix.
|
|
120
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
121
|
+
*/
|
|
122
|
+
debug(callback: LogCallback): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log an informational message. Use this as a template string prefix.
|
|
125
|
+
*
|
|
126
|
+
* ```typescript
|
|
127
|
+
* logger.info `An info message with ${value}.`;
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @param message The message template strings array.
|
|
131
|
+
* @param values The message template values.
|
|
132
|
+
*/
|
|
133
|
+
info(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Log an informational message with properties.
|
|
136
|
+
*
|
|
137
|
+
* ```typescript
|
|
138
|
+
* logger.info('An info message with {value}.', { value });
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
142
|
+
* returns the properties:
|
|
143
|
+
*
|
|
144
|
+
* ```typescript
|
|
145
|
+
* logger.info(
|
|
146
|
+
* 'An info message with {value}.',
|
|
147
|
+
* () => ({ value: expensiveComputation() })
|
|
148
|
+
* );
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @param message The message template. Placeholders to be replaced with
|
|
152
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
153
|
+
* `{value}`).
|
|
154
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
155
|
+
* evaluation, this can be a callback that returns the
|
|
156
|
+
* properties.
|
|
157
|
+
*/
|
|
158
|
+
info(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
159
|
+
/**
|
|
160
|
+
* Lazily log an informational message. Use this when the message values are
|
|
161
|
+
* expensive to compute and should only be computed if the message is actually
|
|
162
|
+
* logged.
|
|
163
|
+
*
|
|
164
|
+
* ```typescript
|
|
165
|
+
* logger.info(l => l`An info message with ${expensiveValue()}.`);
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @param callback A callback that returns the message template prefix.
|
|
169
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
170
|
+
*/
|
|
171
|
+
info(callback: LogCallback): void;
|
|
172
|
+
/**
|
|
173
|
+
* Log a warning message. Use this as a template string prefix.
|
|
174
|
+
*
|
|
175
|
+
* ```typescript
|
|
176
|
+
* logger.warn `A warning message with ${value}.`;
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @param message The message template strings array.
|
|
180
|
+
* @param values The message template values.
|
|
181
|
+
*/
|
|
182
|
+
warn(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
183
|
+
/**
|
|
184
|
+
* Log a warning message with properties.
|
|
185
|
+
*
|
|
186
|
+
* ```typescript
|
|
187
|
+
* logger.warn('A warning message with {value}.', { value });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
191
|
+
* returns the properties:
|
|
192
|
+
*
|
|
193
|
+
* ```typescript
|
|
194
|
+
* logger.warn(
|
|
195
|
+
* 'A warning message with {value}.',
|
|
196
|
+
* () => ({ value: expensiveComputation() })
|
|
197
|
+
* );
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @param message The message template. Placeholders to be replaced with
|
|
201
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
202
|
+
* `{value}`).
|
|
203
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
204
|
+
* evaluation, this can be a callback that returns the
|
|
205
|
+
* properties.
|
|
206
|
+
*/
|
|
207
|
+
warn(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
208
|
+
/**
|
|
209
|
+
* Lazily log a warning message. Use this when the message values are
|
|
210
|
+
* expensive to compute and should only be computed if the message is actually
|
|
211
|
+
* logged.
|
|
212
|
+
*
|
|
213
|
+
* ```typescript
|
|
214
|
+
* logger.warn(l => l`A warning message with ${expensiveValue()}.`);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @param callback A callback that returns the message template prefix.
|
|
218
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
219
|
+
*/
|
|
220
|
+
warn(callback: LogCallback): void;
|
|
221
|
+
/**
|
|
222
|
+
* Log an error message. Use this as a template string prefix.
|
|
223
|
+
*
|
|
224
|
+
* ```typescript
|
|
225
|
+
* logger.error `An error message with ${value}.`;
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @param message The message template strings array.
|
|
229
|
+
* @param values The message template values.
|
|
230
|
+
*/
|
|
231
|
+
error(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
232
|
+
/**
|
|
233
|
+
* Log an error message with properties.
|
|
234
|
+
*
|
|
235
|
+
* ```typescript
|
|
236
|
+
* logger.warn('An error message with {value}.', { value });
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
240
|
+
* returns the properties:
|
|
241
|
+
*
|
|
242
|
+
* ```typescript
|
|
243
|
+
* logger.error(
|
|
244
|
+
* 'An error message with {value}.',
|
|
245
|
+
* () => ({ value: expensiveComputation() })
|
|
246
|
+
* );
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @param message The message template. Placeholders to be replaced with
|
|
250
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
251
|
+
* `{value}`).
|
|
252
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
253
|
+
* evaluation, this can be a callback that returns the
|
|
254
|
+
* properties.
|
|
255
|
+
*/
|
|
256
|
+
error(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
257
|
+
/**
|
|
258
|
+
* Lazily log an error message. Use this when the message values are
|
|
259
|
+
* expensive to compute and should only be computed if the message is actually
|
|
260
|
+
* logged.
|
|
261
|
+
*
|
|
262
|
+
* ```typescript
|
|
263
|
+
* logger.error(l => l`An error message with ${expensiveValue()}.`);
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @param callback A callback that returns the message template prefix.
|
|
267
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
268
|
+
*/
|
|
269
|
+
error(callback: LogCallback): void;
|
|
270
|
+
/**
|
|
271
|
+
* Log a fatal error message. Use this as a template string prefix.
|
|
272
|
+
*
|
|
273
|
+
* ```typescript
|
|
274
|
+
* logger.fatal `A fatal error message with ${value}.`;
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @param message The message template strings array.
|
|
278
|
+
* @param values The message template values.
|
|
279
|
+
*/
|
|
280
|
+
fatal(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
281
|
+
/**
|
|
282
|
+
* Log a fatal error message with properties.
|
|
283
|
+
*
|
|
284
|
+
* ```typescript
|
|
285
|
+
* logger.warn('A fatal error message with {value}.', { value });
|
|
286
|
+
* ```
|
|
287
|
+
*
|
|
288
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
289
|
+
* returns the properties:
|
|
290
|
+
*
|
|
291
|
+
* ```typescript
|
|
292
|
+
* logger.fatal(
|
|
293
|
+
* 'A fatal error message with {value}.',
|
|
294
|
+
* () => ({ value: expensiveComputation() })
|
|
295
|
+
* );
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @param message The message template. Placeholders to be replaced with
|
|
299
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
300
|
+
* `{value}`).
|
|
301
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
302
|
+
* evaluation, this can be a callback that returns the
|
|
303
|
+
* properties.
|
|
304
|
+
*/
|
|
305
|
+
fatal(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
306
|
+
/**
|
|
307
|
+
* Lazily log a fatal error message. Use this when the message values are
|
|
308
|
+
* expensive to compute and should only be computed if the message is actually
|
|
309
|
+
* logged.
|
|
310
|
+
*
|
|
311
|
+
* ```typescript
|
|
312
|
+
* logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @param callback A callback that returns the message template prefix.
|
|
316
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
317
|
+
*/
|
|
318
|
+
fatal(callback: LogCallback): void;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* A logging callback function. It is used to defer the computation of a
|
|
322
|
+
* message template until it is actually logged.
|
|
323
|
+
* @param prefix The message template prefix.
|
|
324
|
+
* @returns The rendered message array.
|
|
325
|
+
*/
|
|
326
|
+
export type LogCallback = (prefix: LogTemplatePrefix) => unknown[];
|
|
327
|
+
/**
|
|
328
|
+
* A logging template prefix function. It is used to log a message in
|
|
329
|
+
* a {@link LogCallback} function.
|
|
330
|
+
* @param message The message template strings array.
|
|
331
|
+
* @param values The message template values.
|
|
332
|
+
* @returns The rendered message array.
|
|
333
|
+
*/
|
|
334
|
+
export type LogTemplatePrefix = (message: TemplateStringsArray, ...values: unknown[]) => unknown[];
|
|
335
|
+
/**
|
|
336
|
+
* Get a logger with the given category.
|
|
337
|
+
*
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const logger = getLogger(["my-app"]);
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @param category The category of the logger. It can be a string or an array
|
|
343
|
+
* of strings. If it is a string, it is equivalent to an array
|
|
344
|
+
* with a single element.
|
|
345
|
+
* @returns The logger.
|
|
346
|
+
*/
|
|
347
|
+
export declare function getLogger(category?: string | readonly string[]): Logger;
|
|
348
|
+
/**
|
|
349
|
+
* A logger implementation. Do not use this directly; use {@link getLogger}
|
|
350
|
+
* instead. This class is exported for testing purposes.
|
|
351
|
+
*/
|
|
352
|
+
export declare class LoggerImpl implements Logger {
|
|
353
|
+
readonly parent: LoggerImpl | null;
|
|
354
|
+
readonly children: Record<string, LoggerImpl | WeakRef<LoggerImpl>>;
|
|
355
|
+
readonly category: readonly string[];
|
|
356
|
+
readonly sinks: Sink[];
|
|
357
|
+
parentSinks: "inherit" | "override";
|
|
358
|
+
readonly filters: Filter[];
|
|
359
|
+
lowestLevel: LogLevel | null;
|
|
360
|
+
contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;
|
|
361
|
+
static getLogger(category?: string | readonly string[]): LoggerImpl;
|
|
362
|
+
private constructor();
|
|
363
|
+
getChild(subcategory: string | readonly [string] | readonly [string, ...(readonly string[])]): LoggerImpl;
|
|
364
|
+
/**
|
|
365
|
+
* Reset the logger. This removes all sinks and filters from the logger.
|
|
366
|
+
*/
|
|
367
|
+
reset(): void;
|
|
368
|
+
/**
|
|
369
|
+
* Reset the logger and all its descendants. This removes all sinks and
|
|
370
|
+
* filters from the logger and all its descendants.
|
|
371
|
+
*/
|
|
372
|
+
resetDescendants(): void;
|
|
373
|
+
with(properties: Record<string, unknown>): Logger;
|
|
374
|
+
filter(record: LogRecord): boolean;
|
|
375
|
+
getSinks(level: LogLevel): Iterable<Sink>;
|
|
376
|
+
emit(record: LogRecord, bypassSinks?: Set<Sink>): void;
|
|
377
|
+
log(level: LogLevel, rawMessage: string, properties: Record<string, unknown> | (() => Record<string, unknown>), bypassSinks?: Set<Sink>): void;
|
|
378
|
+
logLazily(level: LogLevel, callback: LogCallback, properties?: Record<string, unknown>): void;
|
|
379
|
+
logTemplate(level: LogLevel, messageTemplate: TemplateStringsArray, values: unknown[], properties?: Record<string, unknown>): void;
|
|
380
|
+
debug(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
381
|
+
info(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
382
|
+
warn(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
383
|
+
error(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
384
|
+
fatal(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* A logger implementation with contextual properties. Do not use this
|
|
388
|
+
* directly; use {@link Logger.with} instead. This class is exported
|
|
389
|
+
* for testing purposes.
|
|
390
|
+
*/
|
|
391
|
+
export declare class LoggerCtx implements Logger {
|
|
392
|
+
logger: LoggerImpl;
|
|
393
|
+
properties: Record<string, unknown>;
|
|
394
|
+
constructor(logger: LoggerImpl, properties: Record<string, unknown>);
|
|
395
|
+
get category(): readonly string[];
|
|
396
|
+
get parent(): Logger | null;
|
|
397
|
+
getChild(subcategory: string | readonly [string] | readonly [string, ...string[]]): Logger;
|
|
398
|
+
with(properties: Record<string, unknown>): Logger;
|
|
399
|
+
log(level: LogLevel, message: string, properties: Record<string, unknown> | (() => Record<string, unknown>), bypassSinks?: Set<Sink>): void;
|
|
400
|
+
logLazily(level: LogLevel, callback: LogCallback): void;
|
|
401
|
+
logTemplate(level: LogLevel, messageTemplate: TemplateStringsArray, values: unknown[]): void;
|
|
402
|
+
debug(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
403
|
+
info(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
404
|
+
warn(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
405
|
+
error(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
406
|
+
fatal(message: TemplateStringsArray | string | LogCallback, ...values: unknown[]): void;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Parse a message template into a message template array and a values array.
|
|
410
|
+
* @param template The message template.
|
|
411
|
+
* @param properties The values to replace placeholders with.
|
|
412
|
+
* @returns The message template array and the values array.
|
|
413
|
+
*/
|
|
414
|
+
export declare function parseMessageTemplate(template: string, properties: Record<string, unknown>): readonly unknown[];
|
|
415
|
+
/**
|
|
416
|
+
* Render a message template with values.
|
|
417
|
+
* @param template The message template.
|
|
418
|
+
* @param values The message template values.
|
|
419
|
+
* @returns The message template values interleaved between the substitution
|
|
420
|
+
* values.
|
|
421
|
+
*/
|
|
422
|
+
export declare function renderMessage(template: TemplateStringsArray, values: readonly unknown[]): unknown[];
|
|
423
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logtape/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,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AAO,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;AAOD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,SAAS,OAAO,EAAE,CAoCpB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,SAAS,OAAO,EAAE,GACzB,OAAO,EAAE,CAOX"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { type Config, ConfigError, configure, configureSync, dispose, disposeSync, getConfig, type LoggerConfig, reset, resetSync, } from "./config.js";
|
|
2
|
+
export { type ContextLocalStorage, withContext } from "./context.js";
|
|
3
|
+
export { type Filter, type FilterLike, getLevelFilter, toFilter, } from "./filter.js";
|
|
4
|
+
export { type AnsiColor, ansiColorFormatter, type AnsiColorFormatterOptions, type AnsiStyle, type ConsoleFormatter, defaultConsoleFormatter, defaultTextFormatter, type FormattedValues, getAnsiColorFormatter, getTextFormatter, type TextFormatter, type TextFormatterOptions, } from "./formatter.js";
|
|
5
|
+
export { compareLogLevel, isLogLevel, type LogLevel, parseLogLevel, } from "./level.js";
|
|
6
|
+
export { getLogger, type Logger } from "./logger.js";
|
|
7
|
+
export type { LogRecord } from "./record.js";
|
|
8
|
+
export { type ConsoleSinkOptions, getConsoleSink, getStreamSink, type Sink, type StreamSinkOptions, withFilter, } from "./sink.js";
|
|
9
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/logtape/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,WAAW,EACX,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,EACL,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,SAAS,EACd,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,eAAe,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,eAAe,EACf,UAAU,EACV,KAAK,QAAQ,EACb,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,KAAK,kBAAkB,EACvB,cAAc,EACd,aAAa,EACb,KAAK,IAAI,EACT,KAAK,iBAAiB,EACtB,UAAU,GACX,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeUtil.d.ts","sourceRoot":"","sources":["../../src/logtape/nodeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LogLevel } from "./level.js";
|
|
2
|
+
/**
|
|
3
|
+
* A log record.
|
|
4
|
+
*/
|
|
5
|
+
export interface LogRecord {
|
|
6
|
+
/**
|
|
7
|
+
* The category of the logger that produced the log record.
|
|
8
|
+
*/
|
|
9
|
+
readonly category: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* The log level.
|
|
12
|
+
*/
|
|
13
|
+
readonly level: LogLevel;
|
|
14
|
+
/**
|
|
15
|
+
* The log message. This is the result of substituting the message template
|
|
16
|
+
* with the values. The number of elements in this array is always odd,
|
|
17
|
+
* with the message template values interleaved between the substitution
|
|
18
|
+
* values.
|
|
19
|
+
*/
|
|
20
|
+
readonly message: readonly unknown[];
|
|
21
|
+
/**
|
|
22
|
+
* The raw log message. This is the original message template without any
|
|
23
|
+
* further processing. It can be either:
|
|
24
|
+
*
|
|
25
|
+
* - A string without any substitutions if the log record was created with
|
|
26
|
+
* a method call syntax, e.g., "Hello, {name}!" for
|
|
27
|
+
* `logger.info("Hello, {name}!", { name })`.
|
|
28
|
+
* - A template string array if the log record was created with a tagged
|
|
29
|
+
* template literal syntax, e.g., `["Hello, ", "!"]` for
|
|
30
|
+
* ``logger.info`Hello, ${name}!```.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.6.0
|
|
33
|
+
*/
|
|
34
|
+
readonly rawMessage: string | TemplateStringsArray;
|
|
35
|
+
/**
|
|
36
|
+
* The timestamp of the log record in milliseconds since the Unix epoch.
|
|
37
|
+
*/
|
|
38
|
+
readonly timestamp: number;
|
|
39
|
+
/**
|
|
40
|
+
* The extra properties of the log record.
|
|
41
|
+
*/
|
|
42
|
+
readonly properties: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/logtape/record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;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;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,oBAAoB,CAAC;IAEnD;;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,108 @@
|
|
|
1
|
+
import { type FilterLike } from "./filter.js";
|
|
2
|
+
import { type ConsoleFormatter, type TextFormatter } from "./formatter.js";
|
|
3
|
+
import type { LogLevel } from "./level.js";
|
|
4
|
+
import type { LogRecord } from "./record.js";
|
|
5
|
+
/**
|
|
6
|
+
* A sink is a function that accepts a log record and prints it somewhere.
|
|
7
|
+
* Thrown exceptions will be suppressed and then logged to the meta logger,
|
|
8
|
+
* a {@link Logger} with the category `["logtape", "meta"]`. (In that case,
|
|
9
|
+
* the meta log record will not be passed to the sink to avoid infinite
|
|
10
|
+
* recursion.)
|
|
11
|
+
*
|
|
12
|
+
* @param record The log record to sink.
|
|
13
|
+
*/
|
|
14
|
+
export type Sink = (record: LogRecord) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
17
|
+
* pass the filter.
|
|
18
|
+
*
|
|
19
|
+
* @example Filter a console sink to only log records with the info level
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param sink A sink to be filtered.
|
|
25
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
26
|
+
* function or a {@link LogLevel} string.
|
|
27
|
+
* @returns A sink that only logs records that pass the filter.
|
|
28
|
+
*/
|
|
29
|
+
export declare function withFilter(sink: Sink, filter: FilterLike): Sink;
|
|
30
|
+
/**
|
|
31
|
+
* Options for the {@link getStreamSink} function.
|
|
32
|
+
*/
|
|
33
|
+
export interface StreamSinkOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The text formatter to use. Defaults to {@link defaultTextFormatter}.
|
|
36
|
+
*/
|
|
37
|
+
formatter?: TextFormatter;
|
|
38
|
+
/**
|
|
39
|
+
* The text encoder to use. Defaults to an instance of {@link TextEncoder}.
|
|
40
|
+
*/
|
|
41
|
+
encoder?: {
|
|
42
|
+
encode(text: string): Uint8Array;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A factory that returns a sink that writes to a {@link WritableStream}.
|
|
47
|
+
*
|
|
48
|
+
* Note that the `stream` is of Web Streams API, which is different from
|
|
49
|
+
* Node.js streams. You can convert a Node.js stream to a Web Streams API
|
|
50
|
+
* stream using [`stream.Writable.toWeb()`] method.
|
|
51
|
+
*
|
|
52
|
+
* [`stream.Writable.toWeb()`]: https://nodejs.org/api/stream.html#streamwritabletowebstreamwritable
|
|
53
|
+
*
|
|
54
|
+
* @example Sink to the standard error in Deno
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const stderrSink = getStreamSink(Deno.stderr.writable);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Sink to the standard error in Node.js
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import stream from "node:stream";
|
|
62
|
+
* const stderrSink = getStreamSink(stream.Writable.toWeb(process.stderr));
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param stream The stream to write to.
|
|
66
|
+
* @param options The options for the sink.
|
|
67
|
+
* @returns A sink that writes to the stream.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getStreamSink(stream: WritableStream, options?: StreamSinkOptions): Sink & AsyncDisposable;
|
|
70
|
+
type ConsoleMethod = "debug" | "info" | "log" | "warn" | "error";
|
|
71
|
+
/**
|
|
72
|
+
* Options for the {@link getConsoleSink} function.
|
|
73
|
+
*/
|
|
74
|
+
export interface ConsoleSinkOptions {
|
|
75
|
+
/**
|
|
76
|
+
* The console formatter or text formatter to use.
|
|
77
|
+
* Defaults to {@link defaultConsoleFormatter}.
|
|
78
|
+
*/
|
|
79
|
+
formatter?: ConsoleFormatter | TextFormatter;
|
|
80
|
+
/**
|
|
81
|
+
* The mapping from log levels to console methods. Defaults to:
|
|
82
|
+
*
|
|
83
|
+
* ```typescript
|
|
84
|
+
* {
|
|
85
|
+
* debug: "debug",
|
|
86
|
+
* info: "info",
|
|
87
|
+
* warning: "warn",
|
|
88
|
+
* error: "error",
|
|
89
|
+
* fatal: "error",
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* @since 0.9.0
|
|
93
|
+
*/
|
|
94
|
+
levelMap?: Record<LogLevel, ConsoleMethod>;
|
|
95
|
+
/**
|
|
96
|
+
* The console to log to. Defaults to {@link console}.
|
|
97
|
+
*/
|
|
98
|
+
console?: Console;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A console sink factory that returns a sink that logs to the console.
|
|
102
|
+
*
|
|
103
|
+
* @param options The options for the sink.
|
|
104
|
+
* @returns A sink that logs to the console.
|
|
105
|
+
*/
|
|
106
|
+
export declare function getConsoleSink(options?: ConsoleSinkOptions): Sink;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../../src/logtape/sink.ts"],"names":[],"mappings":"AAAA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