@logtape/file 0.9.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/file/filesink.base.js +78 -0
- package/esm/file/filesink.node.js +47 -0
- package/esm/file/mod.js +1 -0
- package/esm/logtape/config.js +287 -0
- package/esm/logtape/context.js +23 -0
- package/esm/logtape/filter.js +42 -0
- package/esm/logtape/formatter.js +261 -0
- package/esm/logtape/level.js +59 -0
- package/esm/logtape/logger.js +480 -0
- package/esm/logtape/mod.js +8 -0
- package/esm/logtape/nodeUtil.js +2 -0
- package/esm/logtape/record.js +1 -0
- package/esm/logtape/sink.js +96 -0
- package/esm/package.json +3 -0
- package/package.json +55 -0
- package/script/_dnt.shims.js +60 -0
- package/script/file/filesink.base.js +82 -0
- package/script/file/filesink.node.js +55 -0
- package/script/file/mod.js +6 -0
- package/script/logtape/config.js +321 -0
- package/script/logtape/context.js +26 -0
- package/script/logtape/filter.js +46 -0
- package/script/logtape/formatter.js +270 -0
- package/script/logtape/level.js +64 -0
- package/script/logtape/logger.js +511 -0
- package/script/logtape/mod.js +34 -0
- package/script/logtape/nodeUtil.js +7 -0
- package/script/logtape/record.js +2 -0
- package/script/logtape/sink.js +101 -0
- package/script/package.json +3 -0
- package/types/_dnt.shims.d.ts +2 -0
- package/types/_dnt.shims.d.ts.map +1 -0
- package/types/_dnt.test_shims.d.ts.map +1 -0
- package/types/deps/jsr.io/@david/which-runtime/0.2.1/mod.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_constants.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_diff.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/_format.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_equals.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/assertion_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/equal.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/fmt/0.222.1/colors.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/assert_path.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/constants.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/normalize.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_common/normalize_string.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/_os.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/_util.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/posix/normalize.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/_util.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/join.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/path/1.0.8/windows/normalize.d.ts.map +1 -0
- package/types/file/filesink.base.d.ts +89 -0
- package/types/file/filesink.base.d.ts.map +1 -0
- package/types/file/filesink.node.d.ts +34 -0
- package/types/file/filesink.node.d.ts.map +1 -0
- package/types/file/filesink.test.d.ts.map +1 -0
- package/types/file/mod.d.ts +3 -0
- package/types/file/mod.d.ts.map +1 -0
- package/types/logtape/config.d.ts +183 -0
- package/types/logtape/config.d.ts.map +1 -0
- package/types/logtape/context.d.ts +35 -0
- package/types/logtape/context.d.ts.map +1 -0
- package/types/logtape/filter.d.ts +31 -0
- package/types/logtape/filter.d.ts.map +1 -0
- package/types/logtape/fixtures.d.ts.map +1 -0
- package/types/logtape/formatter.d.ts +260 -0
- package/types/logtape/formatter.d.ts.map +1 -0
- package/types/logtape/level.d.ts +32 -0
- package/types/logtape/level.d.ts.map +1 -0
- package/types/logtape/logger.d.ts +423 -0
- package/types/logtape/logger.d.ts.map +1 -0
- package/types/logtape/mod.d.ts +9 -0
- package/types/logtape/mod.d.ts.map +1 -0
- package/types/logtape/nodeUtil.d.ts +3 -0
- package/types/logtape/nodeUtil.d.ts.map +1 -0
- package/types/logtape/record.d.ts +44 -0
- package/types/logtape/record.d.ts.map +1 -0
- package/types/logtape/sink.d.ts +108 -0
- package/types/logtape/sink.d.ts.map +1 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LoggerCtx = exports.LoggerImpl = void 0;
|
|
27
|
+
exports.getLogger = getLogger;
|
|
28
|
+
exports.parseMessageTemplate = parseMessageTemplate;
|
|
29
|
+
exports.renderMessage = renderMessage;
|
|
30
|
+
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
31
|
+
const level_js_1 = require("./level.js");
|
|
32
|
+
/**
|
|
33
|
+
* Get a logger with the given category.
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const logger = getLogger(["my-app"]);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param category The category of the logger. It can be a string or an array
|
|
40
|
+
* of strings. If it is a string, it is equivalent to an array
|
|
41
|
+
* with a single element.
|
|
42
|
+
* @returns The logger.
|
|
43
|
+
*/
|
|
44
|
+
function getLogger(category = []) {
|
|
45
|
+
return LoggerImpl.getLogger(category);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The symbol for the global root logger.
|
|
49
|
+
*/
|
|
50
|
+
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
|
|
51
|
+
/**
|
|
52
|
+
* A logger implementation. Do not use this directly; use {@link getLogger}
|
|
53
|
+
* instead. This class is exported for testing purposes.
|
|
54
|
+
*/
|
|
55
|
+
class LoggerImpl {
|
|
56
|
+
static getLogger(category = []) {
|
|
57
|
+
let rootLogger = globalRootLoggerSymbol in dntShim.dntGlobalThis
|
|
58
|
+
? (dntShim.dntGlobalThis[globalRootLoggerSymbol] ??
|
|
59
|
+
null)
|
|
60
|
+
: null;
|
|
61
|
+
if (rootLogger == null) {
|
|
62
|
+
rootLogger = new LoggerImpl(null, []);
|
|
63
|
+
dntShim.dntGlobalThis[globalRootLoggerSymbol] =
|
|
64
|
+
rootLogger;
|
|
65
|
+
}
|
|
66
|
+
if (typeof category === "string")
|
|
67
|
+
return rootLogger.getChild(category);
|
|
68
|
+
if (category.length === 0)
|
|
69
|
+
return rootLogger;
|
|
70
|
+
return rootLogger.getChild(category);
|
|
71
|
+
}
|
|
72
|
+
constructor(parent, category) {
|
|
73
|
+
Object.defineProperty(this, "parent", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(this, "children", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(this, "category", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: void 0
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(this, "sinks", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true,
|
|
94
|
+
writable: true,
|
|
95
|
+
value: void 0
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(this, "parentSinks", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
value: "inherit"
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(this, "filters", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
configurable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
value: void 0
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(this, "lowestLevel", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: "debug"
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "contextLocalStorage", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
this.parent = parent;
|
|
122
|
+
this.children = {};
|
|
123
|
+
this.category = category;
|
|
124
|
+
this.sinks = [];
|
|
125
|
+
this.filters = [];
|
|
126
|
+
}
|
|
127
|
+
getChild(subcategory) {
|
|
128
|
+
const name = typeof subcategory === "string" ? subcategory : subcategory[0];
|
|
129
|
+
const childRef = this.children[name];
|
|
130
|
+
let child = childRef instanceof LoggerImpl
|
|
131
|
+
? childRef
|
|
132
|
+
: childRef?.deref();
|
|
133
|
+
if (child == null) {
|
|
134
|
+
child = new LoggerImpl(this, [...this.category, name]);
|
|
135
|
+
this.children[name] = "WeakRef" in dntShim.dntGlobalThis
|
|
136
|
+
? new WeakRef(child)
|
|
137
|
+
: child;
|
|
138
|
+
}
|
|
139
|
+
if (typeof subcategory === "string" || subcategory.length === 1) {
|
|
140
|
+
return child;
|
|
141
|
+
}
|
|
142
|
+
return child.getChild(subcategory.slice(1));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Reset the logger. This removes all sinks and filters from the logger.
|
|
146
|
+
*/
|
|
147
|
+
reset() {
|
|
148
|
+
while (this.sinks.length > 0)
|
|
149
|
+
this.sinks.shift();
|
|
150
|
+
this.parentSinks = "inherit";
|
|
151
|
+
while (this.filters.length > 0)
|
|
152
|
+
this.filters.shift();
|
|
153
|
+
this.lowestLevel = "debug";
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Reset the logger and all its descendants. This removes all sinks and
|
|
157
|
+
* filters from the logger and all its descendants.
|
|
158
|
+
*/
|
|
159
|
+
resetDescendants() {
|
|
160
|
+
for (const child of Object.values(this.children)) {
|
|
161
|
+
const logger = child instanceof LoggerImpl ? child : child.deref();
|
|
162
|
+
if (logger != null)
|
|
163
|
+
logger.resetDescendants();
|
|
164
|
+
}
|
|
165
|
+
this.reset();
|
|
166
|
+
}
|
|
167
|
+
with(properties) {
|
|
168
|
+
return new LoggerCtx(this, { ...properties });
|
|
169
|
+
}
|
|
170
|
+
filter(record) {
|
|
171
|
+
for (const filter of this.filters) {
|
|
172
|
+
if (!filter(record))
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (this.filters.length < 1)
|
|
176
|
+
return this.parent?.filter(record) ?? true;
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
*getSinks(level) {
|
|
180
|
+
if (this.lowestLevel === null || (0, level_js_1.compareLogLevel)(level, this.lowestLevel) < 0) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (this.parent != null && this.parentSinks === "inherit") {
|
|
184
|
+
for (const sink of this.parent.getSinks(level))
|
|
185
|
+
yield sink;
|
|
186
|
+
}
|
|
187
|
+
for (const sink of this.sinks)
|
|
188
|
+
yield sink;
|
|
189
|
+
}
|
|
190
|
+
emit(record, bypassSinks) {
|
|
191
|
+
if (this.lowestLevel === null ||
|
|
192
|
+
(0, level_js_1.compareLogLevel)(record.level, this.lowestLevel) < 0 ||
|
|
193
|
+
!this.filter(record)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (const sink of this.getSinks(record.level)) {
|
|
197
|
+
if (bypassSinks?.has(sink))
|
|
198
|
+
continue;
|
|
199
|
+
try {
|
|
200
|
+
sink(record);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const bypassSinks2 = new Set(bypassSinks);
|
|
204
|
+
bypassSinks2.add(sink);
|
|
205
|
+
metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", { sink, error, record }, bypassSinks2);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
log(level, rawMessage, properties, bypassSinks) {
|
|
210
|
+
const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
|
|
211
|
+
let cachedProps = undefined;
|
|
212
|
+
const record = typeof properties === "function"
|
|
213
|
+
? {
|
|
214
|
+
category: this.category,
|
|
215
|
+
level,
|
|
216
|
+
timestamp: Date.now(),
|
|
217
|
+
get message() {
|
|
218
|
+
return parseMessageTemplate(rawMessage, this.properties);
|
|
219
|
+
},
|
|
220
|
+
rawMessage,
|
|
221
|
+
get properties() {
|
|
222
|
+
if (cachedProps == null) {
|
|
223
|
+
cachedProps = {
|
|
224
|
+
...implicitContext,
|
|
225
|
+
...properties(),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
return cachedProps;
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
: {
|
|
232
|
+
category: this.category,
|
|
233
|
+
level,
|
|
234
|
+
timestamp: Date.now(),
|
|
235
|
+
message: parseMessageTemplate(rawMessage, {
|
|
236
|
+
...implicitContext,
|
|
237
|
+
...properties,
|
|
238
|
+
}),
|
|
239
|
+
rawMessage,
|
|
240
|
+
properties: { ...implicitContext, ...properties },
|
|
241
|
+
};
|
|
242
|
+
this.emit(record, bypassSinks);
|
|
243
|
+
}
|
|
244
|
+
logLazily(level, callback, properties = {}) {
|
|
245
|
+
const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
|
|
246
|
+
let rawMessage = undefined;
|
|
247
|
+
let msg = undefined;
|
|
248
|
+
function realizeMessage() {
|
|
249
|
+
if (msg == null || rawMessage == null) {
|
|
250
|
+
msg = callback((tpl, ...values) => {
|
|
251
|
+
rawMessage = tpl;
|
|
252
|
+
return renderMessage(tpl, values);
|
|
253
|
+
});
|
|
254
|
+
if (rawMessage == null)
|
|
255
|
+
throw new TypeError("No log record was made.");
|
|
256
|
+
}
|
|
257
|
+
return [msg, rawMessage];
|
|
258
|
+
}
|
|
259
|
+
this.emit({
|
|
260
|
+
category: this.category,
|
|
261
|
+
level,
|
|
262
|
+
get message() {
|
|
263
|
+
return realizeMessage()[0];
|
|
264
|
+
},
|
|
265
|
+
get rawMessage() {
|
|
266
|
+
return realizeMessage()[1];
|
|
267
|
+
},
|
|
268
|
+
timestamp: Date.now(),
|
|
269
|
+
properties: { ...implicitContext, ...properties },
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
logTemplate(level, messageTemplate, values, properties = {}) {
|
|
273
|
+
const implicitContext = LoggerImpl.getLogger().contextLocalStorage?.getStore() ?? {};
|
|
274
|
+
this.emit({
|
|
275
|
+
category: this.category,
|
|
276
|
+
level,
|
|
277
|
+
message: renderMessage(messageTemplate, values),
|
|
278
|
+
rawMessage: messageTemplate,
|
|
279
|
+
timestamp: Date.now(),
|
|
280
|
+
properties: { ...implicitContext, ...properties },
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
debug(message, ...values) {
|
|
284
|
+
if (typeof message === "string") {
|
|
285
|
+
this.log("debug", message, (values[0] ?? {}));
|
|
286
|
+
}
|
|
287
|
+
else if (typeof message === "function") {
|
|
288
|
+
this.logLazily("debug", message);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
this.logTemplate("debug", message, values);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
info(message, ...values) {
|
|
295
|
+
if (typeof message === "string") {
|
|
296
|
+
this.log("info", message, (values[0] ?? {}));
|
|
297
|
+
}
|
|
298
|
+
else if (typeof message === "function") {
|
|
299
|
+
this.logLazily("info", message);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
this.logTemplate("info", message, values);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
warn(message, ...values) {
|
|
306
|
+
if (typeof message === "string") {
|
|
307
|
+
this.log("warning", message, (values[0] ?? {}));
|
|
308
|
+
}
|
|
309
|
+
else if (typeof message === "function") {
|
|
310
|
+
this.logLazily("warning", message);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
this.logTemplate("warning", message, values);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
error(message, ...values) {
|
|
317
|
+
if (typeof message === "string") {
|
|
318
|
+
this.log("error", message, (values[0] ?? {}));
|
|
319
|
+
}
|
|
320
|
+
else if (typeof message === "function") {
|
|
321
|
+
this.logLazily("error", message);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
this.logTemplate("error", message, values);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
fatal(message, ...values) {
|
|
328
|
+
if (typeof message === "string") {
|
|
329
|
+
this.log("fatal", message, (values[0] ?? {}));
|
|
330
|
+
}
|
|
331
|
+
else if (typeof message === "function") {
|
|
332
|
+
this.logLazily("fatal", message);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
this.logTemplate("fatal", message, values);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
exports.LoggerImpl = LoggerImpl;
|
|
340
|
+
/**
|
|
341
|
+
* A logger implementation with contextual properties. Do not use this
|
|
342
|
+
* directly; use {@link Logger.with} instead. This class is exported
|
|
343
|
+
* for testing purposes.
|
|
344
|
+
*/
|
|
345
|
+
class LoggerCtx {
|
|
346
|
+
constructor(logger, properties) {
|
|
347
|
+
Object.defineProperty(this, "logger", {
|
|
348
|
+
enumerable: true,
|
|
349
|
+
configurable: true,
|
|
350
|
+
writable: true,
|
|
351
|
+
value: void 0
|
|
352
|
+
});
|
|
353
|
+
Object.defineProperty(this, "properties", {
|
|
354
|
+
enumerable: true,
|
|
355
|
+
configurable: true,
|
|
356
|
+
writable: true,
|
|
357
|
+
value: void 0
|
|
358
|
+
});
|
|
359
|
+
this.logger = logger;
|
|
360
|
+
this.properties = properties;
|
|
361
|
+
}
|
|
362
|
+
get category() {
|
|
363
|
+
return this.logger.category;
|
|
364
|
+
}
|
|
365
|
+
get parent() {
|
|
366
|
+
return this.logger.parent;
|
|
367
|
+
}
|
|
368
|
+
getChild(subcategory) {
|
|
369
|
+
return this.logger.getChild(subcategory).with(this.properties);
|
|
370
|
+
}
|
|
371
|
+
with(properties) {
|
|
372
|
+
return new LoggerCtx(this.logger, { ...this.properties, ...properties });
|
|
373
|
+
}
|
|
374
|
+
log(level, message, properties, bypassSinks) {
|
|
375
|
+
this.logger.log(level, message, typeof properties === "function"
|
|
376
|
+
? () => ({
|
|
377
|
+
...this.properties,
|
|
378
|
+
...properties(),
|
|
379
|
+
})
|
|
380
|
+
: { ...this.properties, ...properties }, bypassSinks);
|
|
381
|
+
}
|
|
382
|
+
logLazily(level, callback) {
|
|
383
|
+
this.logger.logLazily(level, callback, this.properties);
|
|
384
|
+
}
|
|
385
|
+
logTemplate(level, messageTemplate, values) {
|
|
386
|
+
this.logger.logTemplate(level, messageTemplate, values, this.properties);
|
|
387
|
+
}
|
|
388
|
+
debug(message, ...values) {
|
|
389
|
+
if (typeof message === "string") {
|
|
390
|
+
this.log("debug", message, (values[0] ?? {}));
|
|
391
|
+
}
|
|
392
|
+
else if (typeof message === "function") {
|
|
393
|
+
this.logLazily("debug", message);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
this.logTemplate("debug", message, values);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
info(message, ...values) {
|
|
400
|
+
if (typeof message === "string") {
|
|
401
|
+
this.log("info", message, (values[0] ?? {}));
|
|
402
|
+
}
|
|
403
|
+
else if (typeof message === "function") {
|
|
404
|
+
this.logLazily("info", message);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
this.logTemplate("info", message, values);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
warn(message, ...values) {
|
|
411
|
+
if (typeof message === "string") {
|
|
412
|
+
this.log("warning", message, (values[0] ?? {}));
|
|
413
|
+
}
|
|
414
|
+
else if (typeof message === "function") {
|
|
415
|
+
this.logLazily("warning", message);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
this.logTemplate("warning", message, values);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
error(message, ...values) {
|
|
422
|
+
if (typeof message === "string") {
|
|
423
|
+
this.log("error", message, (values[0] ?? {}));
|
|
424
|
+
}
|
|
425
|
+
else if (typeof message === "function") {
|
|
426
|
+
this.logLazily("error", message);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
this.logTemplate("error", message, values);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
fatal(message, ...values) {
|
|
433
|
+
if (typeof message === "string") {
|
|
434
|
+
this.log("fatal", message, (values[0] ?? {}));
|
|
435
|
+
}
|
|
436
|
+
else if (typeof message === "function") {
|
|
437
|
+
this.logLazily("fatal", message);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
this.logTemplate("fatal", message, values);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
exports.LoggerCtx = LoggerCtx;
|
|
445
|
+
/**
|
|
446
|
+
* The meta logger. It is a logger with the category `["logtape", "meta"]`.
|
|
447
|
+
*/
|
|
448
|
+
const metaLogger = LoggerImpl.getLogger(["logtape", "meta"]);
|
|
449
|
+
/**
|
|
450
|
+
* Parse a message template into a message template array and a values array.
|
|
451
|
+
* @param template The message template.
|
|
452
|
+
* @param properties The values to replace placeholders with.
|
|
453
|
+
* @returns The message template array and the values array.
|
|
454
|
+
*/
|
|
455
|
+
function parseMessageTemplate(template, properties) {
|
|
456
|
+
const message = [];
|
|
457
|
+
let part = "";
|
|
458
|
+
for (let i = 0; i < template.length; i++) {
|
|
459
|
+
const char = template.charAt(i);
|
|
460
|
+
const nextChar = template.charAt(i + 1);
|
|
461
|
+
if (char === "{" && nextChar === "{") {
|
|
462
|
+
// Escaped { character
|
|
463
|
+
part = part + char;
|
|
464
|
+
i++;
|
|
465
|
+
}
|
|
466
|
+
else if (char === "}" && nextChar === "}") {
|
|
467
|
+
// Escaped } character
|
|
468
|
+
part = part + char;
|
|
469
|
+
i++;
|
|
470
|
+
}
|
|
471
|
+
else if (char === "{") {
|
|
472
|
+
// Start of a placeholder
|
|
473
|
+
message.push(part);
|
|
474
|
+
part = "";
|
|
475
|
+
}
|
|
476
|
+
else if (char === "}") {
|
|
477
|
+
// End of a placeholder
|
|
478
|
+
let prop;
|
|
479
|
+
if (part.match(/^\s|\s$/)) {
|
|
480
|
+
prop = part in properties ? properties[part] : properties[part.trim()];
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
prop = properties[part];
|
|
484
|
+
}
|
|
485
|
+
message.push(prop);
|
|
486
|
+
part = "";
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
// Default case
|
|
490
|
+
part = part + char;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
message.push(part);
|
|
494
|
+
return message;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Render a message template with values.
|
|
498
|
+
* @param template The message template.
|
|
499
|
+
* @param values The message template values.
|
|
500
|
+
* @returns The message template values interleaved between the substitution
|
|
501
|
+
* values.
|
|
502
|
+
*/
|
|
503
|
+
function renderMessage(template, values) {
|
|
504
|
+
const args = [];
|
|
505
|
+
for (let i = 0; i < template.length; i++) {
|
|
506
|
+
args.push(template[i]);
|
|
507
|
+
if (i < values.length)
|
|
508
|
+
args.push(values[i]);
|
|
509
|
+
}
|
|
510
|
+
return args;
|
|
511
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
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.withContext = exports.resetSync = exports.reset = exports.getConfig = exports.disposeSync = exports.dispose = exports.configureSync = exports.configure = exports.ConfigError = void 0;
|
|
4
|
+
var config_js_1 = require("./config.js");
|
|
5
|
+
Object.defineProperty(exports, "ConfigError", { enumerable: true, get: function () { return config_js_1.ConfigError; } });
|
|
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; } });
|
|
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; } });
|
|
10
|
+
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_js_1.getConfig; } });
|
|
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; } });
|
|
13
|
+
var context_js_1 = require("./context.js");
|
|
14
|
+
Object.defineProperty(exports, "withContext", { enumerable: true, get: function () { return context_js_1.withContext; } });
|
|
15
|
+
var filter_js_1 = require("./filter.js");
|
|
16
|
+
Object.defineProperty(exports, "getLevelFilter", { enumerable: true, get: function () { return filter_js_1.getLevelFilter; } });
|
|
17
|
+
Object.defineProperty(exports, "toFilter", { enumerable: true, get: function () { return filter_js_1.toFilter; } });
|
|
18
|
+
var formatter_js_1 = require("./formatter.js");
|
|
19
|
+
Object.defineProperty(exports, "ansiColorFormatter", { enumerable: true, get: function () { return formatter_js_1.ansiColorFormatter; } });
|
|
20
|
+
Object.defineProperty(exports, "defaultConsoleFormatter", { enumerable: true, get: function () { return formatter_js_1.defaultConsoleFormatter; } });
|
|
21
|
+
Object.defineProperty(exports, "defaultTextFormatter", { enumerable: true, get: function () { return formatter_js_1.defaultTextFormatter; } });
|
|
22
|
+
Object.defineProperty(exports, "getAnsiColorFormatter", { enumerable: true, get: function () { return formatter_js_1.getAnsiColorFormatter; } });
|
|
23
|
+
Object.defineProperty(exports, "getTextFormatter", { enumerable: true, get: function () { return formatter_js_1.getTextFormatter; } });
|
|
24
|
+
var level_js_1 = require("./level.js");
|
|
25
|
+
Object.defineProperty(exports, "compareLogLevel", { enumerable: true, get: function () { return level_js_1.compareLogLevel; } });
|
|
26
|
+
Object.defineProperty(exports, "isLogLevel", { enumerable: true, get: function () { return level_js_1.isLogLevel; } });
|
|
27
|
+
Object.defineProperty(exports, "parseLogLevel", { enumerable: true, get: function () { return level_js_1.parseLogLevel; } });
|
|
28
|
+
var logger_js_1 = require("./logger.js");
|
|
29
|
+
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_js_1.getLogger; } });
|
|
30
|
+
var sink_js_1 = require("./sink.js");
|
|
31
|
+
Object.defineProperty(exports, "getConsoleSink", { enumerable: true, get: function () { return sink_js_1.getConsoleSink; } });
|
|
32
|
+
Object.defineProperty(exports, "getStreamSink", { enumerable: true, get: function () { return sink_js_1.getStreamSink; } });
|
|
33
|
+
Object.defineProperty(exports, "withFilter", { enumerable: true, get: function () { return sink_js_1.withFilter; } });
|
|
34
|
+
// cSpell: ignore filesink
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
7
|
+
exports.default = node_util_1.default;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withFilter = withFilter;
|
|
4
|
+
exports.getStreamSink = getStreamSink;
|
|
5
|
+
exports.getConsoleSink = getConsoleSink;
|
|
6
|
+
const filter_js_1 = require("./filter.js");
|
|
7
|
+
const formatter_js_1 = require("./formatter.js");
|
|
8
|
+
/**
|
|
9
|
+
* Turns a sink into a filtered sink. The returned sink only logs records that
|
|
10
|
+
* pass the filter.
|
|
11
|
+
*
|
|
12
|
+
* @example Filter a console sink to only log records with the info level
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const sink = withFilter(getConsoleSink(), "info");
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param sink A sink to be filtered.
|
|
18
|
+
* @param filter A filter to apply to the sink. It can be either a filter
|
|
19
|
+
* function or a {@link LogLevel} string.
|
|
20
|
+
* @returns A sink that only logs records that pass the filter.
|
|
21
|
+
*/
|
|
22
|
+
function withFilter(sink, filter) {
|
|
23
|
+
const filterFunc = (0, filter_js_1.toFilter)(filter);
|
|
24
|
+
return (record) => {
|
|
25
|
+
if (filterFunc(record))
|
|
26
|
+
sink(record);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A factory that returns a sink that writes to a {@link WritableStream}.
|
|
31
|
+
*
|
|
32
|
+
* Note that the `stream` is of Web Streams API, which is different from
|
|
33
|
+
* Node.js streams. You can convert a Node.js stream to a Web Streams API
|
|
34
|
+
* stream using [`stream.Writable.toWeb()`] method.
|
|
35
|
+
*
|
|
36
|
+
* [`stream.Writable.toWeb()`]: https://nodejs.org/api/stream.html#streamwritabletowebstreamwritable
|
|
37
|
+
*
|
|
38
|
+
* @example Sink to the standard error in Deno
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const stderrSink = getStreamSink(Deno.stderr.writable);
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Sink to the standard error in Node.js
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import stream from "node:stream";
|
|
46
|
+
* const stderrSink = getStreamSink(stream.Writable.toWeb(process.stderr));
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param stream The stream to write to.
|
|
50
|
+
* @param options The options for the sink.
|
|
51
|
+
* @returns A sink that writes to the stream.
|
|
52
|
+
*/
|
|
53
|
+
function getStreamSink(stream, options = {}) {
|
|
54
|
+
const formatter = options.formatter ?? formatter_js_1.defaultTextFormatter;
|
|
55
|
+
const encoder = options.encoder ?? new TextEncoder();
|
|
56
|
+
const writer = stream.getWriter();
|
|
57
|
+
let lastPromise = Promise.resolve();
|
|
58
|
+
const sink = (record) => {
|
|
59
|
+
const bytes = encoder.encode(formatter(record));
|
|
60
|
+
lastPromise = lastPromise
|
|
61
|
+
.then(() => writer.ready)
|
|
62
|
+
.then(() => writer.write(bytes));
|
|
63
|
+
};
|
|
64
|
+
sink[Symbol.asyncDispose] = async () => {
|
|
65
|
+
await lastPromise;
|
|
66
|
+
await writer.close();
|
|
67
|
+
};
|
|
68
|
+
return sink;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A console sink factory that returns a sink that logs to the console.
|
|
72
|
+
*
|
|
73
|
+
* @param options The options for the sink.
|
|
74
|
+
* @returns A sink that logs to the console.
|
|
75
|
+
*/
|
|
76
|
+
function getConsoleSink(options = {}) {
|
|
77
|
+
const formatter = options.formatter ?? formatter_js_1.defaultConsoleFormatter;
|
|
78
|
+
const levelMap = {
|
|
79
|
+
debug: "debug",
|
|
80
|
+
info: "info",
|
|
81
|
+
warning: "warn",
|
|
82
|
+
error: "error",
|
|
83
|
+
fatal: "error",
|
|
84
|
+
...(options.levelMap ?? {}),
|
|
85
|
+
};
|
|
86
|
+
const console = options.console ?? globalThis.console;
|
|
87
|
+
return (record) => {
|
|
88
|
+
const args = formatter(record);
|
|
89
|
+
const method = levelMap[record.level];
|
|
90
|
+
if (method === undefined) {
|
|
91
|
+
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
92
|
+
}
|
|
93
|
+
if (typeof args === "string") {
|
|
94
|
+
const msg = args.replace(/\r?\n$/, "");
|
|
95
|
+
console[method](msg);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console[method](...args);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.test_shims.d.ts","sourceRoot":"","sources":["../src/_dnt.test_shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@david/which-runtime/0.2.1/mod.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,EAAE,OAA4C,CAAC;AAClE,eAAO,MAAM,MAAM,EAAE,OAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_constants.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_diff.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_diff.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,QAAQ,CAAC;AAE7C,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC;AA4BD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA+L5D;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,wBAsI3C;AAwCD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAC7C,EAAE,UAAkB,EAAE;;CAAK,GAC1B,MAAM,EAAE,CAyBV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_format.ts"],"names":[],"mappings":"AAYA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAezC"}
|