@logtape/file 0.10.0-dev.148 → 0.10.0-dev.155
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/file/filesink.base.js +1 -1
- package/package.json +4 -1
- package/script/file/filesink.base.js +3 -3
- package/types/file/filesink.base.d.ts +1 -1
- package/types/file/filesink.base.d.ts.map +1 -1
- package/types/file/filesink.node.d.ts +1 -1
- package/types/file/filesink.node.d.ts.map +1 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/logtape/config.js +0 -287
- package/esm/logtape/context.js +0 -23
- package/esm/logtape/filter.js +0 -42
- package/esm/logtape/formatter.js +0 -263
- package/esm/logtape/level.js +0 -59
- package/esm/logtape/logger.js +0 -480
- package/esm/logtape/mod.js +0 -8
- package/esm/logtape/nodeUtil.js +0 -2
- package/esm/logtape/record.js +0 -1
- package/esm/logtape/sink.js +0 -96
- package/script/_dnt.shims.js +0 -60
- package/script/logtape/config.js +0 -321
- package/script/logtape/context.js +0 -26
- package/script/logtape/filter.js +0 -46
- package/script/logtape/formatter.js +0 -272
- package/script/logtape/level.js +0 -64
- package/script/logtape/logger.js +0 -511
- package/script/logtape/mod.js +0 -34
- package/script/logtape/nodeUtil.js +0 -7
- package/script/logtape/record.js +0 -2
- package/script/logtape/sink.js +0 -101
- package/types/_dnt.shims.d.ts +0 -2
- package/types/_dnt.shims.d.ts.map +0 -1
- package/types/logtape/config.d.ts +0 -183
- package/types/logtape/config.d.ts.map +0 -1
- package/types/logtape/context.d.ts +0 -35
- package/types/logtape/context.d.ts.map +0 -1
- package/types/logtape/filter.d.ts +0 -31
- package/types/logtape/filter.d.ts.map +0 -1
- package/types/logtape/formatter.d.ts +0 -261
- package/types/logtape/formatter.d.ts.map +0 -1
- package/types/logtape/level.d.ts +0 -32
- package/types/logtape/logger.d.ts +0 -423
- package/types/logtape/logger.d.ts.map +0 -1
- package/types/logtape/mod.d.ts +0 -9
- package/types/logtape/mod.d.ts.map +0 -1
- package/types/logtape/nodeUtil.d.ts +0 -3
- package/types/logtape/nodeUtil.d.ts.map +0 -1
- package/types/logtape/record.d.ts +0 -44
- package/types/logtape/sink.d.ts +0 -108
- package/types/logtape/sink.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/file",
|
|
3
|
-
"version": "0.10.0-dev.
|
|
3
|
+
"version": "0.10.0-dev.155+5ee37546",
|
|
4
4
|
"description": "File sink and rotating file sink for LogTape",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
"funding": [
|
|
47
47
|
"https://github.com/sponsors/dahlia"
|
|
48
48
|
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@logtape/logtape": "^0.10.0-dev.149"
|
|
51
|
+
},
|
|
49
52
|
"devDependencies": {
|
|
50
53
|
"@types/node": "^20.9.0",
|
|
51
54
|
"picocolors": "^1.0.0",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBaseFileSink = getBaseFileSink;
|
|
4
4
|
exports.getBaseRotatingFileSink = getBaseRotatingFileSink;
|
|
5
|
-
const
|
|
5
|
+
const logtape_1 = require("@logtape/logtape");
|
|
6
6
|
/**
|
|
7
7
|
* Get a platform-independent file sink.
|
|
8
8
|
*
|
|
@@ -13,7 +13,7 @@ const mod_js_1 = require("../logtape/mod.js");
|
|
|
13
13
|
* object that closes the file when disposed.
|
|
14
14
|
*/
|
|
15
15
|
function getBaseFileSink(path, options) {
|
|
16
|
-
const formatter = options.formatter ??
|
|
16
|
+
const formatter = options.formatter ?? logtape_1.defaultTextFormatter;
|
|
17
17
|
const encoder = options.encoder ?? new TextEncoder();
|
|
18
18
|
let fd = options.lazy ? null : options.openSync(path);
|
|
19
19
|
const sink = (record) => {
|
|
@@ -44,7 +44,7 @@ function getBaseFileSink(path, options) {
|
|
|
44
44
|
* object that closes the file when disposed.
|
|
45
45
|
*/
|
|
46
46
|
function getBaseRotatingFileSink(path, options) {
|
|
47
|
-
const formatter = options.formatter ??
|
|
47
|
+
const formatter = options.formatter ?? logtape_1.defaultTextFormatter;
|
|
48
48
|
const encoder = options.encoder ?? new TextEncoder();
|
|
49
49
|
const maxSize = options.maxSize ?? 1024 * 1024;
|
|
50
50
|
const maxFiles = options.maxFiles ?? 5;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesink.base.d.ts","sourceRoot":"","sources":["../../src/file/filesink.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,iBAAiB,EACvB,MAAM,
|
|
1
|
+
{"version":3,"file":"filesink.base.d.ts","sourceRoot":"","sources":["../../src/file/filesink.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IAChD;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK;IACnC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAE9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAE9C;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,KAAK,GAAG,IAAI,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,KAAK,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,GAAG,cAAc,CAAC,KAAK,CAAC,GAC/C,IAAI,GAAG,UAAU,CAiBnB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;IAC5E;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,CAAE,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC1E;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAEzC;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAC3C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAAG,sBAAsB,CAAC,KAAK,CAAC,GAC/D,IAAI,GAAG,UAAU,CAwCnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesink.node.d.ts","sourceRoot":"","sources":["../../src/file/filesink.node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"filesink.node.d.ts","sourceRoot":"","sources":["../../src/file/filesink.node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EACL,KAAK,eAAe,EAGpB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,sBAAsB,CAAC,MAAM,GAAG,IAAI,CAS5D,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,IAAI,GAAG,UAAU,CAEnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACpC,IAAI,GAAG,UAAU,CAEnB"}
|
package/esm/_dnt.shims.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const dntGlobals = {};
|
|
2
|
-
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
-
function createMergeProxy(baseObj, extObj) {
|
|
4
|
-
return new Proxy(baseObj, {
|
|
5
|
-
get(_target, prop, _receiver) {
|
|
6
|
-
if (prop in extObj) {
|
|
7
|
-
return extObj[prop];
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return baseObj[prop];
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
set(_target, prop, value) {
|
|
14
|
-
if (prop in extObj) {
|
|
15
|
-
delete extObj[prop];
|
|
16
|
-
}
|
|
17
|
-
baseObj[prop] = value;
|
|
18
|
-
return true;
|
|
19
|
-
},
|
|
20
|
-
deleteProperty(_target, prop) {
|
|
21
|
-
let success = false;
|
|
22
|
-
if (prop in extObj) {
|
|
23
|
-
delete extObj[prop];
|
|
24
|
-
success = true;
|
|
25
|
-
}
|
|
26
|
-
if (prop in baseObj) {
|
|
27
|
-
delete baseObj[prop];
|
|
28
|
-
success = true;
|
|
29
|
-
}
|
|
30
|
-
return success;
|
|
31
|
-
},
|
|
32
|
-
ownKeys(_target) {
|
|
33
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
-
const extKeysSet = new Set(extKeys);
|
|
36
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
-
},
|
|
38
|
-
defineProperty(_target, prop, desc) {
|
|
39
|
-
if (prop in extObj) {
|
|
40
|
-
delete extObj[prop];
|
|
41
|
-
}
|
|
42
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
-
if (prop in extObj) {
|
|
47
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
has(_target, prop) {
|
|
54
|
-
return prop in extObj || prop in baseObj;
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
package/esm/logtape/config.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
-
import { toFilter } from "./filter.js";
|
|
3
|
-
import { LoggerImpl } from "./logger.js";
|
|
4
|
-
import { getConsoleSink } from "./sink.js";
|
|
5
|
-
/**
|
|
6
|
-
* The current configuration, if any. Otherwise, `null`.
|
|
7
|
-
*/
|
|
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();
|
|
15
|
-
/**
|
|
16
|
-
* Disposables to dispose when resetting the configuration.
|
|
17
|
-
*/
|
|
18
|
-
const disposables = new Set();
|
|
19
|
-
/**
|
|
20
|
-
* Async disposables to dispose when resetting the configuration.
|
|
21
|
-
*/
|
|
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
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Configure the loggers with the specified configuration.
|
|
35
|
-
*
|
|
36
|
-
* Note that if the given sinks or filters are disposable, they will be
|
|
37
|
-
* disposed when the configuration is reset, or when the process exits.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* await configure({
|
|
42
|
-
* sinks: {
|
|
43
|
-
* console: getConsoleSink(),
|
|
44
|
-
* },
|
|
45
|
-
* filters: {
|
|
46
|
-
* slow: (log) =>
|
|
47
|
-
* "duration" in log.properties &&
|
|
48
|
-
* log.properties.duration as number > 1000,
|
|
49
|
-
* },
|
|
50
|
-
* loggers: [
|
|
51
|
-
* {
|
|
52
|
-
* category: "my-app",
|
|
53
|
-
* sinks: ["console"],
|
|
54
|
-
* level: "info",
|
|
55
|
-
* },
|
|
56
|
-
* {
|
|
57
|
-
* category: ["my-app", "sql"],
|
|
58
|
-
* filters: ["slow"],
|
|
59
|
-
* level: "debug",
|
|
60
|
-
* },
|
|
61
|
-
* {
|
|
62
|
-
* category: "logtape",
|
|
63
|
-
* sinks: ["console"],
|
|
64
|
-
* level: "error",
|
|
65
|
-
* },
|
|
66
|
-
* ],
|
|
67
|
-
* });
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @param config The configuration.
|
|
71
|
-
*/
|
|
72
|
-
export async function configure(config) {
|
|
73
|
-
if (currentConfig != null && !config.reset) {
|
|
74
|
-
throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
75
|
-
}
|
|
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) {
|
|
138
|
-
currentConfig = config;
|
|
139
|
-
let metaConfigured = false;
|
|
140
|
-
let levelUsed = false;
|
|
141
|
-
for (const cfg of config.loggers) {
|
|
142
|
-
if (isLoggerConfigMeta(cfg)) {
|
|
143
|
-
metaConfigured = true;
|
|
144
|
-
}
|
|
145
|
-
const logger = LoggerImpl.getLogger(cfg.category);
|
|
146
|
-
for (const sinkId of cfg.sinks ?? []) {
|
|
147
|
-
const sink = config.sinks[sinkId];
|
|
148
|
-
if (!sink) {
|
|
149
|
-
throw new ConfigError(`Sink not found: ${sinkId}.`);
|
|
150
|
-
}
|
|
151
|
-
logger.sinks.push(sink);
|
|
152
|
-
}
|
|
153
|
-
logger.parentSinks = cfg.parentSinks ?? "inherit";
|
|
154
|
-
if (cfg.lowestLevel !== undefined) {
|
|
155
|
-
logger.lowestLevel = cfg.lowestLevel;
|
|
156
|
-
}
|
|
157
|
-
if (cfg.level !== undefined) {
|
|
158
|
-
levelUsed = true;
|
|
159
|
-
logger.filters.push(toFilter(cfg.level));
|
|
160
|
-
}
|
|
161
|
-
for (const filterId of cfg.filters ?? []) {
|
|
162
|
-
const filter = config.filters?.[filterId];
|
|
163
|
-
if (filter === undefined) {
|
|
164
|
-
throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
165
|
-
}
|
|
166
|
-
logger.filters.push(toFilter(filter));
|
|
167
|
-
}
|
|
168
|
-
strongRefs.add(logger);
|
|
169
|
-
}
|
|
170
|
-
LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
171
|
-
for (const sink of Object.values(config.sinks)) {
|
|
172
|
-
if (Symbol.asyncDispose in sink) {
|
|
173
|
-
if (allowAsync)
|
|
174
|
-
asyncDisposables.add(sink);
|
|
175
|
-
else {
|
|
176
|
-
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (Symbol.dispose in sink)
|
|
180
|
-
disposables.add(sink);
|
|
181
|
-
}
|
|
182
|
-
for (const filter of Object.values(config.filters ?? {})) {
|
|
183
|
-
if (filter == null || typeof filter === "string")
|
|
184
|
-
continue;
|
|
185
|
-
if (Symbol.asyncDispose in filter) {
|
|
186
|
-
if (allowAsync)
|
|
187
|
-
asyncDisposables.add(filter);
|
|
188
|
-
else {
|
|
189
|
-
throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (Symbol.dispose in filter)
|
|
193
|
-
disposables.add(filter);
|
|
194
|
-
}
|
|
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);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// @ts-ignore: It's fine to addEventListener() on the browser/Deno
|
|
202
|
-
addEventListener("unload", allowAsync ? dispose : disposeSync);
|
|
203
|
-
}
|
|
204
|
-
const meta = LoggerImpl.getLogger(["logtape", "meta"]);
|
|
205
|
-
if (!metaConfigured) {
|
|
206
|
-
meta.sinks.push(getConsoleSink());
|
|
207
|
-
}
|
|
208
|
-
meta.info("LogTape loggers are configured. Note that LogTape itself uses the meta " +
|
|
209
|
-
"logger, which has category {metaLoggerCategory}. The meta logger " +
|
|
210
|
-
"purposes to log internal errors such as sink exceptions. If you " +
|
|
211
|
-
"are seeing this message, the meta logger is automatically configured. " +
|
|
212
|
-
"It's recommended to configure the meta logger with a separate sink " +
|
|
213
|
-
"so that you can easily notice if logging itself fails or is " +
|
|
214
|
-
"misconfigured. To turn off this message, configure the meta logger " +
|
|
215
|
-
"with higher log levels than {dismissLevel}. See also " +
|
|
216
|
-
"<https://logtape.org/manual/categories#meta-logger>.", { metaLoggerCategory: ["logtape", "meta"], dismissLevel: "info" });
|
|
217
|
-
if (levelUsed) {
|
|
218
|
-
meta.warn("The level option is deprecated in favor of lowestLevel option. " +
|
|
219
|
-
"Please update your configuration. See also " +
|
|
220
|
-
"<https://logtape.org/manual/levels#configuring-severity-levels>.");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Get the current configuration, if any. Otherwise, `null`.
|
|
225
|
-
* @returns The current configuration, if any. Otherwise, `null`.
|
|
226
|
-
*/
|
|
227
|
-
export function getConfig() {
|
|
228
|
-
return currentConfig;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Reset the configuration. Mostly for testing purposes.
|
|
232
|
-
*/
|
|
233
|
-
export async function reset() {
|
|
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() {
|
|
247
|
-
const rootLogger = LoggerImpl.getLogger([]);
|
|
248
|
-
rootLogger.resetDescendants();
|
|
249
|
-
delete rootLogger.contextLocalStorage;
|
|
250
|
-
strongRefs.clear();
|
|
251
|
-
currentConfig = null;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Dispose of the disposables.
|
|
255
|
-
*/
|
|
256
|
-
export async function dispose() {
|
|
257
|
-
disposeSync();
|
|
258
|
-
const promises = [];
|
|
259
|
-
for (const disposable of asyncDisposables) {
|
|
260
|
-
promises.push(disposable[Symbol.asyncDispose]());
|
|
261
|
-
asyncDisposables.delete(disposable);
|
|
262
|
-
}
|
|
263
|
-
await Promise.all(promises);
|
|
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
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* A configuration error.
|
|
277
|
-
*/
|
|
278
|
-
export class ConfigError extends Error {
|
|
279
|
-
/**
|
|
280
|
-
* Constructs a new configuration error.
|
|
281
|
-
* @param message The error message.
|
|
282
|
-
*/
|
|
283
|
-
constructor(message) {
|
|
284
|
-
super(message);
|
|
285
|
-
this.name = "ConfigureError";
|
|
286
|
-
}
|
|
287
|
-
}
|
package/esm/logtape/context.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { LoggerImpl } from "./logger.js";
|
|
2
|
-
/**
|
|
3
|
-
* Runs a callback with the given implicit context. Every single log record
|
|
4
|
-
* in the callback will have the given context.
|
|
5
|
-
*
|
|
6
|
-
* If no `contextLocalStorage` is configured, this function does nothing and
|
|
7
|
-
* just returns the return value of the callback. It also logs a warning to
|
|
8
|
-
* the `["logtape", "meta"]` logger in this case.
|
|
9
|
-
* @param context The context to inject.
|
|
10
|
-
* @param callback The callback to run.
|
|
11
|
-
* @returns The return value of the callback.
|
|
12
|
-
* @since 0.7.0
|
|
13
|
-
*/
|
|
14
|
-
export function withContext(context, callback) {
|
|
15
|
-
const rootLogger = LoggerImpl.getLogger();
|
|
16
|
-
if (rootLogger.contextLocalStorage == null) {
|
|
17
|
-
LoggerImpl.getLogger(["logtape", "meta"]).warn("Context-local storage is not configured. " +
|
|
18
|
-
"Specify contextLocalStorage option in the configure() function.");
|
|
19
|
-
return callback();
|
|
20
|
-
}
|
|
21
|
-
const parentContext = rootLogger.contextLocalStorage.getStore() ?? {};
|
|
22
|
-
return rootLogger.contextLocalStorage.run({ ...parentContext, ...context }, callback);
|
|
23
|
-
}
|
package/esm/logtape/filter.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a {@link FilterLike} value to an actual {@link Filter}.
|
|
3
|
-
*
|
|
4
|
-
* @param filter The filter-like value to convert.
|
|
5
|
-
* @returns The actual filter.
|
|
6
|
-
*/
|
|
7
|
-
export function toFilter(filter) {
|
|
8
|
-
if (typeof filter === "function")
|
|
9
|
-
return filter;
|
|
10
|
-
return getLevelFilter(filter);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Returns a filter that accepts log records with the specified level.
|
|
14
|
-
*
|
|
15
|
-
* @param level The level to filter by. If `null`, the filter will reject all
|
|
16
|
-
* records.
|
|
17
|
-
* @returns The filter.
|
|
18
|
-
*/
|
|
19
|
-
export function getLevelFilter(level) {
|
|
20
|
-
if (level == null)
|
|
21
|
-
return () => false;
|
|
22
|
-
if (level === "fatal") {
|
|
23
|
-
return (record) => record.level === "fatal";
|
|
24
|
-
}
|
|
25
|
-
else if (level === "error") {
|
|
26
|
-
return (record) => record.level === "fatal" || record.level === "error";
|
|
27
|
-
}
|
|
28
|
-
else if (level === "warning") {
|
|
29
|
-
return (record) => record.level === "fatal" ||
|
|
30
|
-
record.level === "error" ||
|
|
31
|
-
record.level === "warning";
|
|
32
|
-
}
|
|
33
|
-
else if (level === "info") {
|
|
34
|
-
return (record) => record.level === "fatal" ||
|
|
35
|
-
record.level === "error" ||
|
|
36
|
-
record.level === "warning" ||
|
|
37
|
-
record.level === "info";
|
|
38
|
-
}
|
|
39
|
-
else if (level === "debug")
|
|
40
|
-
return () => true;
|
|
41
|
-
throw new TypeError(`Invalid log level: ${level}.`);
|
|
42
|
-
}
|