@logtape/logtape 0.9.0-dev.123 → 0.9.0-dev.128
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/esm/config.js +112 -17
- package/esm/mod.js +1 -1
- package/package.json +1 -1
- package/script/config.js +115 -17
- package/script/mod.js +4 -1
- package/types/config.d.ts +46 -0
- package/types/config.d.ts.map +1 -1
- package/types/mod.d.ts +1 -1
- package/types/mod.d.ts.map +1 -1
package/esm/config.js
CHANGED
|
@@ -20,6 +20,16 @@ const disposables = new Set();
|
|
|
20
20
|
* Async disposables to dispose when resetting the configuration.
|
|
21
21
|
*/
|
|
22
22
|
const asyncDisposables = new Set();
|
|
23
|
+
/**
|
|
24
|
+
* Check if a config is for the meta logger.
|
|
25
|
+
*/
|
|
26
|
+
function isLoggerConfigMeta(cfg) {
|
|
27
|
+
return cfg.category.length === 0 ||
|
|
28
|
+
(cfg.category.length === 1 && cfg.category[0] === "logtape") ||
|
|
29
|
+
(cfg.category.length === 2 &&
|
|
30
|
+
cfg.category[0] === "logtape" &&
|
|
31
|
+
cfg.category[1] === "meta");
|
|
32
|
+
}
|
|
23
33
|
/**
|
|
24
34
|
* Configure the loggers with the specified configuration.
|
|
25
35
|
*
|
|
@@ -64,22 +74,78 @@ export async function configure(config) {
|
|
|
64
74
|
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
65
75
|
}
|
|
66
76
|
await reset();
|
|
77
|
+
try {
|
|
78
|
+
configureInternal(config, true);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
if (e instanceof ConfigError)
|
|
82
|
+
await reset();
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Configure sync loggers with the specified configuration.
|
|
88
|
+
*
|
|
89
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
90
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
91
|
+
*
|
|
92
|
+
* Also note that passing async sinks or filters will throw. If
|
|
93
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* configureSync({
|
|
98
|
+
* sinks: {
|
|
99
|
+
* console: getConsoleSink(),
|
|
100
|
+
* },
|
|
101
|
+
* loggers: [
|
|
102
|
+
* {
|
|
103
|
+
* category: "my-app",
|
|
104
|
+
* sinks: ["console"],
|
|
105
|
+
* level: "info",
|
|
106
|
+
* },
|
|
107
|
+
* {
|
|
108
|
+
* category: "logtape",
|
|
109
|
+
* sinks: ["console"],
|
|
110
|
+
* level: "error",
|
|
111
|
+
* },
|
|
112
|
+
* ],
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param config The configuration.
|
|
117
|
+
* @since 0.9.0
|
|
118
|
+
*/
|
|
119
|
+
export function configureSync(config) {
|
|
120
|
+
if (currentConfig != null && !config.reset) {
|
|
121
|
+
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
122
|
+
}
|
|
123
|
+
if (asyncDisposables.size > 0) {
|
|
124
|
+
throw new ConfigError("Previously configured async disposables are still active. " +
|
|
125
|
+
"Use configure() instead or explicitly dispose them using dispose().");
|
|
126
|
+
}
|
|
127
|
+
resetSync();
|
|
128
|
+
try {
|
|
129
|
+
configureInternal(config, false);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
if (e instanceof ConfigError)
|
|
133
|
+
resetSync();
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function configureInternal(config, allowAsync) {
|
|
67
138
|
currentConfig = config;
|
|
68
139
|
let metaConfigured = false;
|
|
69
140
|
let levelUsed = false;
|
|
70
141
|
for (const cfg of config.loggers) {
|
|
71
|
-
if (cfg
|
|
72
|
-
(cfg.category.length === 1 && cfg.category[0] === "logtape") ||
|
|
73
|
-
(cfg.category.length === 2 &&
|
|
74
|
-
cfg.category[0] === "logtape" &&
|
|
75
|
-
cfg.category[1] === "meta")) {
|
|
142
|
+
if (isLoggerConfigMeta(cfg)) {
|
|
76
143
|
metaConfigured = true;
|
|
77
144
|
}
|
|
78
145
|
const logger = LoggerImpl.getLogger(cfg.category);
|
|
79
146
|
for (const sinkId of cfg.sinks ?? []) {
|
|
80
147
|
const sink = config.sinks[sinkId];
|
|
81
148
|
if (!sink) {
|
|
82
|
-
await reset();
|
|
83
149
|
throw new ConfigError(`Sink not found: ${sinkId}.`);
|
|
84
150
|
}
|
|
85
151
|
logger.sinks.push(sink);
|
|
@@ -95,7 +161,6 @@ export async function configure(config) {
|
|
|
95
161
|
for (const filterId of cfg.filters ?? []) {
|
|
96
162
|
const filter = config.filters?.[filterId];
|
|
97
163
|
if (filter === undefined) {
|
|
98
|
-
await reset();
|
|
99
164
|
throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
100
165
|
}
|
|
101
166
|
logger.filters.push(toFilter(filter));
|
|
@@ -105,7 +170,11 @@ export async function configure(config) {
|
|
|
105
170
|
LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
106
171
|
for (const sink of Object.values(config.sinks)) {
|
|
107
172
|
if (Symbol.asyncDispose in sink) {
|
|
108
|
-
|
|
173
|
+
if (allowAsync)
|
|
174
|
+
asyncDisposables.add(sink);
|
|
175
|
+
else {
|
|
176
|
+
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
177
|
+
}
|
|
109
178
|
}
|
|
110
179
|
if (Symbol.dispose in sink)
|
|
111
180
|
disposables.add(sink);
|
|
@@ -114,17 +183,23 @@ export async function configure(config) {
|
|
|
114
183
|
if (filter == null || typeof filter === "string")
|
|
115
184
|
continue;
|
|
116
185
|
if (Symbol.asyncDispose in filter) {
|
|
117
|
-
|
|
186
|
+
if (allowAsync)
|
|
187
|
+
asyncDisposables.add(filter);
|
|
188
|
+
else {
|
|
189
|
+
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
190
|
+
}
|
|
118
191
|
}
|
|
119
192
|
if (Symbol.dispose in filter)
|
|
120
193
|
disposables.add(filter);
|
|
121
194
|
}
|
|
122
|
-
if ("process" in dntShim.dntGlobalThis && !("Deno" in dntShim.dntGlobalThis)) {
|
|
123
|
-
//
|
|
124
|
-
process
|
|
195
|
+
if ("process" in dntShim.dntGlobalThis && !("Deno" in dntShim.dntGlobalThis)) {
|
|
196
|
+
// @ts-ignore: It's fine to use process in Node
|
|
197
|
+
// deno-lint-ignore no-process-global
|
|
198
|
+
process.on("exit", allowAsync ? dispose : disposeSync);
|
|
125
199
|
}
|
|
126
|
-
else {
|
|
127
|
-
addEventListener(
|
|
200
|
+
else {
|
|
201
|
+
// @ts-ignore: It's fine to addEventListener() on the browser/Deno
|
|
202
|
+
addEventListener("unload", allowAsync ? dispose : disposeSync);
|
|
128
203
|
}
|
|
129
204
|
const meta = LoggerImpl.getLogger(["logtape", "meta"]);
|
|
130
205
|
if (!metaConfigured) {
|
|
@@ -157,6 +232,18 @@ export function getConfig() {
|
|
|
157
232
|
*/
|
|
158
233
|
export async function reset() {
|
|
159
234
|
await dispose();
|
|
235
|
+
resetInternal();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
239
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
240
|
+
* @since 0.9.0
|
|
241
|
+
*/
|
|
242
|
+
export function resetSync() {
|
|
243
|
+
disposeSync();
|
|
244
|
+
resetInternal();
|
|
245
|
+
}
|
|
246
|
+
function resetInternal() {
|
|
160
247
|
const rootLogger = LoggerImpl.getLogger([]);
|
|
161
248
|
rootLogger.resetDescendants();
|
|
162
249
|
delete rootLogger.contextLocalStorage;
|
|
@@ -167,9 +254,7 @@ export async function reset() {
|
|
|
167
254
|
* Dispose of the disposables.
|
|
168
255
|
*/
|
|
169
256
|
export async function dispose() {
|
|
170
|
-
|
|
171
|
-
disposable[Symbol.dispose]();
|
|
172
|
-
disposables.clear();
|
|
257
|
+
disposeSync();
|
|
173
258
|
const promises = [];
|
|
174
259
|
for (const disposable of asyncDisposables) {
|
|
175
260
|
promises.push(disposable[Symbol.asyncDispose]());
|
|
@@ -177,6 +262,16 @@ export async function dispose() {
|
|
|
177
262
|
}
|
|
178
263
|
await Promise.all(promises);
|
|
179
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
267
|
+
* use {@link dispose} if you have async sinks.
|
|
268
|
+
* @since 0.9.0
|
|
269
|
+
*/
|
|
270
|
+
export function disposeSync() {
|
|
271
|
+
for (const disposable of disposables)
|
|
272
|
+
disposable[Symbol.dispose]();
|
|
273
|
+
disposables.clear();
|
|
274
|
+
}
|
|
180
275
|
/**
|
|
181
276
|
* A configuration error.
|
|
182
277
|
*/
|
package/esm/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ConfigError, configure, dispose, getConfig, reset, } from "./config.js";
|
|
1
|
+
export { ConfigError, configure, configureSync, dispose, disposeSync, getConfig, reset, resetSync, } from "./config.js";
|
|
2
2
|
export { withContext } from "./context.js";
|
|
3
3
|
export { getFileSink, getRotatingFileSink } from "./filesink.node.js";
|
|
4
4
|
export { getLevelFilter, toFilter, } from "./filter.js";
|
package/package.json
CHANGED
package/script/config.js
CHANGED
|
@@ -25,9 +25,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ConfigError = void 0;
|
|
27
27
|
exports.configure = configure;
|
|
28
|
+
exports.configureSync = configureSync;
|
|
28
29
|
exports.getConfig = getConfig;
|
|
29
30
|
exports.reset = reset;
|
|
31
|
+
exports.resetSync = resetSync;
|
|
30
32
|
exports.dispose = dispose;
|
|
33
|
+
exports.disposeSync = disposeSync;
|
|
31
34
|
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
32
35
|
const filter_js_1 = require("./filter.js");
|
|
33
36
|
const logger_js_1 = require("./logger.js");
|
|
@@ -50,6 +53,16 @@ const disposables = new Set();
|
|
|
50
53
|
* Async disposables to dispose when resetting the configuration.
|
|
51
54
|
*/
|
|
52
55
|
const asyncDisposables = new Set();
|
|
56
|
+
/**
|
|
57
|
+
* Check if a config is for the meta logger.
|
|
58
|
+
*/
|
|
59
|
+
function isLoggerConfigMeta(cfg) {
|
|
60
|
+
return cfg.category.length === 0 ||
|
|
61
|
+
(cfg.category.length === 1 && cfg.category[0] === "logtape") ||
|
|
62
|
+
(cfg.category.length === 2 &&
|
|
63
|
+
cfg.category[0] === "logtape" &&
|
|
64
|
+
cfg.category[1] === "meta");
|
|
65
|
+
}
|
|
53
66
|
/**
|
|
54
67
|
* Configure the loggers with the specified configuration.
|
|
55
68
|
*
|
|
@@ -94,22 +107,78 @@ async function configure(config) {
|
|
|
94
107
|
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
95
108
|
}
|
|
96
109
|
await reset();
|
|
110
|
+
try {
|
|
111
|
+
configureInternal(config, true);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
if (e instanceof ConfigError)
|
|
115
|
+
await reset();
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Configure sync loggers with the specified configuration.
|
|
121
|
+
*
|
|
122
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
123
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
124
|
+
*
|
|
125
|
+
* Also note that passing async sinks or filters will throw. If
|
|
126
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* configureSync({
|
|
131
|
+
* sinks: {
|
|
132
|
+
* console: getConsoleSink(),
|
|
133
|
+
* },
|
|
134
|
+
* loggers: [
|
|
135
|
+
* {
|
|
136
|
+
* category: "my-app",
|
|
137
|
+
* sinks: ["console"],
|
|
138
|
+
* level: "info",
|
|
139
|
+
* },
|
|
140
|
+
* {
|
|
141
|
+
* category: "logtape",
|
|
142
|
+
* sinks: ["console"],
|
|
143
|
+
* level: "error",
|
|
144
|
+
* },
|
|
145
|
+
* ],
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @param config The configuration.
|
|
150
|
+
* @since 0.9.0
|
|
151
|
+
*/
|
|
152
|
+
function configureSync(config) {
|
|
153
|
+
if (currentConfig != null && !config.reset) {
|
|
154
|
+
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
155
|
+
}
|
|
156
|
+
if (asyncDisposables.size > 0) {
|
|
157
|
+
throw new ConfigError("Previously configured async disposables are still active. " +
|
|
158
|
+
"Use configure() instead or explicitly dispose them using dispose().");
|
|
159
|
+
}
|
|
160
|
+
resetSync();
|
|
161
|
+
try {
|
|
162
|
+
configureInternal(config, false);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
if (e instanceof ConfigError)
|
|
166
|
+
resetSync();
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function configureInternal(config, allowAsync) {
|
|
97
171
|
currentConfig = config;
|
|
98
172
|
let metaConfigured = false;
|
|
99
173
|
let levelUsed = false;
|
|
100
174
|
for (const cfg of config.loggers) {
|
|
101
|
-
if (cfg
|
|
102
|
-
(cfg.category.length === 1 && cfg.category[0] === "logtape") ||
|
|
103
|
-
(cfg.category.length === 2 &&
|
|
104
|
-
cfg.category[0] === "logtape" &&
|
|
105
|
-
cfg.category[1] === "meta")) {
|
|
175
|
+
if (isLoggerConfigMeta(cfg)) {
|
|
106
176
|
metaConfigured = true;
|
|
107
177
|
}
|
|
108
178
|
const logger = logger_js_1.LoggerImpl.getLogger(cfg.category);
|
|
109
179
|
for (const sinkId of cfg.sinks ?? []) {
|
|
110
180
|
const sink = config.sinks[sinkId];
|
|
111
181
|
if (!sink) {
|
|
112
|
-
await reset();
|
|
113
182
|
throw new ConfigError(`Sink not found: ${sinkId}.`);
|
|
114
183
|
}
|
|
115
184
|
logger.sinks.push(sink);
|
|
@@ -125,7 +194,6 @@ async function configure(config) {
|
|
|
125
194
|
for (const filterId of cfg.filters ?? []) {
|
|
126
195
|
const filter = config.filters?.[filterId];
|
|
127
196
|
if (filter === undefined) {
|
|
128
|
-
await reset();
|
|
129
197
|
throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
130
198
|
}
|
|
131
199
|
logger.filters.push((0, filter_js_1.toFilter)(filter));
|
|
@@ -135,7 +203,11 @@ async function configure(config) {
|
|
|
135
203
|
logger_js_1.LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
136
204
|
for (const sink of Object.values(config.sinks)) {
|
|
137
205
|
if (Symbol.asyncDispose in sink) {
|
|
138
|
-
|
|
206
|
+
if (allowAsync)
|
|
207
|
+
asyncDisposables.add(sink);
|
|
208
|
+
else {
|
|
209
|
+
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
210
|
+
}
|
|
139
211
|
}
|
|
140
212
|
if (Symbol.dispose in sink)
|
|
141
213
|
disposables.add(sink);
|
|
@@ -144,17 +216,23 @@ async function configure(config) {
|
|
|
144
216
|
if (filter == null || typeof filter === "string")
|
|
145
217
|
continue;
|
|
146
218
|
if (Symbol.asyncDispose in filter) {
|
|
147
|
-
|
|
219
|
+
if (allowAsync)
|
|
220
|
+
asyncDisposables.add(filter);
|
|
221
|
+
else {
|
|
222
|
+
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
223
|
+
}
|
|
148
224
|
}
|
|
149
225
|
if (Symbol.dispose in filter)
|
|
150
226
|
disposables.add(filter);
|
|
151
227
|
}
|
|
152
|
-
if ("process" in dntShim.dntGlobalThis && !("Deno" in dntShim.dntGlobalThis)) {
|
|
153
|
-
//
|
|
154
|
-
process
|
|
228
|
+
if ("process" in dntShim.dntGlobalThis && !("Deno" in dntShim.dntGlobalThis)) {
|
|
229
|
+
// @ts-ignore: It's fine to use process in Node
|
|
230
|
+
// deno-lint-ignore no-process-global
|
|
231
|
+
process.on("exit", allowAsync ? dispose : disposeSync);
|
|
155
232
|
}
|
|
156
|
-
else {
|
|
157
|
-
addEventListener(
|
|
233
|
+
else {
|
|
234
|
+
// @ts-ignore: It's fine to addEventListener() on the browser/Deno
|
|
235
|
+
addEventListener("unload", allowAsync ? dispose : disposeSync);
|
|
158
236
|
}
|
|
159
237
|
const meta = logger_js_1.LoggerImpl.getLogger(["logtape", "meta"]);
|
|
160
238
|
if (!metaConfigured) {
|
|
@@ -187,6 +265,18 @@ function getConfig() {
|
|
|
187
265
|
*/
|
|
188
266
|
async function reset() {
|
|
189
267
|
await dispose();
|
|
268
|
+
resetInternal();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
272
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
273
|
+
* @since 0.9.0
|
|
274
|
+
*/
|
|
275
|
+
function resetSync() {
|
|
276
|
+
disposeSync();
|
|
277
|
+
resetInternal();
|
|
278
|
+
}
|
|
279
|
+
function resetInternal() {
|
|
190
280
|
const rootLogger = logger_js_1.LoggerImpl.getLogger([]);
|
|
191
281
|
rootLogger.resetDescendants();
|
|
192
282
|
delete rootLogger.contextLocalStorage;
|
|
@@ -197,9 +287,7 @@ async function reset() {
|
|
|
197
287
|
* Dispose of the disposables.
|
|
198
288
|
*/
|
|
199
289
|
async function dispose() {
|
|
200
|
-
|
|
201
|
-
disposable[Symbol.dispose]();
|
|
202
|
-
disposables.clear();
|
|
290
|
+
disposeSync();
|
|
203
291
|
const promises = [];
|
|
204
292
|
for (const disposable of asyncDisposables) {
|
|
205
293
|
promises.push(disposable[Symbol.asyncDispose]());
|
|
@@ -207,6 +295,16 @@ async function dispose() {
|
|
|
207
295
|
}
|
|
208
296
|
await Promise.all(promises);
|
|
209
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
300
|
+
* use {@link dispose} if you have async sinks.
|
|
301
|
+
* @since 0.9.0
|
|
302
|
+
*/
|
|
303
|
+
function disposeSync() {
|
|
304
|
+
for (const disposable of disposables)
|
|
305
|
+
disposable[Symbol.dispose]();
|
|
306
|
+
disposables.clear();
|
|
307
|
+
}
|
|
210
308
|
/**
|
|
211
309
|
* A configuration error.
|
|
212
310
|
*/
|
package/script/mod.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withFilter = exports.getStreamSink = exports.getConsoleSink = exports.getLogger = exports.parseLogLevel = exports.isLogLevel = exports.compareLogLevel = exports.getTextFormatter = exports.getAnsiColorFormatter = exports.defaultTextFormatter = exports.defaultConsoleFormatter = exports.ansiColorFormatter = exports.toFilter = exports.getLevelFilter = exports.getRotatingFileSink = exports.getFileSink = exports.withContext = exports.reset = exports.getConfig = exports.dispose = exports.configure = exports.ConfigError = void 0;
|
|
3
|
+
exports.withFilter = exports.getStreamSink = exports.getConsoleSink = exports.getLogger = exports.parseLogLevel = exports.isLogLevel = exports.compareLogLevel = exports.getTextFormatter = exports.getAnsiColorFormatter = exports.defaultTextFormatter = exports.defaultConsoleFormatter = exports.ansiColorFormatter = exports.toFilter = exports.getLevelFilter = exports.getRotatingFileSink = exports.getFileSink = exports.withContext = exports.resetSync = exports.reset = exports.getConfig = exports.disposeSync = exports.dispose = exports.configureSync = 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
|
+
Object.defineProperty(exports, "configureSync", { enumerable: true, get: function () { return config_js_1.configureSync; } });
|
|
7
8
|
Object.defineProperty(exports, "dispose", { enumerable: true, get: function () { return config_js_1.dispose; } });
|
|
9
|
+
Object.defineProperty(exports, "disposeSync", { enumerable: true, get: function () { return config_js_1.disposeSync; } });
|
|
8
10
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_js_1.getConfig; } });
|
|
9
11
|
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return config_js_1.reset; } });
|
|
12
|
+
Object.defineProperty(exports, "resetSync", { enumerable: true, get: function () { return config_js_1.resetSync; } });
|
|
10
13
|
var context_js_1 = require("./context.js");
|
|
11
14
|
Object.defineProperty(exports, "withContext", { enumerable: true, get: function () { return context_js_1.withContext; } });
|
|
12
15
|
var filesink_node_js_1 = require("./filesink.node.js");
|
package/types/config.d.ts
CHANGED
|
@@ -111,6 +111,40 @@ export interface LoggerConfig<TSinkId extends string, TFilterId extends string>
|
|
|
111
111
|
* @param config The configuration.
|
|
112
112
|
*/
|
|
113
113
|
export declare function configure<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Configure sync loggers with the specified configuration.
|
|
116
|
+
*
|
|
117
|
+
* Note that if the given sinks or filters are disposable, they will be
|
|
118
|
+
* disposed when the configuration is reset, or when the process exits.
|
|
119
|
+
*
|
|
120
|
+
* Also note that passing async sinks or filters will throw. If
|
|
121
|
+
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* configureSync({
|
|
126
|
+
* sinks: {
|
|
127
|
+
* console: getConsoleSink(),
|
|
128
|
+
* },
|
|
129
|
+
* loggers: [
|
|
130
|
+
* {
|
|
131
|
+
* category: "my-app",
|
|
132
|
+
* sinks: ["console"],
|
|
133
|
+
* level: "info",
|
|
134
|
+
* },
|
|
135
|
+
* {
|
|
136
|
+
* category: "logtape",
|
|
137
|
+
* sinks: ["console"],
|
|
138
|
+
* level: "error",
|
|
139
|
+
* },
|
|
140
|
+
* ],
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @param config The configuration.
|
|
145
|
+
* @since 0.9.0
|
|
146
|
+
*/
|
|
147
|
+
export declare function configureSync<TSinkId extends string, TFilterId extends string>(config: Config<TSinkId, TFilterId>): void;
|
|
114
148
|
/**
|
|
115
149
|
* Get the current configuration, if any. Otherwise, `null`.
|
|
116
150
|
* @returns The current configuration, if any. Otherwise, `null`.
|
|
@@ -120,10 +154,22 @@ export declare function getConfig(): Config<string, string> | null;
|
|
|
120
154
|
* Reset the configuration. Mostly for testing purposes.
|
|
121
155
|
*/
|
|
122
156
|
export declare function reset(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
159
|
+
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
160
|
+
* @since 0.9.0
|
|
161
|
+
*/
|
|
162
|
+
export declare function resetSync(): void;
|
|
123
163
|
/**
|
|
124
164
|
* Dispose of the disposables.
|
|
125
165
|
*/
|
|
126
166
|
export declare function dispose(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
169
|
+
* use {@link dispose} if you have async sinks.
|
|
170
|
+
* @since 0.9.0
|
|
171
|
+
*/
|
|
172
|
+
export declare function disposeSync(): void;
|
|
127
173
|
/**
|
|
128
174
|
* A configuration error.
|
|
129
175
|
*/
|
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,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAkB,KAAK,IAAI,EAA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AAgB,aAAa,CAAC,OAAO,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM,EAC5E,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,GACjC,IAAI,CAmBN;AAuGD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAEzD;AAED;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAGhC;AAUD;;GAEG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ7C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI5B"}
|
package/types/mod.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type Config, ConfigError, configure, dispose, getConfig, type LoggerConfig, reset, } from "./config.js";
|
|
1
|
+
export { type Config, ConfigError, configure, configureSync, dispose, disposeSync, getConfig, type LoggerConfig, reset, resetSync, } from "./config.js";
|
|
2
2
|
export { type ContextLocalStorage, withContext } from "./context.js";
|
|
3
3
|
export { getFileSink, getRotatingFileSink } from "./filesink.node.js";
|
|
4
4
|
export { type Filter, type FilterLike, getLevelFilter, toFilter, } from "./filter.js";
|
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,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/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,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,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,KAAK,eAAe,EACpB,cAAc,EACd,aAAa,EACb,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACT,KAAK,iBAAiB,EACtB,UAAU,GACX,MAAM,WAAW,CAAC"}
|