@logtape/logtape 0.3.0-dev.24 → 0.3.0-dev.29
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/README.md +99 -7
- package/esm/config.js +20 -5
- package/esm/level.js +39 -0
- package/esm/mod.js +3 -2
- package/esm/sink.js +22 -0
- package/package.json +1 -1
- package/script/config.js +22 -6
- package/script/level.js +44 -0
- package/script/mod.js +6 -1
- package/script/sink.js +24 -1
- package/types/config.d.ts +6 -1
- package/types/config.d.ts.map +1 -1
- package/types/filter.d.ts +2 -1
- package/types/filter.d.ts.map +1 -1
- package/types/formatter.d.ts.map +1 -1
- package/types/level.d.ts +21 -0
- package/types/level.d.ts.map +1 -0
- package/types/level.test.d.ts.map +1 -0
- package/types/logger.d.ts +2 -1
- package/types/logger.d.ts.map +1 -1
- package/types/mod.d.ts +4 -3
- package/types/mod.d.ts.map +1 -1
- package/types/record.d.ts +1 -4
- package/types/record.d.ts.map +1 -1
- package/types/sink.d.ts +16 -0
- package/types/sink.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -27,9 +27,7 @@ The highlights of LogTape are:
|
|
|
27
27
|
and browsers. You can use LogTape in various environments without
|
|
28
28
|
changing the code.
|
|
29
29
|
|
|
30
|
-
- *Structured logging*:
|
|
31
|
-
messages with structured data. LogTape provides a simple and flexible
|
|
32
|
-
way to log structured data.
|
|
30
|
+
- *Structured logging*: You can log messages with structured data.
|
|
33
31
|
|
|
34
32
|
- *Hierarchical categories*: LogTape uses a hierarchical category system
|
|
35
33
|
to manage loggers. You can control the verbosity of log messages by
|
|
@@ -40,8 +38,7 @@ The highlights of LogTape are:
|
|
|
40
38
|
You can use template literals to log messages with placeholders and
|
|
41
39
|
values.
|
|
42
40
|
|
|
43
|
-
- *Dead simple sinks*:
|
|
44
|
-
sinks. You can easily add your own sinks to LogTape.
|
|
41
|
+
- *Dead simple sinks*: You can easily add your own sinks to LogTape.
|
|
45
42
|
|
|
46
43
|
Currently, LogTape provides only few sinks, but [you can easily add your own
|
|
47
44
|
sinks.](#sinks)
|
|
@@ -296,13 +293,17 @@ await configure({
|
|
|
296
293
|
See also [`getFileSink()`] function and [`FileSinkOptions`] interface
|
|
297
294
|
in the API reference for more details.
|
|
298
295
|
|
|
296
|
+
> [!NOTE]
|
|
297
|
+
> On Deno, you need to have the `--allow-write` flag and the `--unstable-fs`
|
|
298
|
+
> flag to use the file sink.
|
|
299
|
+
|
|
299
300
|
[`getFileSink()`]: https://jsr.io/@logtape/logtape/doc/~/getFileSink
|
|
300
301
|
[`FileSinkOptions`]: https://jsr.io/@logtape/logtape/doc/~/FileSinkOptions
|
|
301
302
|
|
|
302
303
|
### Rotating file sink
|
|
303
304
|
|
|
304
305
|
> [!NOTE]
|
|
305
|
-
>
|
|
306
|
+
> Rotating file sink is unavailable in the browser environment.
|
|
306
307
|
|
|
307
308
|
A rotating file sink is a file sink that rotates log files. It creates a new
|
|
308
309
|
log file when the current log file reaches a certain size. Here's an example
|
|
@@ -327,6 +328,10 @@ Rotated log files are named with a suffix like *.1*, *.2*, *.3*, and so on.
|
|
|
327
328
|
For more details, see [`getRotatingFileSink()`] function and
|
|
328
329
|
[`RotatingFileSinkOptions`] interface in the API reference.
|
|
329
330
|
|
|
331
|
+
> [!NOTE]
|
|
332
|
+
> On Deno, you need to have the `--allow-write` flag and the `--unstable-fs`
|
|
333
|
+
> flag to use the rotating file sink.
|
|
334
|
+
|
|
330
335
|
[`getRotatingFileSink()`]: https://jsr.io/@logtape/logtape/doc/~/getRotatingFileSink
|
|
331
336
|
[`RotatingFileSinkOptions`]: https://jsr.io/@logtape/logtape/doc/~/RotatingFileSinkOptions
|
|
332
337
|
|
|
@@ -346,7 +351,9 @@ Here's an example of a text formatter that writes log messages in a JSON format:
|
|
|
346
351
|
await configure({
|
|
347
352
|
sinks: {
|
|
348
353
|
stream: getStreamSink(Deno.stderr.writable, {
|
|
349
|
-
formatter
|
|
354
|
+
formatter(log) {
|
|
355
|
+
return JSON.stringify(log) + "\n",
|
|
356
|
+
}
|
|
350
357
|
}),
|
|
351
358
|
},
|
|
352
359
|
// Omitted for brevity
|
|
@@ -411,6 +418,91 @@ export default {
|
|
|
411
418
|
[`ctx.waitUntil()`]: https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil
|
|
412
419
|
|
|
413
420
|
|
|
421
|
+
Filters
|
|
422
|
+
-------
|
|
423
|
+
|
|
424
|
+
A filter is a function that filters log messages. A filter takes a log record
|
|
425
|
+
and returns a boolean value. If the filter returns `true`, the log record is
|
|
426
|
+
passed to the sinks; otherwise, the log record is discarded. Its signature is:
|
|
427
|
+
|
|
428
|
+
~~~~ typescript
|
|
429
|
+
export type Filter = (record: LogRecord) => boolean;
|
|
430
|
+
~~~~
|
|
431
|
+
|
|
432
|
+
For example, the following filter discards log messages whose property `elapsed`
|
|
433
|
+
is less than 100 milliseconds:
|
|
434
|
+
|
|
435
|
+
~~~~ typescript
|
|
436
|
+
import { configure, type LogRecord } from "@logtape/logtape";
|
|
437
|
+
|
|
438
|
+
await configure({
|
|
439
|
+
// Omitted for brevity
|
|
440
|
+
filters: {
|
|
441
|
+
tooSlow(record: LogRecord) {
|
|
442
|
+
return "elapsed" in record.properties && record.properties.elapsed >= 100;
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
loggers: [
|
|
446
|
+
{
|
|
447
|
+
category: ["my-app", "database"],
|
|
448
|
+
level: "debug",
|
|
449
|
+
sinks: ["console"],
|
|
450
|
+
filters: ["tooSlow"],
|
|
451
|
+
}
|
|
452
|
+
]
|
|
453
|
+
});
|
|
454
|
+
~~~~
|
|
455
|
+
|
|
456
|
+
### Level filter
|
|
457
|
+
|
|
458
|
+
LogTape provides a built-in level filter. You can use the level filter to
|
|
459
|
+
filter log messages by their log levels. The level filter factory takes
|
|
460
|
+
a [`LogLevel`] string and returns a level filter. For example, the following
|
|
461
|
+
level filter discards log messages whose log level is less than `info`:
|
|
462
|
+
|
|
463
|
+
~~~~ typescript
|
|
464
|
+
import { getLevelFilter } from "@logtape/logtape";
|
|
465
|
+
|
|
466
|
+
await configure({
|
|
467
|
+
filters: {
|
|
468
|
+
infoOrHigher: getLevelFilter("info");
|
|
469
|
+
},
|
|
470
|
+
// Omitted for brevity
|
|
471
|
+
});
|
|
472
|
+
~~~~
|
|
473
|
+
|
|
474
|
+
[`LogLevel`]: https://jsr.io/@logtape/logtape/doc/~/LogLevel
|
|
475
|
+
|
|
476
|
+
### Sink filter
|
|
477
|
+
|
|
478
|
+
A sink filter is a filter that is applied to a specific sink. You can add a
|
|
479
|
+
sink filter to a sink by decorating the sink with [`withFilter()`]:
|
|
480
|
+
|
|
481
|
+
~~~~ typescript
|
|
482
|
+
import { getConsoleSink, withFilter } from "@logtape/logtape";
|
|
483
|
+
|
|
484
|
+
await configure({
|
|
485
|
+
sinks: {
|
|
486
|
+
filteredConsole: withFilter(
|
|
487
|
+
getConsoleSink(),
|
|
488
|
+
log => "elapsed" in log.properties && log.properties.elapsed >= 100,
|
|
489
|
+
),
|
|
490
|
+
},
|
|
491
|
+
// Omitted for brevity
|
|
492
|
+
});
|
|
493
|
+
~~~~
|
|
494
|
+
|
|
495
|
+
The `filteredConsoleSink` only logs messages whose property `elapsed` is greater
|
|
496
|
+
than or equal to 100 milliseconds to the console.
|
|
497
|
+
|
|
498
|
+
> [!TIP]
|
|
499
|
+
> The `withFilter()` function can take a [`LogLevel`] string as the second
|
|
500
|
+
> argument. In this case, the log messages whose log level is less than
|
|
501
|
+
> the specified log level are discarded.
|
|
502
|
+
|
|
503
|
+
[`withFilter()`]: https://jsr.io/@logtape/logtape/doc/~/withFilter
|
|
504
|
+
|
|
505
|
+
|
|
414
506
|
Testing
|
|
415
507
|
-------
|
|
416
508
|
|
package/esm/config.js
CHANGED
|
@@ -3,9 +3,15 @@ import { toFilter } from "./filter.js";
|
|
|
3
3
|
import { LoggerImpl } from "./logger.js";
|
|
4
4
|
import { getConsoleSink } from "./sink.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The current configuration, if any. Otherwise, `null`.
|
|
7
7
|
*/
|
|
8
|
-
let
|
|
8
|
+
let currentConfig = null;
|
|
9
|
+
/**
|
|
10
|
+
* Strong references to the loggers.
|
|
11
|
+
* This is to prevent the loggers from being garbage collected so that their
|
|
12
|
+
* sinks and filters are not removed.
|
|
13
|
+
*/
|
|
14
|
+
const strongRefs = new Set();
|
|
9
15
|
/**
|
|
10
16
|
* Disposables to dispose when resetting the configuration.
|
|
11
17
|
*/
|
|
@@ -54,11 +60,11 @@ const asyncDisposables = new Set();
|
|
|
54
60
|
* @param config The configuration.
|
|
55
61
|
*/
|
|
56
62
|
export async function configure(config) {
|
|
57
|
-
if (
|
|
63
|
+
if (currentConfig != null && !config.reset) {
|
|
58
64
|
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
59
65
|
}
|
|
60
66
|
await reset();
|
|
61
|
-
|
|
67
|
+
currentConfig = config;
|
|
62
68
|
let metaConfigured = false;
|
|
63
69
|
for (const cfg of config.loggers) {
|
|
64
70
|
if (cfg.category.length === 0 ||
|
|
@@ -87,6 +93,7 @@ export async function configure(config) {
|
|
|
87
93
|
}
|
|
88
94
|
logger.filters.push(toFilter(filter));
|
|
89
95
|
}
|
|
96
|
+
strongRefs.add(logger);
|
|
90
97
|
}
|
|
91
98
|
for (const sink of Object.values(config.sinks)) {
|
|
92
99
|
if (Symbol.asyncDispose in sink) {
|
|
@@ -123,13 +130,21 @@ export async function configure(config) {
|
|
|
123
130
|
"misconfigured. To turn off this message, configure the meta logger " +
|
|
124
131
|
"with higher log levels than {dismissLevel}.", { metaLoggerCategory: ["logtape", "meta"], dismissLevel: "info" });
|
|
125
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
135
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
136
|
+
*/
|
|
137
|
+
export function getConfig() {
|
|
138
|
+
return currentConfig;
|
|
139
|
+
}
|
|
126
140
|
/**
|
|
127
141
|
* Reset the configuration. Mostly for testing purposes.
|
|
128
142
|
*/
|
|
129
143
|
export async function reset() {
|
|
130
144
|
await dispose();
|
|
131
145
|
LoggerImpl.getLogger([]).resetDescendants();
|
|
132
|
-
|
|
146
|
+
strongRefs.clear();
|
|
147
|
+
currentConfig = null;
|
|
133
148
|
}
|
|
134
149
|
/**
|
|
135
150
|
* Dispose of the disposables.
|
package/esm/level.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a log level from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param level The log level as a string. This is case-insensitive.
|
|
5
|
+
* @returns The log level.
|
|
6
|
+
* @throws {TypeError} If the log level is invalid.
|
|
7
|
+
*/
|
|
8
|
+
export function parseLogLevel(level) {
|
|
9
|
+
level = level.toLowerCase();
|
|
10
|
+
switch (level) {
|
|
11
|
+
case "debug":
|
|
12
|
+
case "info":
|
|
13
|
+
case "warning":
|
|
14
|
+
case "error":
|
|
15
|
+
case "fatal":
|
|
16
|
+
return level;
|
|
17
|
+
default:
|
|
18
|
+
throw new TypeError(`Invalid log level: ${level}.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a string is a valid log level. This function can be used as
|
|
23
|
+
* as a type guard to narrow the type of a string to a {@link LogLevel}.
|
|
24
|
+
*
|
|
25
|
+
* @param level The log level as a string. This is case-sensitive.
|
|
26
|
+
* @returns `true` if the string is a valid log level.
|
|
27
|
+
*/
|
|
28
|
+
export function isLogLevel(level) {
|
|
29
|
+
switch (level) {
|
|
30
|
+
case "debug":
|
|
31
|
+
case "info":
|
|
32
|
+
case "warning":
|
|
33
|
+
case "error":
|
|
34
|
+
case "fatal":
|
|
35
|
+
return true;
|
|
36
|
+
default:
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/esm/mod.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { ConfigError, configure, dispose, reset, } from "./config.js";
|
|
1
|
+
export { ConfigError, configure, dispose, getConfig, reset, } from "./config.js";
|
|
2
2
|
export { getFileSink, getRotatingFileSink } from "./filesink.node.js";
|
|
3
3
|
export { getLevelFilter, toFilter, } from "./filter.js";
|
|
4
4
|
export { defaultConsoleFormatter, defaultTextFormatter, } from "./formatter.js";
|
|
5
|
+
export { isLogLevel, parseLogLevel } from "./level.js";
|
|
5
6
|
export { getLogger } from "./logger.js";
|
|
6
|
-
export { getConsoleSink, getStreamSink, } from "./sink.js";
|
|
7
|
+
export { getConsoleSink, getStreamSink, withFilter, } from "./sink.js";
|
|
7
8
|
// cSpell: ignore filesink
|
package/esm/sink.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
import { toFilter } from "./filter.js";
|
|
1
2
|
import { defaultConsoleFormatter, defaultTextFormatter, } from "./formatter.js";
|
|
3
|
+
/**
|
|
4
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
5
|
+
* pass the filter.
|
|
6
|
+
*
|
|
7
|
+
* @example Filter a console sink to only log records with the info level
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param sink A sink to be filtered.
|
|
13
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
14
|
+
* function or a {@link LogLevel} string.
|
|
15
|
+
* @returns A sink that only logs records that pass the filter.
|
|
16
|
+
*/
|
|
17
|
+
export function withFilter(sink, filter) {
|
|
18
|
+
const filterFunc = toFilter(filter);
|
|
19
|
+
return (record) => {
|
|
20
|
+
if (filterFunc(record))
|
|
21
|
+
sink(record);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
2
24
|
/**
|
|
3
25
|
* A factory that returns a sink that writes to a {@link WritableStream}.
|
|
4
26
|
*
|
package/package.json
CHANGED
package/script/config.js
CHANGED
|
@@ -23,15 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ConfigError = exports.dispose = exports.reset = exports.configure = void 0;
|
|
26
|
+
exports.ConfigError = exports.dispose = exports.reset = exports.getConfig = exports.configure = void 0;
|
|
27
27
|
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
28
28
|
const filter_js_1 = require("./filter.js");
|
|
29
29
|
const logger_js_1 = require("./logger.js");
|
|
30
30
|
const sink_js_1 = require("./sink.js");
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* The current configuration, if any. Otherwise, `null`.
|
|
33
33
|
*/
|
|
34
|
-
let
|
|
34
|
+
let currentConfig = null;
|
|
35
|
+
/**
|
|
36
|
+
* Strong references to the loggers.
|
|
37
|
+
* This is to prevent the loggers from being garbage collected so that their
|
|
38
|
+
* sinks and filters are not removed.
|
|
39
|
+
*/
|
|
40
|
+
const strongRefs = new Set();
|
|
35
41
|
/**
|
|
36
42
|
* Disposables to dispose when resetting the configuration.
|
|
37
43
|
*/
|
|
@@ -80,11 +86,11 @@ const asyncDisposables = new Set();
|
|
|
80
86
|
* @param config The configuration.
|
|
81
87
|
*/
|
|
82
88
|
async function configure(config) {
|
|
83
|
-
if (
|
|
89
|
+
if (currentConfig != null && !config.reset) {
|
|
84
90
|
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
85
91
|
}
|
|
86
92
|
await reset();
|
|
87
|
-
|
|
93
|
+
currentConfig = config;
|
|
88
94
|
let metaConfigured = false;
|
|
89
95
|
for (const cfg of config.loggers) {
|
|
90
96
|
if (cfg.category.length === 0 ||
|
|
@@ -113,6 +119,7 @@ async function configure(config) {
|
|
|
113
119
|
}
|
|
114
120
|
logger.filters.push((0, filter_js_1.toFilter)(filter));
|
|
115
121
|
}
|
|
122
|
+
strongRefs.add(logger);
|
|
116
123
|
}
|
|
117
124
|
for (const sink of Object.values(config.sinks)) {
|
|
118
125
|
if (Symbol.asyncDispose in sink) {
|
|
@@ -150,13 +157,22 @@ async function configure(config) {
|
|
|
150
157
|
"with higher log levels than {dismissLevel}.", { metaLoggerCategory: ["logtape", "meta"], dismissLevel: "info" });
|
|
151
158
|
}
|
|
152
159
|
exports.configure = configure;
|
|
160
|
+
/**
|
|
161
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
162
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
163
|
+
*/
|
|
164
|
+
function getConfig() {
|
|
165
|
+
return currentConfig;
|
|
166
|
+
}
|
|
167
|
+
exports.getConfig = getConfig;
|
|
153
168
|
/**
|
|
154
169
|
* Reset the configuration. Mostly for testing purposes.
|
|
155
170
|
*/
|
|
156
171
|
async function reset() {
|
|
157
172
|
await dispose();
|
|
158
173
|
logger_js_1.LoggerImpl.getLogger([]).resetDescendants();
|
|
159
|
-
|
|
174
|
+
strongRefs.clear();
|
|
175
|
+
currentConfig = null;
|
|
160
176
|
}
|
|
161
177
|
exports.reset = reset;
|
|
162
178
|
/**
|
package/script/level.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLogLevel = exports.parseLogLevel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Parses a log level from a string.
|
|
6
|
+
*
|
|
7
|
+
* @param level The log level as a string. This is case-insensitive.
|
|
8
|
+
* @returns The log level.
|
|
9
|
+
* @throws {TypeError} If the log level is invalid.
|
|
10
|
+
*/
|
|
11
|
+
function parseLogLevel(level) {
|
|
12
|
+
level = level.toLowerCase();
|
|
13
|
+
switch (level) {
|
|
14
|
+
case "debug":
|
|
15
|
+
case "info":
|
|
16
|
+
case "warning":
|
|
17
|
+
case "error":
|
|
18
|
+
case "fatal":
|
|
19
|
+
return level;
|
|
20
|
+
default:
|
|
21
|
+
throw new TypeError(`Invalid log level: ${level}.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.parseLogLevel = parseLogLevel;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a string is a valid log level. This function can be used as
|
|
27
|
+
* as a type guard to narrow the type of a string to a {@link LogLevel}.
|
|
28
|
+
*
|
|
29
|
+
* @param level The log level as a string. This is case-sensitive.
|
|
30
|
+
* @returns `true` if the string is a valid log level.
|
|
31
|
+
*/
|
|
32
|
+
function isLogLevel(level) {
|
|
33
|
+
switch (level) {
|
|
34
|
+
case "debug":
|
|
35
|
+
case "info":
|
|
36
|
+
case "warning":
|
|
37
|
+
case "error":
|
|
38
|
+
case "fatal":
|
|
39
|
+
return true;
|
|
40
|
+
default:
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.isLogLevel = isLogLevel;
|
package/script/mod.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStreamSink = exports.getConsoleSink = exports.getLogger = exports.defaultTextFormatter = exports.defaultConsoleFormatter = exports.toFilter = exports.getLevelFilter = exports.getRotatingFileSink = exports.getFileSink = exports.reset = exports.dispose = exports.configure = exports.ConfigError = void 0;
|
|
3
|
+
exports.withFilter = exports.getStreamSink = exports.getConsoleSink = exports.getLogger = exports.parseLogLevel = exports.isLogLevel = exports.defaultTextFormatter = exports.defaultConsoleFormatter = exports.toFilter = exports.getLevelFilter = exports.getRotatingFileSink = exports.getFileSink = exports.reset = exports.getConfig = exports.dispose = exports.configure = exports.ConfigError = void 0;
|
|
4
4
|
var config_js_1 = require("./config.js");
|
|
5
5
|
Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_js_1.ConfigError; } });
|
|
6
6
|
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return config_js_1.configure; } });
|
|
7
7
|
Object.defineProperty(exports, "dispose", { enumerable: true, get: function () { return config_js_1.dispose; } });
|
|
8
|
+
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_js_1.getConfig; } });
|
|
8
9
|
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return config_js_1.reset; } });
|
|
9
10
|
var filesink_node_js_1 = require("./filesink.node.js");
|
|
10
11
|
Object.defineProperty(exports, "getFileSink", { enumerable: true, get: function () { return filesink_node_js_1.getFileSink; } });
|
|
@@ -15,9 +16,13 @@ Object.defineProperty(exports, "toFilter", { enumerable: true, get: function ()
|
|
|
15
16
|
var formatter_js_1 = require("./formatter.js");
|
|
16
17
|
Object.defineProperty(exports, "defaultConsoleFormatter", { enumerable: true, get: function () { return formatter_js_1.defaultConsoleFormatter; } });
|
|
17
18
|
Object.defineProperty(exports, "defaultTextFormatter", { enumerable: true, get: function () { return formatter_js_1.defaultTextFormatter; } });
|
|
19
|
+
var level_js_1 = require("./level.js");
|
|
20
|
+
Object.defineProperty(exports, "isLogLevel", { enumerable: true, get: function () { return level_js_1.isLogLevel; } });
|
|
21
|
+
Object.defineProperty(exports, "parseLogLevel", { enumerable: true, get: function () { return level_js_1.parseLogLevel; } });
|
|
18
22
|
var logger_js_1 = require("./logger.js");
|
|
19
23
|
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_js_1.getLogger; } });
|
|
20
24
|
var sink_js_1 = require("./sink.js");
|
|
21
25
|
Object.defineProperty(exports, "getConsoleSink", { enumerable: true, get: function () { return sink_js_1.getConsoleSink; } });
|
|
22
26
|
Object.defineProperty(exports, "getStreamSink", { enumerable: true, get: function () { return sink_js_1.getStreamSink; } });
|
|
27
|
+
Object.defineProperty(exports, "withFilter", { enumerable: true, get: function () { return sink_js_1.withFilter; } });
|
|
23
28
|
// cSpell: ignore filesink
|
package/script/sink.js
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRotatingFileSink = exports.getFileSink = exports.getConsoleSink = exports.getStreamSink = void 0;
|
|
3
|
+
exports.getRotatingFileSink = exports.getFileSink = exports.getConsoleSink = exports.getStreamSink = exports.withFilter = void 0;
|
|
4
|
+
const filter_js_1 = require("./filter.js");
|
|
4
5
|
const formatter_js_1 = require("./formatter.js");
|
|
6
|
+
/**
|
|
7
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
8
|
+
* pass the filter.
|
|
9
|
+
*
|
|
10
|
+
* @example Filter a console sink to only log records with the info level
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param sink A sink to be filtered.
|
|
16
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
17
|
+
* function or a {@link LogLevel} string.
|
|
18
|
+
* @returns A sink that only logs records that pass the filter.
|
|
19
|
+
*/
|
|
20
|
+
function withFilter(sink, filter) {
|
|
21
|
+
const filterFunc = (0, filter_js_1.toFilter)(filter);
|
|
22
|
+
return (record) => {
|
|
23
|
+
if (filterFunc(record))
|
|
24
|
+
sink(record);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.withFilter = withFilter;
|
|
5
28
|
/**
|
|
6
29
|
* A factory that returns a sink that writes to a {@link WritableStream}.
|
|
7
30
|
*
|
package/types/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FilterLike } from "./filter.js";
|
|
2
|
-
import type { LogLevel } from "./
|
|
2
|
+
import type { LogLevel } from "./level.js";
|
|
3
3
|
import { type Sink } from "./sink.js";
|
|
4
4
|
/**
|
|
5
5
|
* A configuration for the loggers.
|
|
@@ -87,6 +87,11 @@ export interface LoggerConfig<TSinkId extends string, TFilterId extends string>
|
|
|
87
87
|
* @param config The configuration.
|
|
88
88
|
*/
|
|
89
89
|
export declare function configure<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get the current configuration, if any. Otherwise, `null`.
|
|
92
|
+
* @returns The current configuration, if any. Otherwise, `null`.
|
|
93
|
+
*/
|
|
94
|
+
export declare function getConfig(): Config<string, string> | null;
|
|
90
95
|
/**
|
|
91
96
|
* Reset the configuration. Mostly for testing purposes.
|
|
92
97
|
*/
|
package/types/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,MAAM,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IACtE;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAEvC;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IAE5C;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,OAAO,SAAS,MAAM,EACtB,SAAS,SAAS,MAAM;IAExB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CACzB;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,SAAS,CAC7B,OAAO,SAAS,MAAM,EACtB,SAAS,SAAS,MAAM,EACxB,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA+EnD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAEzD;AAED;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAK3C;AAED;;GAEG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAS7C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B"}
|
package/types/filter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { LogLevel
|
|
1
|
+
import type { LogLevel } from "./level.js";
|
|
2
|
+
import type { LogRecord } from "./record.js";
|
|
2
3
|
/**
|
|
3
4
|
* A filter is a function that accepts a log record and returns `true` if the
|
|
4
5
|
* record should be passed to the sink.
|
package/types/filter.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;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"}
|
package/types/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;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,CA2B7E"}
|
package/types/level.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The severity level of a {@link LogRecord}.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = "debug" | "info" | "warning" | "error" | "fatal";
|
|
5
|
+
/**
|
|
6
|
+
* Parses a log level from a string.
|
|
7
|
+
*
|
|
8
|
+
* @param level The log level as a string. This is case-insensitive.
|
|
9
|
+
* @returns The log level.
|
|
10
|
+
* @throws {TypeError} If the log level is invalid.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseLogLevel(level: string): LogLevel;
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a string is a valid log level. This function can be used as
|
|
15
|
+
* as a type guard to narrow the type of a string to a {@link LogLevel}.
|
|
16
|
+
*
|
|
17
|
+
* @param level The log level as a string. This is case-sensitive.
|
|
18
|
+
* @returns `true` if the string is a valid log level.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isLogLevel(level: string): level is LogLevel;
|
|
21
|
+
//# sourceMappingURL=level.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../src/level.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAYrD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,QAAQ,CAW3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.test.d.ts","sourceRoot":"","sources":["../src/level.test.ts"],"names":[],"mappings":""}
|
package/types/logger.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Filter } from "./filter.js";
|
|
2
|
-
import type { LogLevel
|
|
2
|
+
import type { LogLevel } from "./level.js";
|
|
3
|
+
import type { LogRecord } from "./record.js";
|
|
3
4
|
import type { Sink } from "./sink.js";
|
|
4
5
|
/**
|
|
5
6
|
* A logger interface. It provides methods to log messages at different
|
package/types/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA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AKG;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"}
|
package/types/mod.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export { type Config, ConfigError, configure, dispose, type LoggerConfig, reset, } from "./config.js";
|
|
1
|
+
export { type Config, ConfigError, configure, dispose, getConfig, type LoggerConfig, reset, } from "./config.js";
|
|
2
2
|
export { getFileSink, getRotatingFileSink } from "./filesink.node.js";
|
|
3
3
|
export { type Filter, type FilterLike, getLevelFilter, toFilter, } from "./filter.js";
|
|
4
4
|
export { type ConsoleFormatter, defaultConsoleFormatter, defaultTextFormatter, type TextFormatter, } from "./formatter.js";
|
|
5
|
+
export { isLogLevel, type LogLevel, parseLogLevel } from "./level.js";
|
|
5
6
|
export { getLogger, type Logger } from "./logger.js";
|
|
6
|
-
export type {
|
|
7
|
-
export { type ConsoleSinkOptions, type FileSinkOptions, getConsoleSink, getStreamSink, type RotatingFileSinkOptions, type Sink, type StreamSinkOptions, } from "./sink.js";
|
|
7
|
+
export type { LogRecord } from "./record.js";
|
|
8
|
+
export { type ConsoleSinkOptions, type FileSinkOptions, getConsoleSink, getStreamSink, type RotatingFileSinkOptions, type Sink, type StreamSinkOptions, withFilter, } from "./sink.js";
|
|
8
9
|
//# sourceMappingURL=mod.d.ts.map
|
package/types/mod.d.ts.map
CHANGED
|
@@ -1 +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,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,cAAc,EACd,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,cAAc,EACd,aAAa,EACb,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACT,KAAK,iBAAiB,EACtB,UAAU,GACX,MAAM,WAAW,CAAC"}
|
package/types/record.d.ts
CHANGED
package/types/record.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/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;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C"}
|
package/types/sink.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import * as dntShim from "./_dnt.shims.js";
|
|
5
|
+
import { type FilterLike } from "./filter.js";
|
|
5
6
|
import { type ConsoleFormatter, type TextFormatter } from "./formatter.js";
|
|
6
7
|
import type { LogRecord } from "./record.js";
|
|
7
8
|
/**
|
|
@@ -14,6 +15,21 @@ import type { LogRecord } from "./record.js";
|
|
|
14
15
|
* @param record The log record to sink.
|
|
15
16
|
*/
|
|
16
17
|
export type Sink = (record: LogRecord) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
20
|
+
* pass the filter.
|
|
21
|
+
*
|
|
22
|
+
* @example Filter a console sink to only log records with the info level
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param sink A sink to be filtered.
|
|
28
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
29
|
+
* function or a {@link LogLevel} string.
|
|
30
|
+
* @returns A sink that only logs records that pass the filter.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withFilter(sink: Sink, filter: FilterLike): Sink;
|
|
17
33
|
/**
|
|
18
34
|
* Options for the {@link getStreamSink} function.
|
|
19
35
|
*/
|
package/types/sink.d.ts.map
CHANGED
|
@@ -1 +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;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;OAEG;IACH,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,CAAC,cAAc,EAC9B,OAAO,GAAE,iBAAsB,GAC9B,IAAI,GAAG,eAAe,CAgBxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAE7B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAuB,GAAG,IAAI,CAYrE;AA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