@likec4/log 1.49.0 → 1.51.0
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/dist/THIRD-PARTY-LICENSES.md +29 -0
- package/dist/_chunks/libs/@logtape/logtape.d.mts +1278 -0
- package/dist/_chunks/libs/@logtape/logtape.mjs +1314 -0
- package/dist/_chunks/rolldown-runtime.mjs +11 -0
- package/dist/index.d.mts +47 -11
- package/dist/index.mjs +120 -15
- package/package.json +5 -7
- package/src/formatters.ts +36 -10
- package/src/index.ts +13 -7
- package/src/sink.ts +7 -0
- package/src/utils.ts +16 -0
|
@@ -0,0 +1,1278 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/context.d.ts
|
|
2
|
+
//#region src/context.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A generic interface for a context-local storage. It resembles
|
|
5
|
+
* the {@link AsyncLocalStorage} API from Node.js.
|
|
6
|
+
* @template T The type of the context-local store.
|
|
7
|
+
* @since 0.7.0
|
|
8
|
+
*/
|
|
9
|
+
interface ContextLocalStorage<T> {
|
|
10
|
+
/**
|
|
11
|
+
* Runs a callback with the given store as the context-local store.
|
|
12
|
+
* @param store The store to use as the context-local store.
|
|
13
|
+
* @param callback The callback to run.
|
|
14
|
+
* @returns The return value of the callback.
|
|
15
|
+
*/
|
|
16
|
+
run<R>(store: T, callback: () => R): R;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the current context-local store.
|
|
19
|
+
* @returns The current context-local store, or `undefined` if there is no
|
|
20
|
+
* store.
|
|
21
|
+
*/
|
|
22
|
+
getStore(): T | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Runs a callback with the given implicit context. Every single log record
|
|
26
|
+
* in the callback will have the given context.
|
|
27
|
+
*
|
|
28
|
+
* If no `contextLocalStorage` is configured, this function does nothing and
|
|
29
|
+
* just returns the return value of the callback. It also logs a warning to
|
|
30
|
+
* the `["logtape", "meta"]` logger in this case.
|
|
31
|
+
* @param context The context to inject.
|
|
32
|
+
* @param callback The callback to run.
|
|
33
|
+
* @returns The return value of the callback.
|
|
34
|
+
* @since 0.7.0
|
|
35
|
+
*/
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/level.d.ts
|
|
38
|
+
//#region src/level.d.ts
|
|
39
|
+
declare const logLevels: readonly ["trace", "debug", "info", "warning", "error", "fatal"];
|
|
40
|
+
/**
|
|
41
|
+
* The severity level of a {@link LogRecord}.
|
|
42
|
+
*/
|
|
43
|
+
type LogLevel = typeof logLevels[number];
|
|
44
|
+
/**
|
|
45
|
+
* Lists all available log levels with the order of their severity.
|
|
46
|
+
* The `"trace"` level goes first, and the `"fatal"` level goes last.
|
|
47
|
+
* @returns A new copy of the array of log levels.
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/record.d.ts
|
|
52
|
+
//#region src/record.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* A log record.
|
|
55
|
+
*/
|
|
56
|
+
interface LogRecord {
|
|
57
|
+
/**
|
|
58
|
+
* The category of the logger that produced the log record.
|
|
59
|
+
*/
|
|
60
|
+
readonly category: readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* The log level.
|
|
63
|
+
*/
|
|
64
|
+
readonly level: LogLevel;
|
|
65
|
+
/**
|
|
66
|
+
* The log message. This is the result of substituting the message template
|
|
67
|
+
* with the values. The number of elements in this array is always odd,
|
|
68
|
+
* with the message template values interleaved between the substitution
|
|
69
|
+
* values.
|
|
70
|
+
*/
|
|
71
|
+
readonly message: readonly unknown[];
|
|
72
|
+
/**
|
|
73
|
+
* The raw log message. This is the original message template without any
|
|
74
|
+
* further processing. It can be either:
|
|
75
|
+
*
|
|
76
|
+
* - A string without any substitutions if the log record was created with
|
|
77
|
+
* a method call syntax, e.g., "Hello, {name}!" for
|
|
78
|
+
* `logger.info("Hello, {name}!", { name })`.
|
|
79
|
+
* - A template string array if the log record was created with a tagged
|
|
80
|
+
* template literal syntax, e.g., `["Hello, ", "!"]` for
|
|
81
|
+
* ``logger.info`Hello, ${name}!```.
|
|
82
|
+
*
|
|
83
|
+
* @since 0.6.0
|
|
84
|
+
*/
|
|
85
|
+
readonly rawMessage: string | TemplateStringsArray;
|
|
86
|
+
/**
|
|
87
|
+
* The timestamp of the log record in milliseconds since the Unix epoch.
|
|
88
|
+
*/
|
|
89
|
+
readonly timestamp: number;
|
|
90
|
+
/**
|
|
91
|
+
* The extra properties of the log record.
|
|
92
|
+
*/
|
|
93
|
+
readonly properties: Record<string, unknown>;
|
|
94
|
+
} //# sourceMappingURL=record.d.ts.map
|
|
95
|
+
//#endregion
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/filter.d.ts
|
|
98
|
+
//#region src/filter.d.ts
|
|
99
|
+
/**
|
|
100
|
+
* A filter is a function that accepts a log record and returns `true` if the
|
|
101
|
+
* record should be passed to the sink.
|
|
102
|
+
*
|
|
103
|
+
* @param record The log record to filter.
|
|
104
|
+
* @returns `true` if the record should be passed to the sink.
|
|
105
|
+
*/
|
|
106
|
+
type Filter = (record: LogRecord) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* A filter-like value is either a {@link Filter} or a {@link LogLevel}.
|
|
109
|
+
* `null` is also allowed to represent a filter that rejects all records.
|
|
110
|
+
*/
|
|
111
|
+
type FilterLike = Filter | LogLevel | null;
|
|
112
|
+
/**
|
|
113
|
+
* Converts a {@link FilterLike} value to an actual {@link Filter}.
|
|
114
|
+
*
|
|
115
|
+
* @param filter The filter-like value to convert.
|
|
116
|
+
* @returns The actual filter.
|
|
117
|
+
*/
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/formatter.d.ts
|
|
120
|
+
//#region src/formatter.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* A text formatter is a function that accepts a log record and returns
|
|
123
|
+
* a string.
|
|
124
|
+
*
|
|
125
|
+
* @param record The log record to format.
|
|
126
|
+
* @returns The formatted log record.
|
|
127
|
+
*/
|
|
128
|
+
type TextFormatter = (record: LogRecord) => string;
|
|
129
|
+
/**
|
|
130
|
+
* The formatted values for a log record.
|
|
131
|
+
* @since 0.6.0
|
|
132
|
+
*/
|
|
133
|
+
interface FormattedValues {
|
|
134
|
+
/**
|
|
135
|
+
* The formatted timestamp.
|
|
136
|
+
*/
|
|
137
|
+
timestamp: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* The formatted log level.
|
|
140
|
+
*/
|
|
141
|
+
level: string;
|
|
142
|
+
/**
|
|
143
|
+
* The formatted category.
|
|
144
|
+
*/
|
|
145
|
+
category: string;
|
|
146
|
+
/**
|
|
147
|
+
* The formatted message.
|
|
148
|
+
*/
|
|
149
|
+
message: string;
|
|
150
|
+
/**
|
|
151
|
+
* The unformatted log record.
|
|
152
|
+
*/
|
|
153
|
+
record: LogRecord;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The various options for the built-in text formatters.
|
|
157
|
+
* @since 0.6.0
|
|
158
|
+
*/
|
|
159
|
+
interface TextFormatterOptions {
|
|
160
|
+
/**
|
|
161
|
+
* The timestamp format. This can be one of the following:
|
|
162
|
+
*
|
|
163
|
+
* - `"date-time-timezone"`: The date and time with the full timezone offset
|
|
164
|
+
* (e.g., `"2023-11-14 22:13:20.000 +00:00"`).
|
|
165
|
+
* - `"date-time-tz"`: The date and time with the short timezone offset
|
|
166
|
+
* (e.g., `"2023-11-14 22:13:20.000 +00"`).
|
|
167
|
+
* - `"date-time"`: The date and time without the timezone offset
|
|
168
|
+
* (e.g., `"2023-11-14 22:13:20.000"`).
|
|
169
|
+
* - `"time-timezone"`: The time with the full timezone offset but without
|
|
170
|
+
* the date (e.g., `"22:13:20.000 +00:00"`).
|
|
171
|
+
* - `"time-tz"`: The time with the short timezone offset but without the date
|
|
172
|
+
* (e.g., `"22:13:20.000 +00"`).
|
|
173
|
+
* - `"time"`: The time without the date or timezone offset
|
|
174
|
+
* (e.g., `"22:13:20.000"`).
|
|
175
|
+
* - `"date"`: The date without the time or timezone offset
|
|
176
|
+
* (e.g., `"2023-11-14"`).
|
|
177
|
+
* - `"rfc3339"`: The date and time in RFC 3339 format
|
|
178
|
+
* (e.g., `"2023-11-14T22:13:20.000Z"`).
|
|
179
|
+
* - `"none"` or `"disabled"`: No display
|
|
180
|
+
*
|
|
181
|
+
* Alternatively, this can be a function that accepts a timestamp and returns
|
|
182
|
+
* a string.
|
|
183
|
+
*
|
|
184
|
+
* The default is `"date-time-timezone"`.
|
|
185
|
+
*/
|
|
186
|
+
timestamp?: "date-time-timezone" | "date-time-tz" | "date-time" | "time-timezone" | "time-tz" | "time" | "date" | "rfc3339" | "none" | "disabled" | ((ts: number) => string | null);
|
|
187
|
+
/**
|
|
188
|
+
* The log level format. This can be one of the following:
|
|
189
|
+
*
|
|
190
|
+
* - `"ABBR"`: The log level abbreviation in uppercase (e.g., `"INF"`).
|
|
191
|
+
* - `"FULL"`: The full log level name in uppercase (e.g., `"INFO"`).
|
|
192
|
+
* - `"L"`: The first letter of the log level in uppercase (e.g., `"I"`).
|
|
193
|
+
* - `"abbr"`: The log level abbreviation in lowercase (e.g., `"inf"`).
|
|
194
|
+
* - `"full"`: The full log level name in lowercase (e.g., `"info"`).
|
|
195
|
+
* - `"l"`: The first letter of the log level in lowercase (e.g., `"i"`).
|
|
196
|
+
*
|
|
197
|
+
* Alternatively, this can be a function that accepts a log level and returns
|
|
198
|
+
* a string.
|
|
199
|
+
*
|
|
200
|
+
* The default is `"ABBR"`.
|
|
201
|
+
*/
|
|
202
|
+
level?: "ABBR" | "FULL" | "L" | "abbr" | "full" | "l" | ((level: LogLevel) => string);
|
|
203
|
+
/**
|
|
204
|
+
* The separator between category names. For example, if the separator is
|
|
205
|
+
* `"·"`, the category `["a", "b", "c"]` will be formatted as `"a·b·c"`.
|
|
206
|
+
* The default separator is `"·"`.
|
|
207
|
+
*
|
|
208
|
+
* If this is a function, it will be called with the category array and
|
|
209
|
+
* should return a string, which will be used for rendering the category.
|
|
210
|
+
*/
|
|
211
|
+
category?: string | ((category: readonly string[]) => string);
|
|
212
|
+
/**
|
|
213
|
+
* The format of the embedded values.
|
|
214
|
+
*
|
|
215
|
+
* A function that renders a value to a string. This function is used to
|
|
216
|
+
* render the values in the log record. The default is a cross-runtime
|
|
217
|
+
* `inspect()` function that uses [`util.inspect()`] in Node.js/Bun,
|
|
218
|
+
* [`Deno.inspect()`] in Deno, or falls back to {@link JSON.stringify} in
|
|
219
|
+
* browsers.
|
|
220
|
+
*
|
|
221
|
+
* The second parameter provides access to the default cross-runtime
|
|
222
|
+
* `inspect()` function, allowing you to fall back to the default behavior
|
|
223
|
+
* for certain values while customizing others. You can ignore this
|
|
224
|
+
* parameter if you don't need the fallback functionality.
|
|
225
|
+
*
|
|
226
|
+
* [`util.inspect()`]: https://nodejs.org/api/util.html#utilinspectobject-options
|
|
227
|
+
* [`Deno.inspect()`]: https://docs.deno.com/api/deno/~/Deno.inspect
|
|
228
|
+
* @param value The value to render.
|
|
229
|
+
* @param inspect The default cross-runtime inspect function that can be used
|
|
230
|
+
* as a fallback. Accepts an optional `options` parameter
|
|
231
|
+
* with a `colors` boolean field.
|
|
232
|
+
* @returns The string representation of the value.
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* getTextFormatter({
|
|
236
|
+
* value(value, inspect) {
|
|
237
|
+
* // Custom formatting for numbers
|
|
238
|
+
* if (typeof value === 'number') {
|
|
239
|
+
* return value.toFixed(2);
|
|
240
|
+
* }
|
|
241
|
+
* // Fall back to default for everything else
|
|
242
|
+
* return inspect(value);
|
|
243
|
+
* }
|
|
244
|
+
* })
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
value?: (value: unknown, inspect: (value: unknown, options?: {
|
|
248
|
+
colors?: boolean;
|
|
249
|
+
}) => string) => string;
|
|
250
|
+
/**
|
|
251
|
+
* How those formatted parts are concatenated.
|
|
252
|
+
*
|
|
253
|
+
* A function that formats the log record. This function is called with the
|
|
254
|
+
* formatted values and should return a string. Note that the formatted
|
|
255
|
+
* *should not* include a newline character at the end.
|
|
256
|
+
*
|
|
257
|
+
* By default, this is a function that formats the log record as follows:
|
|
258
|
+
*
|
|
259
|
+
* ```
|
|
260
|
+
* 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
|
|
261
|
+
* ```
|
|
262
|
+
* @param values The formatted values.
|
|
263
|
+
* @returns The formatted log record.
|
|
264
|
+
*/
|
|
265
|
+
format?: (values: FormattedValues) => string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get a text formatter with the specified options. Although it's flexible
|
|
269
|
+
* enough to create a custom formatter, if you want more control, you can
|
|
270
|
+
* create a custom formatter that satisfies the {@link TextFormatter} type
|
|
271
|
+
* instead.
|
|
272
|
+
*
|
|
273
|
+
* For more information on the options, see {@link TextFormatterOptions}.
|
|
274
|
+
*
|
|
275
|
+
* By default, the formatter formats log records as follows:
|
|
276
|
+
*
|
|
277
|
+
* ```
|
|
278
|
+
* 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
|
|
279
|
+
* ```
|
|
280
|
+
* @param options The options for the text formatter.
|
|
281
|
+
* @returns The text formatter.
|
|
282
|
+
* @since 0.6.0
|
|
283
|
+
*/
|
|
284
|
+
/**
|
|
285
|
+
* The ANSI colors. These can be used to colorize text in the console.
|
|
286
|
+
* @since 0.6.0
|
|
287
|
+
*/
|
|
288
|
+
type AnsiColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
289
|
+
/**
|
|
290
|
+
* The ANSI text styles.
|
|
291
|
+
* @since 0.6.0
|
|
292
|
+
*/
|
|
293
|
+
type AnsiStyle = "bold" | "dim" | "italic" | "underline" | "strikethrough";
|
|
294
|
+
/**
|
|
295
|
+
* The various options for the ANSI color formatter.
|
|
296
|
+
* @since 0.6.0
|
|
297
|
+
*/
|
|
298
|
+
interface AnsiColorFormatterOptions extends TextFormatterOptions {
|
|
299
|
+
/**
|
|
300
|
+
* The timestamp format. This can be one of the following:
|
|
301
|
+
*
|
|
302
|
+
* - `"date-time-timezone"`: The date and time with the full timezone offset
|
|
303
|
+
* (e.g., `"2023-11-14 22:13:20.000 +00:00"`).
|
|
304
|
+
* - `"date-time-tz"`: The date and time with the short timezone offset
|
|
305
|
+
* (e.g., `"2023-11-14 22:13:20.000 +00"`).
|
|
306
|
+
* - `"date-time"`: The date and time without the timezone offset
|
|
307
|
+
* (e.g., `"2023-11-14 22:13:20.000"`).
|
|
308
|
+
* - `"time-timezone"`: The time with the full timezone offset but without
|
|
309
|
+
* the date (e.g., `"22:13:20.000 +00:00"`).
|
|
310
|
+
* - `"time-tz"`: The time with the short timezone offset but without the date
|
|
311
|
+
* (e.g., `"22:13:20.000 +00"`).
|
|
312
|
+
* - `"time"`: The time without the date or timezone offset
|
|
313
|
+
* (e.g., `"22:13:20.000"`).
|
|
314
|
+
* - `"date"`: The date without the time or timezone offset
|
|
315
|
+
* (e.g., `"2023-11-14"`).
|
|
316
|
+
* - `"rfc3339"`: The date and time in RFC 3339 format
|
|
317
|
+
* (e.g., `"2023-11-14T22:13:20.000Z"`).
|
|
318
|
+
*
|
|
319
|
+
* Alternatively, this can be a function that accepts a timestamp and returns
|
|
320
|
+
* a string.
|
|
321
|
+
*
|
|
322
|
+
* The default is `"date-time-tz"`.
|
|
323
|
+
*/
|
|
324
|
+
timestamp?: "date-time-timezone" | "date-time-tz" | "date-time" | "time-timezone" | "time-tz" | "time" | "date" | "rfc3339" | ((ts: number) => string);
|
|
325
|
+
/**
|
|
326
|
+
* The ANSI style for the timestamp. `"dim"` is used by default.
|
|
327
|
+
*/
|
|
328
|
+
timestampStyle?: AnsiStyle | null;
|
|
329
|
+
/**
|
|
330
|
+
* The ANSI color for the timestamp. No color is used by default.
|
|
331
|
+
*/
|
|
332
|
+
timestampColor?: AnsiColor | null;
|
|
333
|
+
/**
|
|
334
|
+
* The ANSI style for the log level. `"bold"` is used by default.
|
|
335
|
+
*/
|
|
336
|
+
levelStyle?: AnsiStyle | null;
|
|
337
|
+
/**
|
|
338
|
+
* The ANSI colors for the log levels. The default colors are as follows:
|
|
339
|
+
*
|
|
340
|
+
* - `"trace"`: `null` (no color)
|
|
341
|
+
* - `"debug"`: `"blue"`
|
|
342
|
+
* - `"info"`: `"green"`
|
|
343
|
+
* - `"warning"`: `"yellow"`
|
|
344
|
+
* - `"error"`: `"red"`
|
|
345
|
+
* - `"fatal"`: `"magenta"`
|
|
346
|
+
*/
|
|
347
|
+
levelColors?: Record<LogLevel, AnsiColor | null>;
|
|
348
|
+
/**
|
|
349
|
+
* The ANSI style for the category. `"dim"` is used by default.
|
|
350
|
+
*/
|
|
351
|
+
categoryStyle?: AnsiStyle | null;
|
|
352
|
+
/**
|
|
353
|
+
* The ANSI color for the category. No color is used by default.
|
|
354
|
+
*/
|
|
355
|
+
categoryColor?: AnsiColor | null;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get an ANSI color formatter with the specified options.
|
|
359
|
+
*
|
|
360
|
+
* 
|
|
361
|
+
* @param option The options for the ANSI color formatter.
|
|
362
|
+
* @returns The ANSI color formatter.
|
|
363
|
+
* @since 0.6.0
|
|
364
|
+
*/
|
|
365
|
+
/**
|
|
366
|
+
* A console formatter is a function that accepts a log record and returns
|
|
367
|
+
* an array of arguments to pass to {@link console.log}.
|
|
368
|
+
*
|
|
369
|
+
* @param record The log record to format.
|
|
370
|
+
* @returns The formatted log record, as an array of arguments for
|
|
371
|
+
* {@link console.log}.
|
|
372
|
+
*/
|
|
373
|
+
type ConsoleFormatter = (record: LogRecord) => readonly unknown[];
|
|
374
|
+
/**
|
|
375
|
+
* The default console formatter.
|
|
376
|
+
*
|
|
377
|
+
* @param record The log record to format.
|
|
378
|
+
* @returns The formatted log record, as an array of arguments for
|
|
379
|
+
* {@link console.log}.
|
|
380
|
+
*/
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/sink.d.ts
|
|
383
|
+
//#region src/sink.d.ts
|
|
384
|
+
/**
|
|
385
|
+
* A sink is a function that accepts a log record and prints it somewhere.
|
|
386
|
+
* Thrown exceptions will be suppressed and then logged to the meta logger,
|
|
387
|
+
* a {@link Logger} with the category `["logtape", "meta"]`. (In that case,
|
|
388
|
+
* the meta log record will not be passed to the sink to avoid infinite
|
|
389
|
+
* recursion.)
|
|
390
|
+
*
|
|
391
|
+
* @param record The log record to sink.
|
|
392
|
+
*/
|
|
393
|
+
type Sink = (record: LogRecord) => void;
|
|
394
|
+
/**
|
|
395
|
+
* An async sink is a function that accepts a log record and asynchronously
|
|
396
|
+
* processes it. This type is used with {@link fromAsyncSink} to create
|
|
397
|
+
* a regular sink that properly handles asynchronous operations.
|
|
398
|
+
*
|
|
399
|
+
* @param record The log record to process asynchronously.
|
|
400
|
+
* @returns A promise that resolves when the record has been processed.
|
|
401
|
+
* @since 1.0.0
|
|
402
|
+
*/
|
|
403
|
+
/**
|
|
404
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
405
|
+
* pass the filter.
|
|
406
|
+
*
|
|
407
|
+
* @example Filter a console sink to only log records with the info level
|
|
408
|
+
* ```typescript
|
|
409
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @param sink A sink to be filtered.
|
|
413
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
414
|
+
* function or a {@link LogLevel} string.
|
|
415
|
+
* @returns A sink that only logs records that pass the filter.
|
|
416
|
+
*/
|
|
417
|
+
declare function withFilter(sink: Sink, filter: FilterLike): Sink;
|
|
418
|
+
/**
|
|
419
|
+
* Options for the {@link getStreamSink} function.
|
|
420
|
+
*/
|
|
421
|
+
type ConsoleMethod = "debug" | "info" | "log" | "warn" | "error";
|
|
422
|
+
/**
|
|
423
|
+
* Options for the {@link getConsoleSink} function.
|
|
424
|
+
*/
|
|
425
|
+
interface ConsoleSinkOptions {
|
|
426
|
+
/**
|
|
427
|
+
* The console formatter or text formatter to use.
|
|
428
|
+
* Defaults to {@link defaultConsoleFormatter}.
|
|
429
|
+
*/
|
|
430
|
+
formatter?: ConsoleFormatter | TextFormatter;
|
|
431
|
+
/**
|
|
432
|
+
* The mapping from log levels to console methods. Defaults to:
|
|
433
|
+
*
|
|
434
|
+
* ```typescript
|
|
435
|
+
* {
|
|
436
|
+
* trace: "trace",
|
|
437
|
+
* debug: "debug",
|
|
438
|
+
* info: "info",
|
|
439
|
+
* warning: "warn",
|
|
440
|
+
* error: "error",
|
|
441
|
+
* fatal: "error",
|
|
442
|
+
* }
|
|
443
|
+
* ```
|
|
444
|
+
* @since 0.9.0
|
|
445
|
+
*/
|
|
446
|
+
levelMap?: Record<LogLevel, ConsoleMethod>;
|
|
447
|
+
/**
|
|
448
|
+
* The console to log to. Defaults to {@link console}.
|
|
449
|
+
*/
|
|
450
|
+
console?: Console;
|
|
451
|
+
/**
|
|
452
|
+
* Enable non-blocking mode with optional buffer configuration.
|
|
453
|
+
* When enabled, log records are buffered and flushed in the background.
|
|
454
|
+
*
|
|
455
|
+
* @example Simple non-blocking mode
|
|
456
|
+
* ```typescript
|
|
457
|
+
* getConsoleSink({ nonBlocking: true });
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @example Custom buffer configuration
|
|
461
|
+
* ```typescript
|
|
462
|
+
* getConsoleSink({
|
|
463
|
+
* nonBlocking: {
|
|
464
|
+
* bufferSize: 1000,
|
|
465
|
+
* flushInterval: 50
|
|
466
|
+
* }
|
|
467
|
+
* });
|
|
468
|
+
* ```
|
|
469
|
+
*
|
|
470
|
+
* @default `false`
|
|
471
|
+
* @since 1.0.0
|
|
472
|
+
*/
|
|
473
|
+
nonBlocking?: boolean | {
|
|
474
|
+
/**
|
|
475
|
+
* Maximum number of records to buffer before flushing.
|
|
476
|
+
* @default `100`
|
|
477
|
+
*/
|
|
478
|
+
bufferSize?: number;
|
|
479
|
+
/**
|
|
480
|
+
* Interval in milliseconds between automatic flushes.
|
|
481
|
+
* @default `100`
|
|
482
|
+
*/
|
|
483
|
+
flushInterval?: number;
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* A console sink factory that returns a sink that logs to the console.
|
|
488
|
+
*
|
|
489
|
+
* @param options The options for the sink.
|
|
490
|
+
* @returns A sink that logs to the console. If `nonBlocking` is enabled,
|
|
491
|
+
* returns a sink that also implements {@link Disposable}.
|
|
492
|
+
*/
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/config.d.ts
|
|
495
|
+
//#region src/config.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* A configuration for the loggers.
|
|
498
|
+
*/
|
|
499
|
+
interface Config<TSinkId extends string, TFilterId extends string> {
|
|
500
|
+
/**
|
|
501
|
+
* The sinks to use. The keys are the sink identifiers, and the values are
|
|
502
|
+
* {@link Sink}s.
|
|
503
|
+
*/
|
|
504
|
+
sinks: Record<TSinkId, Sink>;
|
|
505
|
+
/**
|
|
506
|
+
* The filters to use. The keys are the filter identifiers, and the values
|
|
507
|
+
* are either {@link Filter}s or {@link LogLevel}s.
|
|
508
|
+
*/
|
|
509
|
+
filters?: Record<TFilterId, FilterLike>;
|
|
510
|
+
/**
|
|
511
|
+
* The loggers to configure.
|
|
512
|
+
*/
|
|
513
|
+
loggers: LoggerConfig<TSinkId, TFilterId>[];
|
|
514
|
+
/**
|
|
515
|
+
* The context-local storage to use for implicit contexts.
|
|
516
|
+
* @since 0.7.0
|
|
517
|
+
*/
|
|
518
|
+
contextLocalStorage?: ContextLocalStorage<Record<string, unknown>>;
|
|
519
|
+
/**
|
|
520
|
+
* Whether to reset the configuration before applying this one.
|
|
521
|
+
*/
|
|
522
|
+
reset?: boolean;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* A logger configuration.
|
|
526
|
+
*/
|
|
527
|
+
interface LoggerConfig<TSinkId extends string, TFilterId extends string> {
|
|
528
|
+
/**
|
|
529
|
+
* The category of the logger. If a string, it is equivalent to an array
|
|
530
|
+
* with one element.
|
|
531
|
+
*/
|
|
532
|
+
category: string | string[];
|
|
533
|
+
/**
|
|
534
|
+
* The sink identifiers to use.
|
|
535
|
+
*/
|
|
536
|
+
sinks?: TSinkId[];
|
|
537
|
+
/**
|
|
538
|
+
* Whether to inherit the parent's sinks. If `inherit`, the parent's sinks
|
|
539
|
+
* are used along with the specified sinks. If `override`, the parent's
|
|
540
|
+
* sinks are not used, and only the specified sinks are used.
|
|
541
|
+
*
|
|
542
|
+
* The default is `inherit`.
|
|
543
|
+
* @default `"inherit"
|
|
544
|
+
* @since 0.6.0
|
|
545
|
+
*/
|
|
546
|
+
parentSinks?: "inherit" | "override";
|
|
547
|
+
/**
|
|
548
|
+
* The filter identifiers to use.
|
|
549
|
+
*/
|
|
550
|
+
filters?: TFilterId[];
|
|
551
|
+
/**
|
|
552
|
+
* The lowest log level to accept. If `null`, the logger will reject all
|
|
553
|
+
* records.
|
|
554
|
+
* @since 0.8.0
|
|
555
|
+
*/
|
|
556
|
+
lowestLevel?: LogLevel | null;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Configure the loggers with the specified configuration.
|
|
560
|
+
*
|
|
561
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
562
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* await configure({
|
|
567
|
+
* sinks: {
|
|
568
|
+
* console: getConsoleSink(),
|
|
569
|
+
* },
|
|
570
|
+
* filters: {
|
|
571
|
+
* slow: (log) =>
|
|
572
|
+
* "duration" in log.properties &&
|
|
573
|
+
* log.properties.duration as number > 1000,
|
|
574
|
+
* },
|
|
575
|
+
* loggers: [
|
|
576
|
+
* {
|
|
577
|
+
* category: "my-app",
|
|
578
|
+
* sinks: ["console"],
|
|
579
|
+
* lowestLevel: "info",
|
|
580
|
+
* },
|
|
581
|
+
* {
|
|
582
|
+
* category: ["my-app", "sql"],
|
|
583
|
+
* filters: ["slow"],
|
|
584
|
+
* lowestLevel: "debug",
|
|
585
|
+
* },
|
|
586
|
+
* {
|
|
587
|
+
* category: "logtape",
|
|
588
|
+
* sinks: ["console"],
|
|
589
|
+
* lowestLevel: "error",
|
|
590
|
+
* },
|
|
591
|
+
* ],
|
|
592
|
+
* });
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @param config The configuration.
|
|
596
|
+
*/
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.7/node_modules/@logtape/logtape/dist/logger.d.ts
|
|
599
|
+
//#region src/logger.d.ts
|
|
600
|
+
/**
|
|
601
|
+
* A logger interface. It provides methods to log messages at different
|
|
602
|
+
* severity levels.
|
|
603
|
+
*
|
|
604
|
+
* ```typescript
|
|
605
|
+
* const logger = getLogger("category");
|
|
606
|
+
* logger.trace `A trace message with ${value}`
|
|
607
|
+
* logger.debug `A debug message with ${value}.`;
|
|
608
|
+
* logger.info `An info message with ${value}.`;
|
|
609
|
+
* logger.warn `A warning message with ${value}.`;
|
|
610
|
+
* logger.error `An error message with ${value}.`;
|
|
611
|
+
* logger.fatal `A fatal error message with ${value}.`;
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
interface Logger {
|
|
615
|
+
/**
|
|
616
|
+
* The category of the logger. It is an array of strings.
|
|
617
|
+
*/
|
|
618
|
+
readonly category: readonly string[];
|
|
619
|
+
/**
|
|
620
|
+
* The logger with the supercategory of the current logger. If the current
|
|
621
|
+
* logger is the root logger, this is `null`.
|
|
622
|
+
*/
|
|
623
|
+
readonly parent: Logger | null;
|
|
624
|
+
/**
|
|
625
|
+
* Get a child logger with the given subcategory.
|
|
626
|
+
*
|
|
627
|
+
* ```typescript
|
|
628
|
+
* const logger = getLogger("category");
|
|
629
|
+
* const subLogger = logger.getChild("sub-category");
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* The above code is equivalent to:
|
|
633
|
+
*
|
|
634
|
+
* ```typescript
|
|
635
|
+
* const logger = getLogger("category");
|
|
636
|
+
* const subLogger = getLogger(["category", "sub-category"]);
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @param subcategory The subcategory.
|
|
640
|
+
* @returns The child logger.
|
|
641
|
+
*/
|
|
642
|
+
getChild(subcategory: string | readonly [string] | readonly [string, ...string[]]): Logger;
|
|
643
|
+
/**
|
|
644
|
+
* Get a logger with contextual properties. This is useful for
|
|
645
|
+
* log multiple messages with the shared set of properties.
|
|
646
|
+
*
|
|
647
|
+
* ```typescript
|
|
648
|
+
* const logger = getLogger("category");
|
|
649
|
+
* const ctx = logger.with({ foo: 123, bar: "abc" });
|
|
650
|
+
* ctx.info("A message with {foo} and {bar}.");
|
|
651
|
+
* ctx.warn("Another message with {foo}, {bar}, and {baz}.", { baz: true });
|
|
652
|
+
* ```
|
|
653
|
+
*
|
|
654
|
+
* The above code is equivalent to:
|
|
655
|
+
*
|
|
656
|
+
* ```typescript
|
|
657
|
+
* const logger = getLogger("category");
|
|
658
|
+
* logger.info("A message with {foo} and {bar}.", { foo: 123, bar: "abc" });
|
|
659
|
+
* logger.warn(
|
|
660
|
+
* "Another message with {foo}, {bar}, and {baz}.",
|
|
661
|
+
* { foo: 123, bar: "abc", baz: true },
|
|
662
|
+
* );
|
|
663
|
+
* ```
|
|
664
|
+
*
|
|
665
|
+
* @param properties
|
|
666
|
+
* @returns
|
|
667
|
+
* @since 0.5.0
|
|
668
|
+
*/
|
|
669
|
+
with(properties: Record<string, unknown>): Logger;
|
|
670
|
+
/**
|
|
671
|
+
* Log a trace message. Use this as a template string prefix.
|
|
672
|
+
*
|
|
673
|
+
* ```typescript
|
|
674
|
+
* logger.trace `A trace message with ${value}.`;
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @param message The message template strings array.
|
|
678
|
+
* @param values The message template values.
|
|
679
|
+
* @since 0.12.0
|
|
680
|
+
*/
|
|
681
|
+
trace(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
682
|
+
/**
|
|
683
|
+
* Log a trace message with properties.
|
|
684
|
+
*
|
|
685
|
+
* ```typescript
|
|
686
|
+
* logger.trace('A trace message with {value}.', { value });
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
690
|
+
* returns the properties:
|
|
691
|
+
*
|
|
692
|
+
* ```typescript
|
|
693
|
+
* logger.trace(
|
|
694
|
+
* 'A trace message with {value}.',
|
|
695
|
+
* () => ({ value: expensiveComputation() })
|
|
696
|
+
* );
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @param message The message template. Placeholders to be replaced with
|
|
700
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
701
|
+
* `{value}`).
|
|
702
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
703
|
+
* evaluation, this can be a callback that returns the
|
|
704
|
+
* properties.
|
|
705
|
+
* @since 0.12.0
|
|
706
|
+
*/
|
|
707
|
+
trace(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
708
|
+
/**
|
|
709
|
+
* Log a trace values with no message. This is useful when you
|
|
710
|
+
* want to log properties without a message, e.g., when you want to log
|
|
711
|
+
* the context of a request or an operation.
|
|
712
|
+
*
|
|
713
|
+
* ```typescript
|
|
714
|
+
* logger.trace({ method: 'GET', url: '/api/v1/resource' });
|
|
715
|
+
* ```
|
|
716
|
+
*
|
|
717
|
+
* Note that this is a shorthand for:
|
|
718
|
+
*
|
|
719
|
+
* ```typescript
|
|
720
|
+
* logger.trace('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
724
|
+
* and should use the following syntax instead:
|
|
725
|
+
*
|
|
726
|
+
* ```typescript
|
|
727
|
+
* logger.trace('{*}', () => ({
|
|
728
|
+
* method: expensiveMethod(),
|
|
729
|
+
* url: expensiveUrl(),
|
|
730
|
+
* }));
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* @param properties The values to log. Note that this does not take
|
|
734
|
+
* a callback.
|
|
735
|
+
* @since 0.12.0
|
|
736
|
+
*/
|
|
737
|
+
trace(properties: Record<string, unknown>): void;
|
|
738
|
+
/**
|
|
739
|
+
* Lazily log a trace message. Use this when the message values are expensive
|
|
740
|
+
* to compute and should only be computed if the message is actually logged.
|
|
741
|
+
*
|
|
742
|
+
* ```typescript
|
|
743
|
+
* logger.trace(l => l`A trace message with ${expensiveValue()}.`);
|
|
744
|
+
* ```
|
|
745
|
+
*
|
|
746
|
+
* @param callback A callback that returns the message template prefix.
|
|
747
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
748
|
+
* @since 0.12.0
|
|
749
|
+
*/
|
|
750
|
+
trace(callback: LogCallback): void;
|
|
751
|
+
/**
|
|
752
|
+
* Log a debug message. Use this as a template string prefix.
|
|
753
|
+
*
|
|
754
|
+
* ```typescript
|
|
755
|
+
* logger.debug `A debug message with ${value}.`;
|
|
756
|
+
* ```
|
|
757
|
+
*
|
|
758
|
+
* @param message The message template strings array.
|
|
759
|
+
* @param values The message template values.
|
|
760
|
+
*/
|
|
761
|
+
debug(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
762
|
+
/**
|
|
763
|
+
* Log a debug message with properties.
|
|
764
|
+
*
|
|
765
|
+
* ```typescript
|
|
766
|
+
* logger.debug('A debug message with {value}.', { value });
|
|
767
|
+
* ```
|
|
768
|
+
*
|
|
769
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
770
|
+
* returns the properties:
|
|
771
|
+
*
|
|
772
|
+
* ```typescript
|
|
773
|
+
* logger.debug(
|
|
774
|
+
* 'A debug message with {value}.',
|
|
775
|
+
* () => ({ value: expensiveComputation() })
|
|
776
|
+
* );
|
|
777
|
+
* ```
|
|
778
|
+
*
|
|
779
|
+
* @param message The message template. Placeholders to be replaced with
|
|
780
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
781
|
+
* `{value}`).
|
|
782
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
783
|
+
* evaluation, this can be a callback that returns the
|
|
784
|
+
* properties.
|
|
785
|
+
*/
|
|
786
|
+
debug(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
787
|
+
/**
|
|
788
|
+
* Log a debug values with no message. This is useful when you
|
|
789
|
+
* want to log properties without a message, e.g., when you want to log
|
|
790
|
+
* the context of a request or an operation.
|
|
791
|
+
*
|
|
792
|
+
* ```typescript
|
|
793
|
+
* logger.debug({ method: 'GET', url: '/api/v1/resource' });
|
|
794
|
+
* ```
|
|
795
|
+
*
|
|
796
|
+
* Note that this is a shorthand for:
|
|
797
|
+
*
|
|
798
|
+
* ```typescript
|
|
799
|
+
* logger.debug('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
800
|
+
* ```
|
|
801
|
+
*
|
|
802
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
803
|
+
* and should use the following syntax instead:
|
|
804
|
+
*
|
|
805
|
+
* ```typescript
|
|
806
|
+
* logger.debug('{*}', () => ({
|
|
807
|
+
* method: expensiveMethod(),
|
|
808
|
+
* url: expensiveUrl(),
|
|
809
|
+
* }));
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* @param properties The values to log. Note that this does not take
|
|
813
|
+
* a callback.
|
|
814
|
+
* @since 0.11.0
|
|
815
|
+
*/
|
|
816
|
+
debug(properties: Record<string, unknown>): void;
|
|
817
|
+
/**
|
|
818
|
+
* Lazily log a debug message. Use this when the message values are expensive
|
|
819
|
+
* to compute and should only be computed if the message is actually logged.
|
|
820
|
+
*
|
|
821
|
+
* ```typescript
|
|
822
|
+
* logger.debug(l => l`A debug message with ${expensiveValue()}.`);
|
|
823
|
+
* ```
|
|
824
|
+
*
|
|
825
|
+
* @param callback A callback that returns the message template prefix.
|
|
826
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
827
|
+
*/
|
|
828
|
+
debug(callback: LogCallback): void;
|
|
829
|
+
/**
|
|
830
|
+
* Log an informational message. Use this as a template string prefix.
|
|
831
|
+
*
|
|
832
|
+
* ```typescript
|
|
833
|
+
* logger.info `An info message with ${value}.`;
|
|
834
|
+
* ```
|
|
835
|
+
*
|
|
836
|
+
* @param message The message template strings array.
|
|
837
|
+
* @param values The message template values.
|
|
838
|
+
*/
|
|
839
|
+
info(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
840
|
+
/**
|
|
841
|
+
* Log an informational message with properties.
|
|
842
|
+
*
|
|
843
|
+
* ```typescript
|
|
844
|
+
* logger.info('An info message with {value}.', { value });
|
|
845
|
+
* ```
|
|
846
|
+
*
|
|
847
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
848
|
+
* returns the properties:
|
|
849
|
+
*
|
|
850
|
+
* ```typescript
|
|
851
|
+
* logger.info(
|
|
852
|
+
* 'An info message with {value}.',
|
|
853
|
+
* () => ({ value: expensiveComputation() })
|
|
854
|
+
* );
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @param message The message template. Placeholders to be replaced with
|
|
858
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
859
|
+
* `{value}`).
|
|
860
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
861
|
+
* evaluation, this can be a callback that returns the
|
|
862
|
+
* properties.
|
|
863
|
+
*/
|
|
864
|
+
info(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
865
|
+
/**
|
|
866
|
+
* Log an informational values with no message. This is useful when you
|
|
867
|
+
* want to log properties without a message, e.g., when you want to log
|
|
868
|
+
* the context of a request or an operation.
|
|
869
|
+
*
|
|
870
|
+
* ```typescript
|
|
871
|
+
* logger.info({ method: 'GET', url: '/api/v1/resource' });
|
|
872
|
+
* ```
|
|
873
|
+
*
|
|
874
|
+
* Note that this is a shorthand for:
|
|
875
|
+
*
|
|
876
|
+
* ```typescript
|
|
877
|
+
* logger.info('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
878
|
+
* ```
|
|
879
|
+
*
|
|
880
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
881
|
+
* and should use the following syntax instead:
|
|
882
|
+
*
|
|
883
|
+
* ```typescript
|
|
884
|
+
* logger.info('{*}', () => ({
|
|
885
|
+
* method: expensiveMethod(),
|
|
886
|
+
* url: expensiveUrl(),
|
|
887
|
+
* }));
|
|
888
|
+
* ```
|
|
889
|
+
*
|
|
890
|
+
* @param properties The values to log. Note that this does not take
|
|
891
|
+
* a callback.
|
|
892
|
+
* @since 0.11.0
|
|
893
|
+
*/
|
|
894
|
+
info(properties: Record<string, unknown>): void;
|
|
895
|
+
/**
|
|
896
|
+
* Lazily log an informational message. Use this when the message values are
|
|
897
|
+
* expensive to compute and should only be computed if the message is actually
|
|
898
|
+
* logged.
|
|
899
|
+
*
|
|
900
|
+
* ```typescript
|
|
901
|
+
* logger.info(l => l`An info message with ${expensiveValue()}.`);
|
|
902
|
+
* ```
|
|
903
|
+
*
|
|
904
|
+
* @param callback A callback that returns the message template prefix.
|
|
905
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
906
|
+
*/
|
|
907
|
+
info(callback: LogCallback): void;
|
|
908
|
+
/**
|
|
909
|
+
* Log a warning message. Use this as a template string prefix.
|
|
910
|
+
*
|
|
911
|
+
* ```typescript
|
|
912
|
+
* logger.warn `A warning message with ${value}.`;
|
|
913
|
+
* ```
|
|
914
|
+
*
|
|
915
|
+
* @param message The message template strings array.
|
|
916
|
+
* @param values The message template values.
|
|
917
|
+
*/
|
|
918
|
+
warn(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
919
|
+
/**
|
|
920
|
+
* Log a warning message with properties.
|
|
921
|
+
*
|
|
922
|
+
* ```typescript
|
|
923
|
+
* logger.warn('A warning message with {value}.', { value });
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
927
|
+
* returns the properties:
|
|
928
|
+
*
|
|
929
|
+
* ```typescript
|
|
930
|
+
* logger.warn(
|
|
931
|
+
* 'A warning message with {value}.',
|
|
932
|
+
* () => ({ value: expensiveComputation() })
|
|
933
|
+
* );
|
|
934
|
+
* ```
|
|
935
|
+
*
|
|
936
|
+
* @param message The message template. Placeholders to be replaced with
|
|
937
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
938
|
+
* `{value}`).
|
|
939
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
940
|
+
* evaluation, this can be a callback that returns the
|
|
941
|
+
* properties.
|
|
942
|
+
*/
|
|
943
|
+
warn(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
944
|
+
/**
|
|
945
|
+
* Log a warning values with no message. This is useful when you
|
|
946
|
+
* want to log properties without a message, e.g., when you want to log
|
|
947
|
+
* the context of a request or an operation.
|
|
948
|
+
*
|
|
949
|
+
* ```typescript
|
|
950
|
+
* logger.warn({ method: 'GET', url: '/api/v1/resource' });
|
|
951
|
+
* ```
|
|
952
|
+
*
|
|
953
|
+
* Note that this is a shorthand for:
|
|
954
|
+
*
|
|
955
|
+
* ```typescript
|
|
956
|
+
* logger.warn('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
957
|
+
* ```
|
|
958
|
+
*
|
|
959
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
960
|
+
* and should use the following syntax instead:
|
|
961
|
+
*
|
|
962
|
+
* ```typescript
|
|
963
|
+
* logger.warn('{*}', () => ({
|
|
964
|
+
* method: expensiveMethod(),
|
|
965
|
+
* url: expensiveUrl(),
|
|
966
|
+
* }));
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @param properties The values to log. Note that this does not take
|
|
970
|
+
* a callback.
|
|
971
|
+
* @since 0.11.0
|
|
972
|
+
*/
|
|
973
|
+
warn(properties: Record<string, unknown>): void;
|
|
974
|
+
/**
|
|
975
|
+
* Lazily log a warning message. Use this when the message values are
|
|
976
|
+
* expensive to compute and should only be computed if the message is actually
|
|
977
|
+
* logged.
|
|
978
|
+
*
|
|
979
|
+
* ```typescript
|
|
980
|
+
* logger.warn(l => l`A warning message with ${expensiveValue()}.`);
|
|
981
|
+
* ```
|
|
982
|
+
*
|
|
983
|
+
* @param callback A callback that returns the message template prefix.
|
|
984
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
985
|
+
*/
|
|
986
|
+
warn(callback: LogCallback): void;
|
|
987
|
+
/**
|
|
988
|
+
* Log a warning message. Use this as a template string prefix.
|
|
989
|
+
*
|
|
990
|
+
* ```typescript
|
|
991
|
+
* logger.warning `A warning message with ${value}.`;
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @param message The message template strings array.
|
|
995
|
+
* @param values The message template values.
|
|
996
|
+
* @since 0.12.0
|
|
997
|
+
*/
|
|
998
|
+
warning(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
999
|
+
/**
|
|
1000
|
+
* Log a warning message with properties.
|
|
1001
|
+
*
|
|
1002
|
+
* ```typescript
|
|
1003
|
+
* logger.warning('A warning message with {value}.', { value });
|
|
1004
|
+
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
1007
|
+
* returns the properties:
|
|
1008
|
+
*
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* logger.warning(
|
|
1011
|
+
* 'A warning message with {value}.',
|
|
1012
|
+
* () => ({ value: expensiveComputation() })
|
|
1013
|
+
* );
|
|
1014
|
+
* ```
|
|
1015
|
+
*
|
|
1016
|
+
* @param message The message template. Placeholders to be replaced with
|
|
1017
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
1018
|
+
* `{value}`).
|
|
1019
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
1020
|
+
* evaluation, this can be a callback that returns the
|
|
1021
|
+
* properties.
|
|
1022
|
+
* @since 0.12.0
|
|
1023
|
+
*/
|
|
1024
|
+
warning(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
1025
|
+
/**
|
|
1026
|
+
* Log a warning values with no message. This is useful when you
|
|
1027
|
+
* want to log properties without a message, e.g., when you want to log
|
|
1028
|
+
* the context of a request or an operation.
|
|
1029
|
+
*
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* logger.warning({ method: 'GET', url: '/api/v1/resource' });
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* Note that this is a shorthand for:
|
|
1035
|
+
*
|
|
1036
|
+
* ```typescript
|
|
1037
|
+
* logger.warning('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
1038
|
+
* ```
|
|
1039
|
+
*
|
|
1040
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
1041
|
+
* and should use the following syntax instead:
|
|
1042
|
+
*
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* logger.warning('{*}', () => ({
|
|
1045
|
+
* method: expensiveMethod(),
|
|
1046
|
+
* url: expensiveUrl(),
|
|
1047
|
+
* }));
|
|
1048
|
+
* ```
|
|
1049
|
+
*
|
|
1050
|
+
* @param properties The values to log. Note that this does not take
|
|
1051
|
+
* a callback.
|
|
1052
|
+
* @since 0.12.0
|
|
1053
|
+
*/
|
|
1054
|
+
warning(properties: Record<string, unknown>): void;
|
|
1055
|
+
/**
|
|
1056
|
+
* Lazily log a warning message. Use this when the message values are
|
|
1057
|
+
* expensive to compute and should only be computed if the message is actually
|
|
1058
|
+
* logged.
|
|
1059
|
+
*
|
|
1060
|
+
* ```typescript
|
|
1061
|
+
* logger.warning(l => l`A warning message with ${expensiveValue()}.`);
|
|
1062
|
+
* ```
|
|
1063
|
+
*
|
|
1064
|
+
* @param callback A callback that returns the message template prefix.
|
|
1065
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
1066
|
+
* @since 0.12.0
|
|
1067
|
+
*/
|
|
1068
|
+
warning(callback: LogCallback): void;
|
|
1069
|
+
/**
|
|
1070
|
+
* Log an error message. Use this as a template string prefix.
|
|
1071
|
+
*
|
|
1072
|
+
* ```typescript
|
|
1073
|
+
* logger.error `An error message with ${value}.`;
|
|
1074
|
+
* ```
|
|
1075
|
+
*
|
|
1076
|
+
* @param message The message template strings array.
|
|
1077
|
+
* @param values The message template values.
|
|
1078
|
+
*/
|
|
1079
|
+
error(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
1080
|
+
/**
|
|
1081
|
+
* Log an error message with properties.
|
|
1082
|
+
*
|
|
1083
|
+
* ```typescript
|
|
1084
|
+
* logger.warn('An error message with {value}.', { value });
|
|
1085
|
+
* ```
|
|
1086
|
+
*
|
|
1087
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
1088
|
+
* returns the properties:
|
|
1089
|
+
*
|
|
1090
|
+
* ```typescript
|
|
1091
|
+
* logger.error(
|
|
1092
|
+
* 'An error message with {value}.',
|
|
1093
|
+
* () => ({ value: expensiveComputation() })
|
|
1094
|
+
* );
|
|
1095
|
+
* ```
|
|
1096
|
+
*
|
|
1097
|
+
* @param message The message template. Placeholders to be replaced with
|
|
1098
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
1099
|
+
* `{value}`).
|
|
1100
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
1101
|
+
* evaluation, this can be a callback that returns the
|
|
1102
|
+
* properties.
|
|
1103
|
+
*/
|
|
1104
|
+
error(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
1105
|
+
/**
|
|
1106
|
+
* Log an error values with no message. This is useful when you
|
|
1107
|
+
* want to log properties without a message, e.g., when you want to log
|
|
1108
|
+
* the context of a request or an operation.
|
|
1109
|
+
*
|
|
1110
|
+
* ```typescript
|
|
1111
|
+
* logger.error({ method: 'GET', url: '/api/v1/resource' });
|
|
1112
|
+
* ```
|
|
1113
|
+
*
|
|
1114
|
+
* Note that this is a shorthand for:
|
|
1115
|
+
*
|
|
1116
|
+
* ```typescript
|
|
1117
|
+
* logger.error('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
1118
|
+
* ```
|
|
1119
|
+
*
|
|
1120
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
1121
|
+
* and should use the following syntax instead:
|
|
1122
|
+
*
|
|
1123
|
+
* ```typescript
|
|
1124
|
+
* logger.error('{*}', () => ({
|
|
1125
|
+
* method: expensiveMethod(),
|
|
1126
|
+
* url: expensiveUrl(),
|
|
1127
|
+
* }));
|
|
1128
|
+
* ```
|
|
1129
|
+
*
|
|
1130
|
+
* @param properties The values to log. Note that this does not take
|
|
1131
|
+
* a callback.
|
|
1132
|
+
* @since 0.11.0
|
|
1133
|
+
*/
|
|
1134
|
+
error(properties: Record<string, unknown>): void;
|
|
1135
|
+
/**
|
|
1136
|
+
* Lazily log an error message. Use this when the message values are
|
|
1137
|
+
* expensive to compute and should only be computed if the message is actually
|
|
1138
|
+
* logged.
|
|
1139
|
+
*
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* logger.error(l => l`An error message with ${expensiveValue()}.`);
|
|
1142
|
+
* ```
|
|
1143
|
+
*
|
|
1144
|
+
* @param callback A callback that returns the message template prefix.
|
|
1145
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
1146
|
+
*/
|
|
1147
|
+
error(callback: LogCallback): void;
|
|
1148
|
+
/**
|
|
1149
|
+
* Log a fatal error message. Use this as a template string prefix.
|
|
1150
|
+
*
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* logger.fatal `A fatal error message with ${value}.`;
|
|
1153
|
+
* ```
|
|
1154
|
+
*
|
|
1155
|
+
* @param message The message template strings array.
|
|
1156
|
+
* @param values The message template values.
|
|
1157
|
+
*/
|
|
1158
|
+
fatal(message: TemplateStringsArray, ...values: readonly unknown[]): void;
|
|
1159
|
+
/**
|
|
1160
|
+
* Log a fatal error message with properties.
|
|
1161
|
+
*
|
|
1162
|
+
* ```typescript
|
|
1163
|
+
* logger.warn('A fatal error message with {value}.', { value });
|
|
1164
|
+
* ```
|
|
1165
|
+
*
|
|
1166
|
+
* If the properties are expensive to compute, you can pass a callback that
|
|
1167
|
+
* returns the properties:
|
|
1168
|
+
*
|
|
1169
|
+
* ```typescript
|
|
1170
|
+
* logger.fatal(
|
|
1171
|
+
* 'A fatal error message with {value}.',
|
|
1172
|
+
* () => ({ value: expensiveComputation() })
|
|
1173
|
+
* );
|
|
1174
|
+
* ```
|
|
1175
|
+
*
|
|
1176
|
+
* @param message The message template. Placeholders to be replaced with
|
|
1177
|
+
* `values` are indicated by keys in curly braces (e.g.,
|
|
1178
|
+
* `{value}`).
|
|
1179
|
+
* @param properties The values to replace placeholders with. For lazy
|
|
1180
|
+
* evaluation, this can be a callback that returns the
|
|
1181
|
+
* properties.
|
|
1182
|
+
*/
|
|
1183
|
+
fatal(message: string, properties?: Record<string, unknown> | (() => Record<string, unknown>)): void;
|
|
1184
|
+
/**
|
|
1185
|
+
* Log a fatal error values with no message. This is useful when you
|
|
1186
|
+
* want to log properties without a message, e.g., when you want to log
|
|
1187
|
+
* the context of a request or an operation.
|
|
1188
|
+
*
|
|
1189
|
+
* ```typescript
|
|
1190
|
+
* logger.fatal({ method: 'GET', url: '/api/v1/resource' });
|
|
1191
|
+
* ```
|
|
1192
|
+
*
|
|
1193
|
+
* Note that this is a shorthand for:
|
|
1194
|
+
*
|
|
1195
|
+
* ```typescript
|
|
1196
|
+
* logger.fatal('{*}', { method: 'GET', url: '/api/v1/resource' });
|
|
1197
|
+
* ```
|
|
1198
|
+
*
|
|
1199
|
+
* If the properties are expensive to compute, you cannot use this shorthand
|
|
1200
|
+
* and should use the following syntax instead:
|
|
1201
|
+
*
|
|
1202
|
+
* ```typescript
|
|
1203
|
+
* logger.fatal('{*}', () => ({
|
|
1204
|
+
* method: expensiveMethod(),
|
|
1205
|
+
* url: expensiveUrl(),
|
|
1206
|
+
* }));
|
|
1207
|
+
* ```
|
|
1208
|
+
*
|
|
1209
|
+
* @param properties The values to log. Note that this does not take
|
|
1210
|
+
* a callback.
|
|
1211
|
+
* @since 0.11.0
|
|
1212
|
+
*/
|
|
1213
|
+
fatal(properties: Record<string, unknown>): void;
|
|
1214
|
+
/**
|
|
1215
|
+
* Lazily log a fatal error message. Use this when the message values are
|
|
1216
|
+
* expensive to compute and should only be computed if the message is actually
|
|
1217
|
+
* logged.
|
|
1218
|
+
*
|
|
1219
|
+
* ```typescript
|
|
1220
|
+
* logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);
|
|
1221
|
+
* ```
|
|
1222
|
+
*
|
|
1223
|
+
* @param callback A callback that returns the message template prefix.
|
|
1224
|
+
* @throws {TypeError} If no log record was made inside the callback.
|
|
1225
|
+
*/
|
|
1226
|
+
fatal(callback: LogCallback): void;
|
|
1227
|
+
/**
|
|
1228
|
+
* Emits a log record with custom fields while using this logger's
|
|
1229
|
+
* category.
|
|
1230
|
+
*
|
|
1231
|
+
* This is a low-level API for integration scenarios where you need full
|
|
1232
|
+
* control over the log record, particularly for preserving timestamps
|
|
1233
|
+
* from external systems.
|
|
1234
|
+
*
|
|
1235
|
+
* ```typescript
|
|
1236
|
+
* const logger = getLogger(["my-app", "integration"]);
|
|
1237
|
+
*
|
|
1238
|
+
* // Emit a log with a custom timestamp
|
|
1239
|
+
* logger.emit({
|
|
1240
|
+
* timestamp: kafkaLog.originalTimestamp,
|
|
1241
|
+
* level: "info",
|
|
1242
|
+
* message: [kafkaLog.message],
|
|
1243
|
+
* rawMessage: kafkaLog.message,
|
|
1244
|
+
* properties: {
|
|
1245
|
+
* source: "kafka",
|
|
1246
|
+
* partition: kafkaLog.partition,
|
|
1247
|
+
* offset: kafkaLog.offset,
|
|
1248
|
+
* },
|
|
1249
|
+
* });
|
|
1250
|
+
* ```
|
|
1251
|
+
*
|
|
1252
|
+
* @param record Log record without category field (category comes from
|
|
1253
|
+
* the logger instance)
|
|
1254
|
+
* @since 1.1.0
|
|
1255
|
+
*/
|
|
1256
|
+
emit(record: Omit<LogRecord, "category">): void;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* A logging callback function. It is used to defer the computation of a
|
|
1260
|
+
* message template until it is actually logged.
|
|
1261
|
+
* @param prefix The message template prefix.
|
|
1262
|
+
* @returns The rendered message array.
|
|
1263
|
+
*/
|
|
1264
|
+
type LogCallback = (prefix: LogTemplatePrefix) => unknown[];
|
|
1265
|
+
/**
|
|
1266
|
+
* A logging template prefix function. It is used to log a message in
|
|
1267
|
+
* a {@link LogCallback} function.
|
|
1268
|
+
* @param message The message template strings array.
|
|
1269
|
+
* @param values The message template values.
|
|
1270
|
+
* @returns The rendered message array.
|
|
1271
|
+
*/
|
|
1272
|
+
type LogTemplatePrefix = (message: TemplateStringsArray, ...values: unknown[]) => unknown[];
|
|
1273
|
+
/**
|
|
1274
|
+
* A function type for logging methods in the {@link Logger} interface.
|
|
1275
|
+
* @since 1.0.0
|
|
1276
|
+
*/
|
|
1277
|
+
//#endregion
|
|
1278
|
+
export { withFilter as a, TextFormatter as c, LogRecord as d, LogLevel as f, Sink as i, TextFormatterOptions as l, Config as n, AnsiColorFormatterOptions as o, ConsoleSinkOptions as r, ConsoleFormatter as s, Logger as t, Filter as u };
|