likec4 1.48.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/__app__/src/likec4.js +5595 -4127
- package/__app__/src/routes/index.js +3 -153
- package/__app__/src/routes/projects.js +21 -1087
- package/__app__/src/routes/single.js +1221 -16
- package/__app__/src/style.css +1 -1
- package/__app__/src/vendors.js +3507 -894
- package/__app__/src/webcomponent.js +1 -1
- package/config/schema.json +155 -143
- package/dist/THIRD-PARTY-LICENSES.md +1739 -0
- package/dist/_chunks/GraphvizBinaryAdapter.mjs +72 -0
- package/dist/_chunks/filenames.mjs +14 -0
- package/dist/_chunks/index.d.mts +224 -129
- package/dist/_chunks/index2.d.mts +2033 -1908
- package/dist/_chunks/libs/@chevrotain/gast.mjs +1 -3969
- package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
- package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
- package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
- package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
- package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
- package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
- package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +14 -14
- package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
- package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
- package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
- package/dist/_chunks/libs/ajv.mjs +1 -777
- package/dist/_chunks/libs/atomically.mjs +1 -362
- package/dist/_chunks/libs/birpc.mjs +1 -201
- package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
- package/dist/_chunks/libs/chevrotain.mjs +55 -6229
- package/dist/_chunks/libs/conf.mjs +1 -2258
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/esm-env.mjs +1 -5
- package/dist/_chunks/libs/eventemitter3.mjs +1 -243
- package/dist/_chunks/libs/fast-equals.mjs +1 -446
- package/dist/_chunks/libs/find-up-simple.mjs +1 -24
- package/dist/_chunks/libs/get-port.mjs +1 -107
- package/dist/_chunks/libs/is-docker.mjs +1 -26
- package/dist/_chunks/libs/is-error-instance.mjs +1 -26
- package/dist/_chunks/libs/is-inside-container.mjs +1 -20
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/isexe.mjs +1 -127
- package/dist/_chunks/libs/json5.mjs +14 -959
- package/dist/_chunks/libs/khroma.mjs +1 -605
- package/dist/_chunks/libs/ky.mjs +2 -807
- package/dist/_chunks/libs/langium.d.mts +2880 -2844
- package/dist/_chunks/libs/langium.mjs +32 -20351
- package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
- package/dist/_chunks/libs/nanostores.mjs +1 -198
- package/dist/_chunks/libs/p-limit.mjs +1 -120
- package/dist/_chunks/libs/p-queue.mjs +1 -449
- package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
- package/dist/_chunks/libs/package-up.mjs +1 -10
- package/dist/_chunks/libs/parse-ms.mjs +1 -36
- package/dist/_chunks/libs/pathe.mjs +1 -0
- package/dist/_chunks/libs/picomatch.mjs +1 -1673
- package/dist/_chunks/libs/pretty-ms.mjs +1 -80
- package/dist/_chunks/libs/remeda.mjs +1 -690
- package/dist/_chunks/libs/safe-stringify.mjs +1 -21
- package/dist/_chunks/libs/strip-indent.mjs +1 -15
- package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
- package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
- package/dist/_chunks/libs/ufo.mjs +1 -240
- package/dist/_chunks/libs/which.mjs +1 -84
- package/dist/_chunks/libs/word-wrap.mjs +12 -43
- package/dist/_chunks/node.mjs +481 -0
- package/dist/_chunks/plugin.mjs +98 -772
- package/dist/_chunks/rolldown-runtime.mjs +1 -48
- package/dist/_chunks/sequence-view.mjs +1 -575
- package/dist/cli/index.mjs +127 -1846
- package/dist/config/index.d.mts +2 -2
- package/dist/config/index.mjs +1 -6
- package/dist/index.d.mts +148 -7
- package/dist/index.mjs +1 -21
- package/dist/model/builder.mjs +1 -3
- package/dist/model/index.d.mts +57 -3
- package/dist/model/index.mjs +1 -5
- package/dist/vite-plugin/index.d.mts +4 -3
- package/dist/vite-plugin/index.mjs +1 -22
- package/dist/vite-plugin/internal.d.mts +5 -5
- package/dist/vite-plugin/internal.mjs +1 -68
- package/package.json +60 -41
- package/react/{index.d.ts → index.d.mts} +112 -70
- package/react/{index.js → index.mjs} +21361 -22064
- package/react/package.json +2 -5
- package/vite-plugin-modules.d.ts +5 -5
- package/dist/_chunks/LikeC4.d.mts +0 -121
- package/dist/_chunks/LikeC4.mjs +0 -202
- package/dist/_chunks/config-app.prod.d.mts +0 -18
- package/dist/_chunks/config-app.prod.mjs +0 -188
- package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
- package/dist/_chunks/define-config.mjs +0 -409
- package/dist/_chunks/index3.d.mts +0 -60
- package/dist/_chunks/index4.d.mts +0 -1
- package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +0 -10
- package/dist/_chunks/libs/hono.mjs +0 -1829
- package/dist/_chunks/libs/nanoid.mjs +0 -29
- package/dist/_chunks/model.mjs +0 -12
- package/dist/_chunks/module.d.mts +0 -71
- package/dist/_chunks/module.mjs +0 -18657
- package/dist/_chunks/vite-build.mjs +0 -69
- package/dist/_chunks/vite-dev.mjs +0 -79
- package/dist/_chunks/vite-preview.mjs +0 -27
- package/dist/language/module.d.mts +0 -5
- package/dist/language/module.mjs +0 -20
- package/dist/vite/vite-build.d.mts +0 -26
- package/dist/vite/vite-build.mjs +0 -27
- package/dist/vite/vite-dev.d.mts +0 -34
- package/dist/vite/vite-dev.mjs +0 -29
- package/dist/vite/vite-preview.d.mts +0 -20
- package/dist/vite/vite-preview.mjs +0 -26
|
@@ -1,1354 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param filter The filter-like value to convert.
|
|
9
|
-
* @returns The actual filter.
|
|
10
|
-
*/
|
|
11
|
-
function toFilter(filter) {
|
|
12
|
-
if (typeof filter === "function") return filter;
|
|
13
|
-
return getLevelFilter(filter);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Returns a filter that accepts log records with the specified level.
|
|
17
|
-
*
|
|
18
|
-
* @param level The level to filter by. If `null`, the filter will reject all
|
|
19
|
-
* records.
|
|
20
|
-
* @returns The filter.
|
|
21
|
-
*/
|
|
22
|
-
function getLevelFilter(level) {
|
|
23
|
-
if (level == null) return () => false;
|
|
24
|
-
if (level === "fatal") return (record) => record.level === "fatal";
|
|
25
|
-
else if (level === "error") return (record) => record.level === "fatal" || record.level === "error";
|
|
26
|
-
else if (level === "warning") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning";
|
|
27
|
-
else if (level === "info") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info";
|
|
28
|
-
else if (level === "debug") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info" || record.level === "debug";
|
|
29
|
-
else if (level === "trace") return () => true;
|
|
30
|
-
throw new TypeError(`Invalid log level: ${level}.`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/level.js
|
|
35
|
-
const logLevels = [
|
|
36
|
-
"trace",
|
|
37
|
-
"debug",
|
|
38
|
-
"info",
|
|
39
|
-
"warning",
|
|
40
|
-
"error",
|
|
41
|
-
"fatal"
|
|
42
|
-
];
|
|
43
|
-
/**
|
|
44
|
-
* Compares two log levels.
|
|
45
|
-
* @param a The first log level.
|
|
46
|
-
* @param b The second log level.
|
|
47
|
-
* @returns A negative number if `a` is less than `b`, a positive number if `a`
|
|
48
|
-
* is greater than `b`, or zero if they are equal.
|
|
49
|
-
* @since 0.8.0
|
|
50
|
-
*/
|
|
51
|
-
function compareLogLevel(a, b) {
|
|
52
|
-
const aIndex = logLevels.indexOf(a);
|
|
53
|
-
if (aIndex < 0) throw new TypeError(`Invalid log level: ${JSON.stringify(a)}.`);
|
|
54
|
-
const bIndex = logLevels.indexOf(b);
|
|
55
|
-
if (bIndex < 0) throw new TypeError(`Invalid log level: ${JSON.stringify(b)}.`);
|
|
56
|
-
return aIndex - bIndex;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/logger.js
|
|
61
|
-
/**
|
|
62
|
-
* Get a logger with the given category.
|
|
63
|
-
*
|
|
64
|
-
* ```typescript
|
|
65
|
-
* const logger = getLogger(["my-app"]);
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* @param category The category of the logger. It can be a string or an array
|
|
69
|
-
* of strings. If it is a string, it is equivalent to an array
|
|
70
|
-
* with a single element.
|
|
71
|
-
* @returns The logger.
|
|
72
|
-
*/
|
|
73
|
-
function getLogger(category = []) {
|
|
74
|
-
return LoggerImpl.getLogger(category);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* The symbol for the global root logger.
|
|
78
|
-
*/
|
|
79
|
-
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
|
|
80
|
-
/**
|
|
81
|
-
* A logger implementation. Do not use this directly; use {@link getLogger}
|
|
82
|
-
* instead. This class is exported for testing purposes.
|
|
83
|
-
*/
|
|
84
|
-
var LoggerImpl = class LoggerImpl {
|
|
85
|
-
parent;
|
|
86
|
-
children;
|
|
87
|
-
category;
|
|
88
|
-
sinks;
|
|
89
|
-
parentSinks = "inherit";
|
|
90
|
-
filters;
|
|
91
|
-
lowestLevel = "trace";
|
|
92
|
-
contextLocalStorage;
|
|
93
|
-
static getLogger(category = []) {
|
|
94
|
-
let rootLogger = globalRootLoggerSymbol in globalThis ? globalThis[globalRootLoggerSymbol] ?? null : null;
|
|
95
|
-
if (rootLogger == null) {
|
|
96
|
-
rootLogger = new LoggerImpl(null, []);
|
|
97
|
-
globalThis[globalRootLoggerSymbol] = rootLogger;
|
|
98
|
-
}
|
|
99
|
-
if (typeof category === "string") return rootLogger.getChild(category);
|
|
100
|
-
if (category.length === 0) return rootLogger;
|
|
101
|
-
return rootLogger.getChild(category);
|
|
102
|
-
}
|
|
103
|
-
constructor(parent, category) {
|
|
104
|
-
this.parent = parent;
|
|
105
|
-
this.children = {};
|
|
106
|
-
this.category = category;
|
|
107
|
-
this.sinks = [];
|
|
108
|
-
this.filters = [];
|
|
109
|
-
}
|
|
110
|
-
getChild(subcategory) {
|
|
111
|
-
const name = typeof subcategory === "string" ? subcategory : subcategory[0];
|
|
112
|
-
const childRef = this.children[name];
|
|
113
|
-
let child = childRef instanceof LoggerImpl ? childRef : childRef?.deref();
|
|
114
|
-
if (child == null) {
|
|
115
|
-
child = new LoggerImpl(this, [...this.category, name]);
|
|
116
|
-
this.children[name] = "WeakRef" in globalThis ? new WeakRef(child) : child;
|
|
117
|
-
}
|
|
118
|
-
if (typeof subcategory === "string" || subcategory.length === 1) return child;
|
|
119
|
-
return child.getChild(subcategory.slice(1));
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Reset the logger. This removes all sinks and filters from the logger.
|
|
123
|
-
*/
|
|
124
|
-
reset() {
|
|
125
|
-
while (this.sinks.length > 0) this.sinks.shift();
|
|
126
|
-
this.parentSinks = "inherit";
|
|
127
|
-
while (this.filters.length > 0) this.filters.shift();
|
|
128
|
-
this.lowestLevel = "trace";
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Reset the logger and all its descendants. This removes all sinks and
|
|
132
|
-
* filters from the logger and all its descendants.
|
|
133
|
-
*/
|
|
134
|
-
resetDescendants() {
|
|
135
|
-
for (const child of Object.values(this.children)) {
|
|
136
|
-
const logger = child instanceof LoggerImpl ? child : child.deref();
|
|
137
|
-
if (logger != null) logger.resetDescendants();
|
|
138
|
-
}
|
|
139
|
-
this.reset();
|
|
140
|
-
}
|
|
141
|
-
with(properties) {
|
|
142
|
-
return new LoggerCtx(this, { ...properties });
|
|
143
|
-
}
|
|
144
|
-
filter(record) {
|
|
145
|
-
for (const filter of this.filters) if (!filter(record)) return false;
|
|
146
|
-
if (this.filters.length < 1) return this.parent?.filter(record) ?? true;
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
*getSinks(level) {
|
|
150
|
-
if (this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0) return;
|
|
151
|
-
if (this.parent != null && this.parentSinks === "inherit") for (const sink of this.parent.getSinks(level)) yield sink;
|
|
152
|
-
for (const sink of this.sinks) yield sink;
|
|
153
|
-
}
|
|
154
|
-
emit(record, bypassSinks) {
|
|
155
|
-
const categoryPrefix = getCategoryPrefix();
|
|
156
|
-
const baseCategory = "category" in record ? record.category : this.category;
|
|
157
|
-
const fullCategory = categoryPrefix.length > 0 ? [...categoryPrefix, ...baseCategory] : baseCategory;
|
|
158
|
-
const descriptors = Object.getOwnPropertyDescriptors(record);
|
|
159
|
-
descriptors.category = {
|
|
160
|
-
value: fullCategory,
|
|
161
|
-
enumerable: true,
|
|
162
|
-
configurable: true
|
|
163
|
-
};
|
|
164
|
-
const fullRecord = Object.defineProperties({}, descriptors);
|
|
165
|
-
if (this.lowestLevel === null || compareLogLevel(fullRecord.level, this.lowestLevel) < 0 || !this.filter(fullRecord)) return;
|
|
166
|
-
for (const sink of this.getSinks(fullRecord.level)) {
|
|
167
|
-
if (bypassSinks?.has(sink)) continue;
|
|
168
|
-
try {
|
|
169
|
-
sink(fullRecord);
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const bypassSinks2 = new Set(bypassSinks);
|
|
172
|
-
bypassSinks2.add(sink);
|
|
173
|
-
metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", {
|
|
174
|
-
sink,
|
|
175
|
-
error,
|
|
176
|
-
record: fullRecord
|
|
177
|
-
}, bypassSinks2);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
log(level, rawMessage, properties, bypassSinks) {
|
|
182
|
-
const implicitContext = getImplicitContext();
|
|
183
|
-
let cachedProps = void 0;
|
|
184
|
-
const record = typeof properties === "function" ? {
|
|
185
|
-
category: this.category,
|
|
186
|
-
level,
|
|
187
|
-
timestamp: Date.now(),
|
|
188
|
-
get message() {
|
|
189
|
-
return parseMessageTemplate(rawMessage, this.properties);
|
|
190
|
-
},
|
|
191
|
-
rawMessage,
|
|
192
|
-
get properties() {
|
|
193
|
-
if (cachedProps == null) cachedProps = {
|
|
194
|
-
...implicitContext,
|
|
195
|
-
...properties()
|
|
196
|
-
};
|
|
197
|
-
return cachedProps;
|
|
198
|
-
}
|
|
199
|
-
} : {
|
|
200
|
-
category: this.category,
|
|
201
|
-
level,
|
|
202
|
-
timestamp: Date.now(),
|
|
203
|
-
message: parseMessageTemplate(rawMessage, {
|
|
204
|
-
...implicitContext,
|
|
205
|
-
...properties
|
|
206
|
-
}),
|
|
207
|
-
rawMessage,
|
|
208
|
-
properties: {
|
|
209
|
-
...implicitContext,
|
|
210
|
-
...properties
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
this.emit(record, bypassSinks);
|
|
214
|
-
}
|
|
215
|
-
logLazily(level, callback, properties = {}) {
|
|
216
|
-
const implicitContext = getImplicitContext();
|
|
217
|
-
let rawMessage = void 0;
|
|
218
|
-
let msg = void 0;
|
|
219
|
-
function realizeMessage() {
|
|
220
|
-
if (msg == null || rawMessage == null) {
|
|
221
|
-
msg = callback((tpl, ...values) => {
|
|
222
|
-
rawMessage = tpl;
|
|
223
|
-
return renderMessage(tpl, values);
|
|
224
|
-
});
|
|
225
|
-
if (rawMessage == null) throw new TypeError("No log record was made.");
|
|
226
|
-
}
|
|
227
|
-
return [msg, rawMessage];
|
|
228
|
-
}
|
|
229
|
-
this.emit({
|
|
230
|
-
category: this.category,
|
|
231
|
-
level,
|
|
232
|
-
get message() {
|
|
233
|
-
return realizeMessage()[0];
|
|
234
|
-
},
|
|
235
|
-
get rawMessage() {
|
|
236
|
-
return realizeMessage()[1];
|
|
237
|
-
},
|
|
238
|
-
timestamp: Date.now(),
|
|
239
|
-
properties: {
|
|
240
|
-
...implicitContext,
|
|
241
|
-
...properties
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
logTemplate(level, messageTemplate, values, properties = {}) {
|
|
246
|
-
const implicitContext = getImplicitContext();
|
|
247
|
-
this.emit({
|
|
248
|
-
category: this.category,
|
|
249
|
-
level,
|
|
250
|
-
message: renderMessage(messageTemplate, values),
|
|
251
|
-
rawMessage: messageTemplate,
|
|
252
|
-
timestamp: Date.now(),
|
|
253
|
-
properties: {
|
|
254
|
-
...implicitContext,
|
|
255
|
-
...properties
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
trace(message, ...values) {
|
|
260
|
-
if (typeof message === "string") this.log("trace", message, values[0] ?? {});
|
|
261
|
-
else if (typeof message === "function") this.logLazily("trace", message);
|
|
262
|
-
else if (!Array.isArray(message)) this.log("trace", "{*}", message);
|
|
263
|
-
else this.logTemplate("trace", message, values);
|
|
264
|
-
}
|
|
265
|
-
debug(message, ...values) {
|
|
266
|
-
if (typeof message === "string") this.log("debug", message, values[0] ?? {});
|
|
267
|
-
else if (typeof message === "function") this.logLazily("debug", message);
|
|
268
|
-
else if (!Array.isArray(message)) this.log("debug", "{*}", message);
|
|
269
|
-
else this.logTemplate("debug", message, values);
|
|
270
|
-
}
|
|
271
|
-
info(message, ...values) {
|
|
272
|
-
if (typeof message === "string") this.log("info", message, values[0] ?? {});
|
|
273
|
-
else if (typeof message === "function") this.logLazily("info", message);
|
|
274
|
-
else if (!Array.isArray(message)) this.log("info", "{*}", message);
|
|
275
|
-
else this.logTemplate("info", message, values);
|
|
276
|
-
}
|
|
277
|
-
warn(message, ...values) {
|
|
278
|
-
if (typeof message === "string") this.log("warning", message, values[0] ?? {});
|
|
279
|
-
else if (typeof message === "function") this.logLazily("warning", message);
|
|
280
|
-
else if (!Array.isArray(message)) this.log("warning", "{*}", message);
|
|
281
|
-
else this.logTemplate("warning", message, values);
|
|
282
|
-
}
|
|
283
|
-
warning(message, ...values) {
|
|
284
|
-
this.warn(message, ...values);
|
|
285
|
-
}
|
|
286
|
-
error(message, ...values) {
|
|
287
|
-
if (typeof message === "string") this.log("error", message, values[0] ?? {});
|
|
288
|
-
else if (typeof message === "function") this.logLazily("error", message);
|
|
289
|
-
else if (!Array.isArray(message)) this.log("error", "{*}", message);
|
|
290
|
-
else this.logTemplate("error", message, values);
|
|
291
|
-
}
|
|
292
|
-
fatal(message, ...values) {
|
|
293
|
-
if (typeof message === "string") this.log("fatal", message, values[0] ?? {});
|
|
294
|
-
else if (typeof message === "function") this.logLazily("fatal", message);
|
|
295
|
-
else if (!Array.isArray(message)) this.log("fatal", "{*}", message);
|
|
296
|
-
else this.logTemplate("fatal", message, values);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* A logger implementation with contextual properties. Do not use this
|
|
301
|
-
* directly; use {@link Logger.with} instead. This class is exported
|
|
302
|
-
* for testing purposes.
|
|
303
|
-
*/
|
|
304
|
-
var LoggerCtx = class LoggerCtx {
|
|
305
|
-
logger;
|
|
306
|
-
properties;
|
|
307
|
-
constructor(logger, properties) {
|
|
308
|
-
this.logger = logger;
|
|
309
|
-
this.properties = properties;
|
|
310
|
-
}
|
|
311
|
-
get category() {
|
|
312
|
-
return this.logger.category;
|
|
313
|
-
}
|
|
314
|
-
get parent() {
|
|
315
|
-
return this.logger.parent;
|
|
316
|
-
}
|
|
317
|
-
getChild(subcategory) {
|
|
318
|
-
return this.logger.getChild(subcategory).with(this.properties);
|
|
319
|
-
}
|
|
320
|
-
with(properties) {
|
|
321
|
-
return new LoggerCtx(this.logger, {
|
|
322
|
-
...this.properties,
|
|
323
|
-
...properties
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
log(level, message, properties, bypassSinks) {
|
|
327
|
-
this.logger.log(level, message, typeof properties === "function" ? () => ({
|
|
328
|
-
...this.properties,
|
|
329
|
-
...properties()
|
|
330
|
-
}) : {
|
|
331
|
-
...this.properties,
|
|
332
|
-
...properties
|
|
333
|
-
}, bypassSinks);
|
|
334
|
-
}
|
|
335
|
-
logLazily(level, callback) {
|
|
336
|
-
this.logger.logLazily(level, callback, this.properties);
|
|
337
|
-
}
|
|
338
|
-
logTemplate(level, messageTemplate, values) {
|
|
339
|
-
this.logger.logTemplate(level, messageTemplate, values, this.properties);
|
|
340
|
-
}
|
|
341
|
-
emit(record) {
|
|
342
|
-
const recordWithContext = {
|
|
343
|
-
...record,
|
|
344
|
-
properties: {
|
|
345
|
-
...this.properties,
|
|
346
|
-
...record.properties
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
this.logger.emit(recordWithContext);
|
|
350
|
-
}
|
|
351
|
-
trace(message, ...values) {
|
|
352
|
-
if (typeof message === "string") this.log("trace", message, values[0] ?? {});
|
|
353
|
-
else if (typeof message === "function") this.logLazily("trace", message);
|
|
354
|
-
else if (!Array.isArray(message)) this.log("trace", "{*}", message);
|
|
355
|
-
else this.logTemplate("trace", message, values);
|
|
356
|
-
}
|
|
357
|
-
debug(message, ...values) {
|
|
358
|
-
if (typeof message === "string") this.log("debug", message, values[0] ?? {});
|
|
359
|
-
else if (typeof message === "function") this.logLazily("debug", message);
|
|
360
|
-
else if (!Array.isArray(message)) this.log("debug", "{*}", message);
|
|
361
|
-
else this.logTemplate("debug", message, values);
|
|
362
|
-
}
|
|
363
|
-
info(message, ...values) {
|
|
364
|
-
if (typeof message === "string") this.log("info", message, values[0] ?? {});
|
|
365
|
-
else if (typeof message === "function") this.logLazily("info", message);
|
|
366
|
-
else if (!Array.isArray(message)) this.log("info", "{*}", message);
|
|
367
|
-
else this.logTemplate("info", message, values);
|
|
368
|
-
}
|
|
369
|
-
warn(message, ...values) {
|
|
370
|
-
if (typeof message === "string") this.log("warning", message, values[0] ?? {});
|
|
371
|
-
else if (typeof message === "function") this.logLazily("warning", message);
|
|
372
|
-
else if (!Array.isArray(message)) this.log("warning", "{*}", message);
|
|
373
|
-
else this.logTemplate("warning", message, values);
|
|
374
|
-
}
|
|
375
|
-
warning(message, ...values) {
|
|
376
|
-
this.warn(message, ...values);
|
|
377
|
-
}
|
|
378
|
-
error(message, ...values) {
|
|
379
|
-
if (typeof message === "string") this.log("error", message, values[0] ?? {});
|
|
380
|
-
else if (typeof message === "function") this.logLazily("error", message);
|
|
381
|
-
else if (!Array.isArray(message)) this.log("error", "{*}", message);
|
|
382
|
-
else this.logTemplate("error", message, values);
|
|
383
|
-
}
|
|
384
|
-
fatal(message, ...values) {
|
|
385
|
-
if (typeof message === "string") this.log("fatal", message, values[0] ?? {});
|
|
386
|
-
else if (typeof message === "function") this.logLazily("fatal", message);
|
|
387
|
-
else if (!Array.isArray(message)) this.log("fatal", "{*}", message);
|
|
388
|
-
else this.logTemplate("fatal", message, values);
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
/**
|
|
392
|
-
* The meta logger. It is a logger with the category `["logtape", "meta"]`.
|
|
393
|
-
*/
|
|
394
|
-
const metaLogger = LoggerImpl.getLogger(["logtape", "meta"]);
|
|
395
|
-
/**
|
|
396
|
-
* Check if a property access key contains nested access patterns.
|
|
397
|
-
* @param key The property key to check.
|
|
398
|
-
* @returns True if the key contains nested access patterns.
|
|
399
|
-
*/
|
|
400
|
-
function isNestedAccess(key) {
|
|
401
|
-
return key.includes(".") || key.includes("[") || key.includes("?.");
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Safely access an own property from an object, blocking prototype pollution.
|
|
405
|
-
*
|
|
406
|
-
* @param obj The object to access the property from.
|
|
407
|
-
* @param key The property key to access.
|
|
408
|
-
* @returns The property value or undefined if not accessible.
|
|
409
|
-
*/
|
|
410
|
-
function getOwnProperty(obj, key) {
|
|
411
|
-
if (key === "__proto__" || key === "prototype" || key === "constructor") return void 0;
|
|
412
|
-
if ((typeof obj === "object" || typeof obj === "function") && obj !== null) return Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : void 0;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Parse the next segment from a property path string.
|
|
416
|
-
*
|
|
417
|
-
* @param path The full property path string.
|
|
418
|
-
* @param fromIndex The index to start parsing from.
|
|
419
|
-
* @returns The parsed segment and next index, or null if parsing fails.
|
|
420
|
-
*/
|
|
421
|
-
function parseNextSegment(path, fromIndex) {
|
|
422
|
-
const len = path.length;
|
|
423
|
-
let i = fromIndex;
|
|
424
|
-
if (i >= len) return null;
|
|
425
|
-
let segment;
|
|
426
|
-
if (path[i] === "[") {
|
|
427
|
-
i++;
|
|
428
|
-
if (i >= len) return null;
|
|
429
|
-
if (path[i] === "\"" || path[i] === "'") {
|
|
430
|
-
const quote = path[i];
|
|
431
|
-
i++;
|
|
432
|
-
let segmentStr = "";
|
|
433
|
-
while (i < len && path[i] !== quote) if (path[i] === "\\") {
|
|
434
|
-
i++;
|
|
435
|
-
if (i < len) {
|
|
436
|
-
const escapeChar = path[i];
|
|
437
|
-
switch (escapeChar) {
|
|
438
|
-
case "n":
|
|
439
|
-
segmentStr += "\n";
|
|
440
|
-
break;
|
|
441
|
-
case "t":
|
|
442
|
-
segmentStr += " ";
|
|
443
|
-
break;
|
|
444
|
-
case "r":
|
|
445
|
-
segmentStr += "\r";
|
|
446
|
-
break;
|
|
447
|
-
case "b":
|
|
448
|
-
segmentStr += "\b";
|
|
449
|
-
break;
|
|
450
|
-
case "f":
|
|
451
|
-
segmentStr += "\f";
|
|
452
|
-
break;
|
|
453
|
-
case "v":
|
|
454
|
-
segmentStr += "\v";
|
|
455
|
-
break;
|
|
456
|
-
case "0":
|
|
457
|
-
segmentStr += "\0";
|
|
458
|
-
break;
|
|
459
|
-
case "\\":
|
|
460
|
-
segmentStr += "\\";
|
|
461
|
-
break;
|
|
462
|
-
case "\"":
|
|
463
|
-
segmentStr += "\"";
|
|
464
|
-
break;
|
|
465
|
-
case "'":
|
|
466
|
-
segmentStr += "'";
|
|
467
|
-
break;
|
|
468
|
-
case "u":
|
|
469
|
-
if (i + 4 < len) {
|
|
470
|
-
const hex = path.slice(i + 1, i + 5);
|
|
471
|
-
const codePoint = Number.parseInt(hex, 16);
|
|
472
|
-
if (!Number.isNaN(codePoint)) {
|
|
473
|
-
segmentStr += String.fromCharCode(codePoint);
|
|
474
|
-
i += 4;
|
|
475
|
-
} else segmentStr += escapeChar;
|
|
476
|
-
} else segmentStr += escapeChar;
|
|
477
|
-
break;
|
|
478
|
-
default: segmentStr += escapeChar;
|
|
479
|
-
}
|
|
480
|
-
i++;
|
|
481
|
-
}
|
|
482
|
-
} else {
|
|
483
|
-
segmentStr += path[i];
|
|
484
|
-
i++;
|
|
485
|
-
}
|
|
486
|
-
if (i >= len) return null;
|
|
487
|
-
segment = segmentStr;
|
|
488
|
-
i++;
|
|
489
|
-
} else {
|
|
490
|
-
const startIndex = i;
|
|
491
|
-
while (i < len && path[i] !== "]" && path[i] !== "'" && path[i] !== "\"") i++;
|
|
492
|
-
if (i >= len) return null;
|
|
493
|
-
const indexStr = path.slice(startIndex, i);
|
|
494
|
-
if (indexStr.length === 0) return null;
|
|
495
|
-
const indexNum = Number(indexStr);
|
|
496
|
-
segment = Number.isNaN(indexNum) ? indexStr : indexNum;
|
|
497
|
-
}
|
|
498
|
-
while (i < len && path[i] !== "]") i++;
|
|
499
|
-
if (i < len) i++;
|
|
500
|
-
} else {
|
|
501
|
-
const startIndex = i;
|
|
502
|
-
while (i < len && path[i] !== "." && path[i] !== "[" && path[i] !== "?" && path[i] !== "]") i++;
|
|
503
|
-
segment = path.slice(startIndex, i);
|
|
504
|
-
if (segment.length === 0) return null;
|
|
505
|
-
}
|
|
506
|
-
if (i < len && path[i] === ".") i++;
|
|
507
|
-
return {
|
|
508
|
-
segment,
|
|
509
|
-
nextIndex: i
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Access a property or index on an object or array.
|
|
514
|
-
*
|
|
515
|
-
* @param obj The object or array to access.
|
|
516
|
-
* @param segment The property key or array index.
|
|
517
|
-
* @returns The accessed value or undefined if not accessible.
|
|
518
|
-
*/
|
|
519
|
-
function accessProperty(obj, segment) {
|
|
520
|
-
if (typeof segment === "string") return getOwnProperty(obj, segment);
|
|
521
|
-
if (Array.isArray(obj) && segment >= 0 && segment < obj.length) return obj[segment];
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Resolve a nested property path from an object.
|
|
525
|
-
*
|
|
526
|
-
* There are two types of property access patterns:
|
|
527
|
-
* 1. Array/index access: [0] or ["prop"]
|
|
528
|
-
* 2. Property access: prop or prop?.next
|
|
529
|
-
*
|
|
530
|
-
* @param obj The object to traverse.
|
|
531
|
-
* @param path The property path (e.g., "user.name", "users[0].email", "user['full-name']").
|
|
532
|
-
* @returns The resolved value or undefined if path doesn't exist.
|
|
533
|
-
*/
|
|
534
|
-
function resolvePropertyPath(obj, path) {
|
|
535
|
-
if (obj == null) return void 0;
|
|
536
|
-
if (path.length === 0 || path.endsWith(".")) return void 0;
|
|
537
|
-
let current = obj;
|
|
538
|
-
let i = 0;
|
|
539
|
-
const len = path.length;
|
|
540
|
-
while (i < len) {
|
|
541
|
-
if (path.slice(i, i + 2) === "?.") {
|
|
542
|
-
i += 2;
|
|
543
|
-
if (current == null) return void 0;
|
|
544
|
-
} else if (current == null) return void 0;
|
|
545
|
-
const result = parseNextSegment(path, i);
|
|
546
|
-
if (result === null) return void 0;
|
|
547
|
-
const { segment, nextIndex } = result;
|
|
548
|
-
i = nextIndex;
|
|
549
|
-
current = accessProperty(current, segment);
|
|
550
|
-
if (current === void 0) return void 0;
|
|
551
|
-
}
|
|
552
|
-
return current;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Parse a message template into a message template array and a values array.
|
|
556
|
-
*
|
|
557
|
-
* Placeholders to be replaced with `values` are indicated by keys in curly braces
|
|
558
|
-
* (e.g., `{value}`). The system supports both simple property access and nested
|
|
559
|
-
* property access patterns:
|
|
560
|
-
*
|
|
561
|
-
* **Simple property access:**
|
|
562
|
-
* ```ts
|
|
563
|
-
* parseMessageTemplate("Hello, {user}!", { user: "foo" })
|
|
564
|
-
* // Returns: ["Hello, ", "foo", "!"]
|
|
565
|
-
* ```
|
|
566
|
-
*
|
|
567
|
-
* **Nested property access (dot notation):**
|
|
568
|
-
* ```ts
|
|
569
|
-
* parseMessageTemplate("Hello, {user.name}!", {
|
|
570
|
-
* user: { name: "foo", email: "foo@example.com" }
|
|
571
|
-
* })
|
|
572
|
-
* // Returns: ["Hello, ", "foo", "!"]
|
|
573
|
-
* ```
|
|
574
|
-
*
|
|
575
|
-
* **Array indexing:**
|
|
576
|
-
* ```ts
|
|
577
|
-
* parseMessageTemplate("First: {users[0]}", {
|
|
578
|
-
* users: ["foo", "bar", "baz"]
|
|
579
|
-
* })
|
|
580
|
-
* // Returns: ["First: ", "foo", ""]
|
|
581
|
-
* ```
|
|
582
|
-
*
|
|
583
|
-
* **Bracket notation for special property names:**
|
|
584
|
-
* ```ts
|
|
585
|
-
* parseMessageTemplate("Name: {user[\"full-name\"]}", {
|
|
586
|
-
* user: { "full-name": "foo bar" }
|
|
587
|
-
* })
|
|
588
|
-
* // Returns: ["Name: ", "foo bar", ""]
|
|
589
|
-
* ```
|
|
590
|
-
*
|
|
591
|
-
* **Optional chaining for safe navigation:**
|
|
592
|
-
* ```ts
|
|
593
|
-
* parseMessageTemplate("Email: {user?.profile?.email}", {
|
|
594
|
-
* user: { name: "foo" }
|
|
595
|
-
* })
|
|
596
|
-
* // Returns: ["Email: ", undefined, ""]
|
|
597
|
-
* ```
|
|
598
|
-
*
|
|
599
|
-
* **Wildcard patterns:**
|
|
600
|
-
* - `{*}` - Replaced with the entire properties object
|
|
601
|
-
* - `{ key-with-whitespace }` - Whitespace is trimmed when looking up keys
|
|
602
|
-
*
|
|
603
|
-
* **Escaping:**
|
|
604
|
-
* - `{{` and `}}` are escaped literal braces
|
|
605
|
-
*
|
|
606
|
-
* **Error handling:**
|
|
607
|
-
* - Non-existent paths return `undefined`
|
|
608
|
-
* - Malformed expressions resolve to `undefined` without throwing errors
|
|
609
|
-
* - Out of bounds array access returns `undefined`
|
|
610
|
-
*
|
|
611
|
-
* @param template The message template string containing placeholders.
|
|
612
|
-
* @param properties The values to replace placeholders with.
|
|
613
|
-
* @returns The message template array with values interleaved between text segments.
|
|
614
|
-
*/
|
|
615
|
-
function parseMessageTemplate(template, properties) {
|
|
616
|
-
const length = template.length;
|
|
617
|
-
if (length === 0) return [""];
|
|
618
|
-
if (!template.includes("{")) return [template];
|
|
619
|
-
const message = [];
|
|
620
|
-
let startIndex = 0;
|
|
621
|
-
for (let i = 0; i < length; i++) {
|
|
622
|
-
const char = template[i];
|
|
623
|
-
if (char === "{") {
|
|
624
|
-
if ((i + 1 < length ? template[i + 1] : "") === "{") {
|
|
625
|
-
i++;
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
const closeIndex = template.indexOf("}", i + 1);
|
|
629
|
-
if (closeIndex === -1) continue;
|
|
630
|
-
const beforeText = template.slice(startIndex, i);
|
|
631
|
-
message.push(beforeText.replace(/{{/g, "{").replace(/}}/g, "}"));
|
|
632
|
-
const key = template.slice(i + 1, closeIndex);
|
|
633
|
-
let prop;
|
|
634
|
-
const trimmedKey = key.trim();
|
|
635
|
-
if (trimmedKey === "*") prop = key in properties ? properties[key] : "*" in properties ? properties["*"] : properties;
|
|
636
|
-
else {
|
|
637
|
-
if (key !== trimmedKey) prop = key in properties ? properties[key] : properties[trimmedKey];
|
|
638
|
-
else prop = properties[key];
|
|
639
|
-
if (prop === void 0 && isNestedAccess(trimmedKey)) prop = resolvePropertyPath(properties, trimmedKey);
|
|
640
|
-
}
|
|
641
|
-
message.push(prop);
|
|
642
|
-
i = closeIndex;
|
|
643
|
-
startIndex = i + 1;
|
|
644
|
-
} else if (char === "}" && i + 1 < length && template[i + 1] === "}") i++;
|
|
645
|
-
}
|
|
646
|
-
const remainingText = template.slice(startIndex);
|
|
647
|
-
message.push(remainingText.replace(/{{/g, "{").replace(/}}/g, "}"));
|
|
648
|
-
return message;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Render a message template with values.
|
|
652
|
-
* @param template The message template.
|
|
653
|
-
* @param values The message template values.
|
|
654
|
-
* @returns The message template values interleaved between the substitution
|
|
655
|
-
* values.
|
|
656
|
-
*/
|
|
657
|
-
function renderMessage(template, values) {
|
|
658
|
-
const args = [];
|
|
659
|
-
for (let i = 0; i < template.length; i++) {
|
|
660
|
-
args.push(template[i]);
|
|
661
|
-
if (i < values.length) args.push(values[i]);
|
|
662
|
-
}
|
|
663
|
-
return args;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
//#endregion
|
|
667
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/context.js
|
|
668
|
-
/**
|
|
669
|
-
* Internal symbol for storing category prefix in context.
|
|
670
|
-
*/
|
|
671
|
-
const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
|
|
672
|
-
/**
|
|
673
|
-
* Gets the current category prefix from context local storage.
|
|
674
|
-
* @returns The current category prefix, or an empty array if not set.
|
|
675
|
-
* @since 1.3.0
|
|
676
|
-
*/
|
|
677
|
-
function getCategoryPrefix() {
|
|
678
|
-
const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
|
|
679
|
-
if (store == null) return [];
|
|
680
|
-
const prefix = store[categoryPrefixSymbol];
|
|
681
|
-
return Array.isArray(prefix) ? prefix : [];
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Gets the current implicit context from context local storage, excluding
|
|
685
|
-
* internal symbol keys (like category prefix).
|
|
686
|
-
* @returns The current implicit context without internal symbol keys.
|
|
687
|
-
* @since 1.3.0
|
|
688
|
-
*/
|
|
689
|
-
function getImplicitContext() {
|
|
690
|
-
const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
|
|
691
|
-
if (store == null) return {};
|
|
692
|
-
const result = {};
|
|
693
|
-
for (const key of Object.keys(store)) result[key] = store[key];
|
|
694
|
-
return result;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
//#endregion
|
|
698
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/util.node.js
|
|
699
|
-
var util_node_exports = /* @__PURE__ */ __exportAll({ inspect: () => inspect$1 });
|
|
700
|
-
function inspect$1(obj, options) {
|
|
701
|
-
return util.inspect(obj, options);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
//#endregion
|
|
705
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/formatter.js
|
|
706
|
-
/**
|
|
707
|
-
* The severity level abbreviations.
|
|
708
|
-
*/
|
|
709
|
-
const levelAbbreviations = {
|
|
710
|
-
"trace": "TRC",
|
|
711
|
-
"debug": "DBG",
|
|
712
|
-
"info": "INF",
|
|
713
|
-
"warning": "WRN",
|
|
714
|
-
"error": "ERR",
|
|
715
|
-
"fatal": "FTL"
|
|
716
|
-
};
|
|
717
|
-
/**
|
|
718
|
-
* A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
|
|
719
|
-
* and in Node.js/Bun it is `util.inspect()`. If neither is available, it
|
|
720
|
-
* falls back to {@link JSON.stringify}.
|
|
721
|
-
*
|
|
722
|
-
* @param value The value to inspect.
|
|
723
|
-
* @param options The options for inspecting the value.
|
|
724
|
-
* If `colors` is `true`, the output will be ANSI-colored.
|
|
725
|
-
* @returns The string representation of the value.
|
|
726
|
-
*/
|
|
727
|
-
const inspect = typeof document !== "undefined" || typeof navigator !== "undefined" && navigator.product === "ReactNative" ? (v) => JSON.stringify(v) : "Deno" in globalThis && "inspect" in globalThis.Deno && typeof globalThis.Deno.inspect === "function" ? (v, opts) => globalThis.Deno.inspect(v, {
|
|
728
|
-
strAbbreviateSize: Infinity,
|
|
729
|
-
iterableLimit: Infinity,
|
|
730
|
-
...opts
|
|
731
|
-
}) : util_node_exports != null && "inspect" in util_node_exports && typeof inspect$1 === "function" ? (v, opts) => inspect$1(v, {
|
|
732
|
-
maxArrayLength: Infinity,
|
|
733
|
-
maxStringLength: Infinity,
|
|
734
|
-
...opts
|
|
735
|
-
}) : (v) => JSON.stringify(v);
|
|
736
|
-
function padZero(num) {
|
|
737
|
-
return num < 10 ? `0${num}` : `${num}`;
|
|
738
|
-
}
|
|
739
|
-
function padThree(num) {
|
|
740
|
-
return num < 10 ? `00${num}` : num < 100 ? `0${num}` : `${num}`;
|
|
741
|
-
}
|
|
742
|
-
const timestampFormatters = {
|
|
743
|
-
"date-time-timezone": (ts) => {
|
|
744
|
-
const d = new Date(ts);
|
|
745
|
-
return `${d.getUTCFullYear()}-${padZero(d.getUTCMonth() + 1)}-${padZero(d.getUTCDate())} ${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())} +00:00`;
|
|
746
|
-
},
|
|
747
|
-
"date-time-tz": (ts) => {
|
|
748
|
-
const d = new Date(ts);
|
|
749
|
-
return `${d.getUTCFullYear()}-${padZero(d.getUTCMonth() + 1)}-${padZero(d.getUTCDate())} ${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())} +00`;
|
|
750
|
-
},
|
|
751
|
-
"date-time": (ts) => {
|
|
752
|
-
const d = new Date(ts);
|
|
753
|
-
return `${d.getUTCFullYear()}-${padZero(d.getUTCMonth() + 1)}-${padZero(d.getUTCDate())} ${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())}`;
|
|
754
|
-
},
|
|
755
|
-
"time-timezone": (ts) => {
|
|
756
|
-
const d = new Date(ts);
|
|
757
|
-
return `${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())} +00:00`;
|
|
758
|
-
},
|
|
759
|
-
"time-tz": (ts) => {
|
|
760
|
-
const d = new Date(ts);
|
|
761
|
-
return `${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())} +00`;
|
|
762
|
-
},
|
|
763
|
-
"time": (ts) => {
|
|
764
|
-
const d = new Date(ts);
|
|
765
|
-
return `${padZero(d.getUTCHours())}:${padZero(d.getUTCMinutes())}:${padZero(d.getUTCSeconds())}.${padThree(d.getUTCMilliseconds())}`;
|
|
766
|
-
},
|
|
767
|
-
"date": (ts) => {
|
|
768
|
-
const d = new Date(ts);
|
|
769
|
-
return `${d.getUTCFullYear()}-${padZero(d.getUTCMonth() + 1)}-${padZero(d.getUTCDate())}`;
|
|
770
|
-
},
|
|
771
|
-
"rfc3339": (ts) => new Date(ts).toISOString(),
|
|
772
|
-
"none": () => null
|
|
773
|
-
};
|
|
774
|
-
const levelRenderersCache = {
|
|
775
|
-
ABBR: levelAbbreviations,
|
|
776
|
-
abbr: {
|
|
777
|
-
trace: "trc",
|
|
778
|
-
debug: "dbg",
|
|
779
|
-
info: "inf",
|
|
780
|
-
warning: "wrn",
|
|
781
|
-
error: "err",
|
|
782
|
-
fatal: "ftl"
|
|
783
|
-
},
|
|
784
|
-
FULL: {
|
|
785
|
-
trace: "TRACE",
|
|
786
|
-
debug: "DEBUG",
|
|
787
|
-
info: "INFO",
|
|
788
|
-
warning: "WARNING",
|
|
789
|
-
error: "ERROR",
|
|
790
|
-
fatal: "FATAL"
|
|
791
|
-
},
|
|
792
|
-
full: {
|
|
793
|
-
trace: "trace",
|
|
794
|
-
debug: "debug",
|
|
795
|
-
info: "info",
|
|
796
|
-
warning: "warning",
|
|
797
|
-
error: "error",
|
|
798
|
-
fatal: "fatal"
|
|
799
|
-
},
|
|
800
|
-
L: {
|
|
801
|
-
trace: "T",
|
|
802
|
-
debug: "D",
|
|
803
|
-
info: "I",
|
|
804
|
-
warning: "W",
|
|
805
|
-
error: "E",
|
|
806
|
-
fatal: "F"
|
|
807
|
-
},
|
|
808
|
-
l: {
|
|
809
|
-
trace: "t",
|
|
810
|
-
debug: "d",
|
|
811
|
-
info: "i",
|
|
812
|
-
warning: "w",
|
|
813
|
-
error: "e",
|
|
814
|
-
fatal: "f"
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
/**
|
|
818
|
-
* Get a text formatter with the specified options. Although it's flexible
|
|
819
|
-
* enough to create a custom formatter, if you want more control, you can
|
|
820
|
-
* create a custom formatter that satisfies the {@link TextFormatter} type
|
|
821
|
-
* instead.
|
|
822
|
-
*
|
|
823
|
-
* For more information on the options, see {@link TextFormatterOptions}.
|
|
824
|
-
*
|
|
825
|
-
* By default, the formatter formats log records as follows:
|
|
826
|
-
*
|
|
827
|
-
* ```
|
|
828
|
-
* 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
|
|
829
|
-
* ```
|
|
830
|
-
* @param options The options for the text formatter.
|
|
831
|
-
* @returns The text formatter.
|
|
832
|
-
* @since 0.6.0
|
|
833
|
-
*/
|
|
834
|
-
function getTextFormatter(options = {}) {
|
|
835
|
-
const timestampRenderer = (() => {
|
|
836
|
-
const tsOption = options.timestamp;
|
|
837
|
-
if (tsOption == null) return timestampFormatters["date-time-timezone"];
|
|
838
|
-
else if (tsOption === "disabled") return timestampFormatters["none"];
|
|
839
|
-
else if (typeof tsOption === "string" && tsOption in timestampFormatters) return timestampFormatters[tsOption];
|
|
840
|
-
else return tsOption;
|
|
841
|
-
})();
|
|
842
|
-
const categorySeparator = options.category ?? "·";
|
|
843
|
-
const valueRenderer = options.value ? (v) => options.value(v, inspect) : inspect;
|
|
844
|
-
const levelRenderer = (() => {
|
|
845
|
-
const levelOption = options.level;
|
|
846
|
-
if (levelOption == null || levelOption === "ABBR") return (level) => levelRenderersCache.ABBR[level];
|
|
847
|
-
else if (levelOption === "abbr") return (level) => levelRenderersCache.abbr[level];
|
|
848
|
-
else if (levelOption === "FULL") return (level) => levelRenderersCache.FULL[level];
|
|
849
|
-
else if (levelOption === "full") return (level) => levelRenderersCache.full[level];
|
|
850
|
-
else if (levelOption === "L") return (level) => levelRenderersCache.L[level];
|
|
851
|
-
else if (levelOption === "l") return (level) => levelRenderersCache.l[level];
|
|
852
|
-
else return levelOption;
|
|
853
|
-
})();
|
|
854
|
-
const formatter = options.format ?? (({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
|
|
855
|
-
return (record) => {
|
|
856
|
-
const msgParts = record.message;
|
|
857
|
-
const msgLen = msgParts.length;
|
|
858
|
-
let message;
|
|
859
|
-
if (msgLen === 1) message = msgParts[0];
|
|
860
|
-
else if (msgLen <= 6) {
|
|
861
|
-
message = "";
|
|
862
|
-
for (let i = 0; i < msgLen; i++) message += i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
|
|
863
|
-
} else {
|
|
864
|
-
const parts = new Array(msgLen);
|
|
865
|
-
for (let i = 0; i < msgLen; i++) parts[i] = i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
|
|
866
|
-
message = parts.join("");
|
|
867
|
-
}
|
|
868
|
-
return `${formatter({
|
|
869
|
-
timestamp: timestampRenderer(record.timestamp),
|
|
870
|
-
level: levelRenderer(record.level),
|
|
871
|
-
category: typeof categorySeparator === "function" ? categorySeparator(record.category) : record.category.join(categorySeparator),
|
|
872
|
-
message,
|
|
873
|
-
record
|
|
874
|
-
})}\n`;
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* The default text formatter. This formatter formats log records as follows:
|
|
879
|
-
*
|
|
880
|
-
* ```
|
|
881
|
-
* 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
|
|
882
|
-
* ```
|
|
883
|
-
*
|
|
884
|
-
* @param record The log record to format.
|
|
885
|
-
* @returns The formatted log record.
|
|
886
|
-
*/
|
|
887
|
-
const defaultTextFormatter = getTextFormatter();
|
|
888
|
-
const RESET = "\x1B[0m";
|
|
889
|
-
const ansiColors = {
|
|
890
|
-
black: "\x1B[30m",
|
|
891
|
-
red: "\x1B[31m",
|
|
892
|
-
green: "\x1B[32m",
|
|
893
|
-
yellow: "\x1B[33m",
|
|
894
|
-
blue: "\x1B[34m",
|
|
895
|
-
magenta: "\x1B[35m",
|
|
896
|
-
cyan: "\x1B[36m",
|
|
897
|
-
white: "\x1B[37m"
|
|
898
|
-
};
|
|
899
|
-
const ansiStyles = {
|
|
900
|
-
bold: "\x1B[1m",
|
|
901
|
-
dim: "\x1B[2m",
|
|
902
|
-
italic: "\x1B[3m",
|
|
903
|
-
underline: "\x1B[4m",
|
|
904
|
-
strikethrough: "\x1B[9m"
|
|
905
|
-
};
|
|
906
|
-
const defaultLevelColors = {
|
|
907
|
-
trace: null,
|
|
908
|
-
debug: "blue",
|
|
909
|
-
info: "green",
|
|
910
|
-
warning: "yellow",
|
|
911
|
-
error: "red",
|
|
912
|
-
fatal: "magenta"
|
|
913
|
-
};
|
|
914
|
-
/**
|
|
915
|
-
* Get an ANSI color formatter with the specified options.
|
|
916
|
-
*
|
|
917
|
-
* 
|
|
918
|
-
* @param option The options for the ANSI color formatter.
|
|
919
|
-
* @returns The ANSI color formatter.
|
|
920
|
-
* @since 0.6.0
|
|
921
|
-
*/
|
|
922
|
-
function getAnsiColorFormatter(options = {}) {
|
|
923
|
-
const format = options.format;
|
|
924
|
-
const timestampStyle = typeof options.timestampStyle === "undefined" ? "dim" : options.timestampStyle;
|
|
925
|
-
const timestampColor = options.timestampColor ?? null;
|
|
926
|
-
const timestampPrefix = `${timestampStyle == null ? "" : ansiStyles[timestampStyle]}${timestampColor == null ? "" : ansiColors[timestampColor]}`;
|
|
927
|
-
const timestampSuffix = timestampStyle == null && timestampColor == null ? "" : RESET;
|
|
928
|
-
const levelStyle = typeof options.levelStyle === "undefined" ? "bold" : options.levelStyle;
|
|
929
|
-
const levelColors = options.levelColors ?? defaultLevelColors;
|
|
930
|
-
const categoryStyle = typeof options.categoryStyle === "undefined" ? "dim" : options.categoryStyle;
|
|
931
|
-
const categoryColor = options.categoryColor ?? null;
|
|
932
|
-
const categoryPrefix = `${categoryStyle == null ? "" : ansiStyles[categoryStyle]}${categoryColor == null ? "" : ansiColors[categoryColor]}`;
|
|
933
|
-
const categorySuffix = categoryStyle == null && categoryColor == null ? "" : RESET;
|
|
934
|
-
return getTextFormatter({
|
|
935
|
-
timestamp: "date-time-tz",
|
|
936
|
-
value(value, fallbackInspect) {
|
|
937
|
-
return fallbackInspect(value, { colors: true });
|
|
938
|
-
},
|
|
939
|
-
...options,
|
|
940
|
-
format({ timestamp, level, category, message, record }) {
|
|
941
|
-
const levelColor = levelColors[record.level];
|
|
942
|
-
timestamp = `${timestampPrefix}${timestamp}${timestampSuffix}`;
|
|
943
|
-
level = `${levelStyle == null ? "" : ansiStyles[levelStyle]}${levelColor == null ? "" : ansiColors[levelColor]}${level}${levelStyle == null && levelColor == null ? "" : RESET}`;
|
|
944
|
-
return format == null ? `${timestamp} ${level} ${categoryPrefix}${category}:${categorySuffix} ${message}` : format({
|
|
945
|
-
timestamp,
|
|
946
|
-
level,
|
|
947
|
-
category: `${categoryPrefix}${category}${categorySuffix}`,
|
|
948
|
-
message,
|
|
949
|
-
record
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* A text formatter that uses ANSI colors to format log records.
|
|
956
|
-
*
|
|
957
|
-
* 
|
|
958
|
-
*
|
|
959
|
-
* @param record The log record to format.
|
|
960
|
-
* @returns The formatted log record.
|
|
961
|
-
* @since 0.5.0
|
|
962
|
-
*/
|
|
963
|
-
const ansiColorFormatter = getAnsiColorFormatter();
|
|
964
|
-
/**
|
|
965
|
-
* Get a [JSON Lines] formatter with the specified options. The log records
|
|
966
|
-
* will be rendered as JSON objects, one per line, which is a common format
|
|
967
|
-
* for log files. This format is also known as Newline-Delimited JSON (NDJSON).
|
|
968
|
-
* It looks like this:
|
|
969
|
-
*
|
|
970
|
-
* ```json
|
|
971
|
-
* {"@timestamp":"2023-11-14T22:13:20.000Z","level":"INFO","message":"Hello, world!","logger":"my.logger","properties":{"key":"value"}}
|
|
972
|
-
* ```
|
|
973
|
-
*
|
|
974
|
-
* [JSON Lines]: https://jsonlines.org/
|
|
975
|
-
* @param options The options for the JSON Lines formatter.
|
|
976
|
-
* @returns The JSON Lines formatter.
|
|
977
|
-
* @since 0.11.0
|
|
978
|
-
*/
|
|
979
|
-
function getJsonLinesFormatter(options = {}) {
|
|
980
|
-
if (!options.categorySeparator && !options.message && !options.properties) return (record) => {
|
|
981
|
-
if (record.message.length === 3) return JSON.stringify({
|
|
982
|
-
"@timestamp": new Date(record.timestamp).toISOString(),
|
|
983
|
-
level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
|
|
984
|
-
message: record.message[0] + JSON.stringify(record.message[1]) + record.message[2],
|
|
985
|
-
logger: record.category.join("."),
|
|
986
|
-
properties: record.properties
|
|
987
|
-
}) + "\n";
|
|
988
|
-
if (record.message.length === 1) return JSON.stringify({
|
|
989
|
-
"@timestamp": new Date(record.timestamp).toISOString(),
|
|
990
|
-
level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
|
|
991
|
-
message: record.message[0],
|
|
992
|
-
logger: record.category.join("."),
|
|
993
|
-
properties: record.properties
|
|
994
|
-
}) + "\n";
|
|
995
|
-
let msg = record.message[0];
|
|
996
|
-
for (let i = 1; i < record.message.length; i++) msg += i & 1 ? JSON.stringify(record.message[i]) : record.message[i];
|
|
997
|
-
return JSON.stringify({
|
|
998
|
-
"@timestamp": new Date(record.timestamp).toISOString(),
|
|
999
|
-
level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
|
|
1000
|
-
message: msg,
|
|
1001
|
-
logger: record.category.join("."),
|
|
1002
|
-
properties: record.properties
|
|
1003
|
-
}) + "\n";
|
|
1004
|
-
};
|
|
1005
|
-
const isTemplateMessage = options.message === "template";
|
|
1006
|
-
const propertiesOption = options.properties ?? "nest:properties";
|
|
1007
|
-
let joinCategory;
|
|
1008
|
-
if (typeof options.categorySeparator === "function") joinCategory = options.categorySeparator;
|
|
1009
|
-
else {
|
|
1010
|
-
const separator = options.categorySeparator ?? ".";
|
|
1011
|
-
joinCategory = (category) => category.join(separator);
|
|
1012
|
-
}
|
|
1013
|
-
let getProperties;
|
|
1014
|
-
if (propertiesOption === "flatten") getProperties = (properties) => properties;
|
|
1015
|
-
else if (propertiesOption.startsWith("prepend:")) {
|
|
1016
|
-
const prefix = propertiesOption.substring(8);
|
|
1017
|
-
if (prefix === "") throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be of the form "prepend:<prefix>" where <prefix> is a non-empty string.`);
|
|
1018
|
-
getProperties = (properties) => {
|
|
1019
|
-
const result = {};
|
|
1020
|
-
for (const key in properties) result[`${prefix}${key}`] = properties[key];
|
|
1021
|
-
return result;
|
|
1022
|
-
};
|
|
1023
|
-
} else if (propertiesOption.startsWith("nest:")) {
|
|
1024
|
-
const key = propertiesOption.substring(5);
|
|
1025
|
-
getProperties = (properties) => ({ [key]: properties });
|
|
1026
|
-
} else throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);
|
|
1027
|
-
let getMessage;
|
|
1028
|
-
if (isTemplateMessage) getMessage = (record) => {
|
|
1029
|
-
if (typeof record.rawMessage === "string") return record.rawMessage;
|
|
1030
|
-
let msg = "";
|
|
1031
|
-
for (let i = 0; i < record.rawMessage.length; i++) msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
|
|
1032
|
-
return msg;
|
|
1033
|
-
};
|
|
1034
|
-
else getMessage = (record) => {
|
|
1035
|
-
const msgLen = record.message.length;
|
|
1036
|
-
if (msgLen === 1) return record.message[0];
|
|
1037
|
-
let msg = "";
|
|
1038
|
-
for (let i = 0; i < msgLen; i++) msg += i % 2 < 1 ? record.message[i] : JSON.stringify(record.message[i]);
|
|
1039
|
-
return msg;
|
|
1040
|
-
};
|
|
1041
|
-
return (record) => {
|
|
1042
|
-
return JSON.stringify({
|
|
1043
|
-
"@timestamp": new Date(record.timestamp).toISOString(),
|
|
1044
|
-
level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
|
|
1045
|
-
message: getMessage(record),
|
|
1046
|
-
logger: joinCategory(record.category),
|
|
1047
|
-
...getProperties(record.properties)
|
|
1048
|
-
}) + "\n";
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* The default [JSON Lines] formatter. This formatter formats log records
|
|
1053
|
-
* as JSON objects, one per line, which is a common format for log files.
|
|
1054
|
-
* It looks like this:
|
|
1055
|
-
*
|
|
1056
|
-
* ```json
|
|
1057
|
-
* {"@timestamp":"2023-11-14T22:13:20.000Z","level":"INFO","message":"Hello, world!","logger":"my.logger","properties":{"key":"value"}}
|
|
1058
|
-
* ```
|
|
1059
|
-
*
|
|
1060
|
-
* You can customize the output by passing options to
|
|
1061
|
-
* {@link getJsonLinesFormatter}. For example, you can change the category
|
|
1062
|
-
* separator, the message format, and how the properties are formatted.
|
|
1063
|
-
*
|
|
1064
|
-
* [JSON Lines]: https://jsonlines.org/
|
|
1065
|
-
* @since 0.11.0
|
|
1066
|
-
*/
|
|
1067
|
-
const jsonLinesFormatter = getJsonLinesFormatter();
|
|
1068
|
-
/**
|
|
1069
|
-
* The styles for the log level in the console.
|
|
1070
|
-
*/
|
|
1071
|
-
const logLevelStyles = {
|
|
1072
|
-
"trace": "background-color: gray; color: white;",
|
|
1073
|
-
"debug": "background-color: gray; color: white;",
|
|
1074
|
-
"info": "background-color: white; color: black;",
|
|
1075
|
-
"warning": "background-color: orange; color: black;",
|
|
1076
|
-
"error": "background-color: red; color: white;",
|
|
1077
|
-
"fatal": "background-color: maroon; color: white;"
|
|
1078
|
-
};
|
|
1079
|
-
/**
|
|
1080
|
-
* The default console formatter.
|
|
1081
|
-
*
|
|
1082
|
-
* @param record The log record to format.
|
|
1083
|
-
* @returns The formatted log record, as an array of arguments for
|
|
1084
|
-
* {@link console.log}.
|
|
1085
|
-
*/
|
|
1086
|
-
function defaultConsoleFormatter(record) {
|
|
1087
|
-
let msg = "";
|
|
1088
|
-
const values = [];
|
|
1089
|
-
for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) msg += record.message[i];
|
|
1090
|
-
else {
|
|
1091
|
-
msg += "%o";
|
|
1092
|
-
values.push(record.message[i]);
|
|
1093
|
-
}
|
|
1094
|
-
const date = new Date(record.timestamp);
|
|
1095
|
-
return [
|
|
1096
|
-
`%c${`${date.getUTCHours().toString().padStart(2, "0")}:${date.getUTCMinutes().toString().padStart(2, "0")}:${date.getUTCSeconds().toString().padStart(2, "0")}.${date.getUTCMilliseconds().toString().padStart(3, "0")}`} %c${levelAbbreviations[record.level]}%c %c${record.category.join("·")} %c${msg}`,
|
|
1097
|
-
"color: gray;",
|
|
1098
|
-
logLevelStyles[record.level],
|
|
1099
|
-
"background-color: default;",
|
|
1100
|
-
"color: gray;",
|
|
1101
|
-
"color: default;",
|
|
1102
|
-
...values
|
|
1103
|
-
];
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
//#endregion
|
|
1107
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/sink.js
|
|
1108
|
-
/**
|
|
1109
|
-
* A console sink factory that returns a sink that logs to the console.
|
|
1110
|
-
*
|
|
1111
|
-
* @param options The options for the sink.
|
|
1112
|
-
* @returns A sink that logs to the console. If `nonBlocking` is enabled,
|
|
1113
|
-
* returns a sink that also implements {@link Disposable}.
|
|
1114
|
-
*/
|
|
1115
|
-
function getConsoleSink(options = {}) {
|
|
1116
|
-
const formatter = options.formatter ?? defaultConsoleFormatter;
|
|
1117
|
-
const levelMap = {
|
|
1118
|
-
trace: "debug",
|
|
1119
|
-
debug: "debug",
|
|
1120
|
-
info: "info",
|
|
1121
|
-
warning: "warn",
|
|
1122
|
-
error: "error",
|
|
1123
|
-
fatal: "error",
|
|
1124
|
-
...options.levelMap ?? {}
|
|
1125
|
-
};
|
|
1126
|
-
const console = options.console ?? globalThis.console;
|
|
1127
|
-
const baseSink = (record) => {
|
|
1128
|
-
const args = formatter(record);
|
|
1129
|
-
const method = levelMap[record.level];
|
|
1130
|
-
if (method === void 0) throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
1131
|
-
if (typeof args === "string") {
|
|
1132
|
-
const msg = args.replace(/\r?\n$/, "");
|
|
1133
|
-
console[method](msg);
|
|
1134
|
-
} else console[method](...args);
|
|
1135
|
-
};
|
|
1136
|
-
if (!options.nonBlocking) return baseSink;
|
|
1137
|
-
const nonBlockingConfig = options.nonBlocking === true ? {} : options.nonBlocking;
|
|
1138
|
-
const bufferSize = nonBlockingConfig.bufferSize ?? 100;
|
|
1139
|
-
const flushInterval = nonBlockingConfig.flushInterval ?? 100;
|
|
1140
|
-
const buffer = [];
|
|
1141
|
-
let flushTimer = null;
|
|
1142
|
-
let disposed = false;
|
|
1143
|
-
let flushScheduled = false;
|
|
1144
|
-
const maxBufferSize = bufferSize * 2;
|
|
1145
|
-
function flush() {
|
|
1146
|
-
if (buffer.length === 0) return;
|
|
1147
|
-
const records = buffer.splice(0);
|
|
1148
|
-
for (const record of records) try {
|
|
1149
|
-
baseSink(record);
|
|
1150
|
-
} catch {}
|
|
1151
|
-
}
|
|
1152
|
-
function scheduleFlush() {
|
|
1153
|
-
if (flushScheduled) return;
|
|
1154
|
-
flushScheduled = true;
|
|
1155
|
-
setTimeout(() => {
|
|
1156
|
-
flushScheduled = false;
|
|
1157
|
-
flush();
|
|
1158
|
-
}, 0);
|
|
1159
|
-
}
|
|
1160
|
-
function startFlushTimer() {
|
|
1161
|
-
if (flushTimer !== null || disposed) return;
|
|
1162
|
-
flushTimer = setInterval(() => {
|
|
1163
|
-
flush();
|
|
1164
|
-
}, flushInterval);
|
|
1165
|
-
}
|
|
1166
|
-
const nonBlockingSink = (record) => {
|
|
1167
|
-
if (disposed) return;
|
|
1168
|
-
if (buffer.length >= maxBufferSize) buffer.shift();
|
|
1169
|
-
buffer.push(record);
|
|
1170
|
-
if (buffer.length >= bufferSize) scheduleFlush();
|
|
1171
|
-
else if (flushTimer === null) startFlushTimer();
|
|
1172
|
-
};
|
|
1173
|
-
nonBlockingSink[Symbol.dispose] = () => {
|
|
1174
|
-
disposed = true;
|
|
1175
|
-
if (flushTimer !== null) {
|
|
1176
|
-
clearInterval(flushTimer);
|
|
1177
|
-
flushTimer = null;
|
|
1178
|
-
}
|
|
1179
|
-
flush();
|
|
1180
|
-
};
|
|
1181
|
-
return nonBlockingSink;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
//#endregion
|
|
1185
|
-
//#region ../../node_modules/.pnpm/@logtape+logtape@1.3.5/node_modules/@logtape/logtape/dist/config.js
|
|
1186
|
-
/**
|
|
1187
|
-
* The current configuration, if any. Otherwise, `null`.
|
|
1188
|
-
*/
|
|
1189
|
-
let currentConfig = null;
|
|
1190
|
-
/**
|
|
1191
|
-
* Strong references to the loggers.
|
|
1192
|
-
* This is to prevent the loggers from being garbage collected so that their
|
|
1193
|
-
* sinks and filters are not removed.
|
|
1194
|
-
*/
|
|
1195
|
-
const strongRefs = /* @__PURE__ */ new Set();
|
|
1196
|
-
/**
|
|
1197
|
-
* Disposables to dispose when resetting the configuration.
|
|
1198
|
-
*/
|
|
1199
|
-
const disposables = /* @__PURE__ */ new Set();
|
|
1200
|
-
/**
|
|
1201
|
-
* Async disposables to dispose when resetting the configuration.
|
|
1202
|
-
*/
|
|
1203
|
-
const asyncDisposables = /* @__PURE__ */ new Set();
|
|
1204
|
-
/**
|
|
1205
|
-
* Check if a config is for the meta logger.
|
|
1206
|
-
*/
|
|
1207
|
-
function isLoggerConfigMeta(cfg) {
|
|
1208
|
-
return cfg.category.length === 0 || cfg.category.length === 1 && cfg.category[0] === "logtape" || cfg.category.length === 2 && cfg.category[0] === "logtape" && cfg.category[1] === "meta";
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* Configure sync loggers with the specified configuration.
|
|
1212
|
-
*
|
|
1213
|
-
* Note that if the given sinks or filters are disposable, they will be
|
|
1214
|
-
* disposed when the configuration is reset, or when the process exits.
|
|
1215
|
-
*
|
|
1216
|
-
* Also note that passing async sinks or filters will throw. If
|
|
1217
|
-
* necessary use {@link resetSync} or {@link disposeSync}.
|
|
1218
|
-
*
|
|
1219
|
-
* @example
|
|
1220
|
-
* ```typescript
|
|
1221
|
-
* configureSync({
|
|
1222
|
-
* sinks: {
|
|
1223
|
-
* console: getConsoleSink(),
|
|
1224
|
-
* },
|
|
1225
|
-
* loggers: [
|
|
1226
|
-
* {
|
|
1227
|
-
* category: "my-app",
|
|
1228
|
-
* sinks: ["console"],
|
|
1229
|
-
* lowestLevel: "info",
|
|
1230
|
-
* },
|
|
1231
|
-
* {
|
|
1232
|
-
* category: "logtape",
|
|
1233
|
-
* sinks: ["console"],
|
|
1234
|
-
* lowestLevel: "error",
|
|
1235
|
-
* },
|
|
1236
|
-
* ],
|
|
1237
|
-
* });
|
|
1238
|
-
* ```
|
|
1239
|
-
*
|
|
1240
|
-
* @param config The configuration.
|
|
1241
|
-
* @since 0.9.0
|
|
1242
|
-
*/
|
|
1243
|
-
function configureSync(config) {
|
|
1244
|
-
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
1245
|
-
if (asyncDisposables.size > 0) throw new ConfigError("Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().");
|
|
1246
|
-
resetSync();
|
|
1247
|
-
try {
|
|
1248
|
-
configureInternal(config, false);
|
|
1249
|
-
} catch (e) {
|
|
1250
|
-
if (e instanceof ConfigError) resetSync();
|
|
1251
|
-
throw e;
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
function configureInternal(config, allowAsync) {
|
|
1255
|
-
currentConfig = config;
|
|
1256
|
-
let metaConfigured = false;
|
|
1257
|
-
const configuredCategories = /* @__PURE__ */ new Set();
|
|
1258
|
-
for (const cfg of config.loggers) {
|
|
1259
|
-
if (isLoggerConfigMeta(cfg)) metaConfigured = true;
|
|
1260
|
-
const categoryKey = Array.isArray(cfg.category) ? JSON.stringify(cfg.category) : JSON.stringify([cfg.category]);
|
|
1261
|
-
if (configuredCategories.has(categoryKey)) throw new ConfigError(`Duplicate logger configuration for category: ${categoryKey}. Each category can only be configured once.`);
|
|
1262
|
-
configuredCategories.add(categoryKey);
|
|
1263
|
-
const logger = LoggerImpl.getLogger(cfg.category);
|
|
1264
|
-
for (const sinkId of cfg.sinks ?? []) {
|
|
1265
|
-
const sink = config.sinks[sinkId];
|
|
1266
|
-
if (!sink) throw new ConfigError(`Sink not found: ${sinkId}.`);
|
|
1267
|
-
logger.sinks.push(sink);
|
|
1268
|
-
}
|
|
1269
|
-
logger.parentSinks = cfg.parentSinks ?? "inherit";
|
|
1270
|
-
if (cfg.lowestLevel !== void 0) logger.lowestLevel = cfg.lowestLevel;
|
|
1271
|
-
for (const filterId of cfg.filters ?? []) {
|
|
1272
|
-
const filter = config.filters?.[filterId];
|
|
1273
|
-
if (filter === void 0) throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
1274
|
-
logger.filters.push(toFilter(filter));
|
|
1275
|
-
}
|
|
1276
|
-
strongRefs.add(logger);
|
|
1277
|
-
}
|
|
1278
|
-
LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
1279
|
-
for (const sink of Object.values(config.sinks)) {
|
|
1280
|
-
if (Symbol.asyncDispose in sink) if (allowAsync) asyncDisposables.add(sink);
|
|
1281
|
-
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
1282
|
-
if (Symbol.dispose in sink) disposables.add(sink);
|
|
1283
|
-
}
|
|
1284
|
-
for (const filter of Object.values(config.filters ?? {})) {
|
|
1285
|
-
if (filter == null || typeof filter === "string") continue;
|
|
1286
|
-
if (Symbol.asyncDispose in filter) if (allowAsync) asyncDisposables.add(filter);
|
|
1287
|
-
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
1288
|
-
if (Symbol.dispose in filter) disposables.add(filter);
|
|
1289
|
-
}
|
|
1290
|
-
if (typeof globalThis.EdgeRuntime !== "string" && "process" in globalThis && !("Deno" in globalThis)) {
|
|
1291
|
-
const proc = globalThis.process;
|
|
1292
|
-
const onMethod = proc?.["on"];
|
|
1293
|
-
if (typeof onMethod === "function") onMethod.call(proc, "exit", allowAsync ? dispose : disposeSync);
|
|
1294
|
-
} else addEventListener("unload", allowAsync ? dispose : disposeSync);
|
|
1295
|
-
const meta = LoggerImpl.getLogger(["logtape", "meta"]);
|
|
1296
|
-
if (!metaConfigured) meta.sinks.push(getConsoleSink());
|
|
1297
|
-
meta.info("LogTape loggers are configured. Note that LogTape itself uses the meta logger, which has category {metaLoggerCategory}. The meta logger purposes to log internal errors such as sink exceptions. If you are seeing this message, the meta logger is automatically configured. It's recommended to configure the meta logger with a separate sink so that you can easily notice if logging itself fails or is misconfigured. To turn off this message, configure the meta logger with higher log levels than {dismissLevel}. See also <https://logtape.org/manual/categories#meta-logger>.", {
|
|
1298
|
-
metaLoggerCategory: ["logtape", "meta"],
|
|
1299
|
-
dismissLevel: "info"
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Reset the configuration. Mostly for testing purposes. Will not clear async
|
|
1304
|
-
* sinks, only use with sync sinks. Use {@link reset} if you have async sinks.
|
|
1305
|
-
* @since 0.9.0
|
|
1306
|
-
*/
|
|
1307
|
-
function resetSync() {
|
|
1308
|
-
disposeSync();
|
|
1309
|
-
resetInternal();
|
|
1310
|
-
}
|
|
1311
|
-
function resetInternal() {
|
|
1312
|
-
const rootLogger = LoggerImpl.getLogger([]);
|
|
1313
|
-
rootLogger.resetDescendants();
|
|
1314
|
-
delete rootLogger.contextLocalStorage;
|
|
1315
|
-
strongRefs.clear();
|
|
1316
|
-
currentConfig = null;
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* Dispose of the disposables.
|
|
1320
|
-
*/
|
|
1321
|
-
async function dispose() {
|
|
1322
|
-
disposeSync();
|
|
1323
|
-
const promises = [];
|
|
1324
|
-
for (const disposable of asyncDisposables) {
|
|
1325
|
-
promises.push(disposable[Symbol.asyncDispose]());
|
|
1326
|
-
asyncDisposables.delete(disposable);
|
|
1327
|
-
}
|
|
1328
|
-
await Promise.all(promises);
|
|
1329
|
-
}
|
|
1330
|
-
/**
|
|
1331
|
-
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
1332
|
-
* use {@link dispose} if you have async sinks.
|
|
1333
|
-
* @since 0.9.0
|
|
1334
|
-
*/
|
|
1335
|
-
function disposeSync() {
|
|
1336
|
-
for (const disposable of disposables) disposable[Symbol.dispose]();
|
|
1337
|
-
disposables.clear();
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* A configuration error.
|
|
1341
|
-
*/
|
|
1342
|
-
var ConfigError = class extends Error {
|
|
1343
|
-
/**
|
|
1344
|
-
* Constructs a new configuration error.
|
|
1345
|
-
* @param message The error message.
|
|
1346
|
-
*/
|
|
1347
|
-
constructor(message) {
|
|
1348
|
-
super(message);
|
|
1349
|
-
this.name = "ConfigureError";
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
|
|
1353
|
-
//#endregion
|
|
1354
|
-
export { getLogger as i, getConsoleSink as n, getAnsiColorFormatter as r, configureSync as t };
|
|
1
|
+
import{r as __exportAll}from"../../rolldown-runtime.mjs";import util from"node:util";function toFilter(e){return typeof e==`function`?e:getLevelFilter(e)}function getLevelFilter(e){if(e==null)return()=>!1;if(e===`fatal`)return e=>e.level===`fatal`;if(e===`error`)return e=>e.level===`fatal`||e.level===`error`;if(e===`warning`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`;if(e===`info`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`||e.level===`info`;if(e===`debug`)return e=>e.level===`fatal`||e.level===`error`||e.level===`warning`||e.level===`info`||e.level===`debug`;if(e===`trace`)return()=>!0;throw TypeError(`Invalid log level: ${e}.`)}const logLevels=[`trace`,`debug`,`info`,`warning`,`error`,`fatal`];function compareLogLevel(e,t){let n=logLevels.indexOf(e);if(n<0)throw TypeError(`Invalid log level: ${JSON.stringify(e)}.`);let r=logLevels.indexOf(t);if(r<0)throw TypeError(`Invalid log level: ${JSON.stringify(t)}.`);return n-r}function getLogger(e=[]){return LoggerImpl.getLogger(e)}const globalRootLoggerSymbol=Symbol.for(`logtape.rootLogger`);var LoggerImpl=class e{parent;children;category;sinks;parentSinks=`inherit`;filters;lowestLevel=`trace`;contextLocalStorage;static getLogger(t=[]){let n=globalRootLoggerSymbol in globalThis?globalThis[globalRootLoggerSymbol]??null:null;return n??(n=new e(null,[]),globalThis[globalRootLoggerSymbol]=n),typeof t==`string`?n.getChild(t):t.length===0?n:n.getChild(t)}constructor(e,t){this.parent=e,this.children={},this.category=t,this.sinks=[],this.filters=[]}getChild(t){let n=typeof t==`string`?t:t[0],r=this.children[n],i=r instanceof e?r:r?.deref();return i??(i=new e(this,[...this.category,n]),this.children[n]=`WeakRef`in globalThis?new WeakRef(i):i),typeof t==`string`||t.length===1?i:i.getChild(t.slice(1))}reset(){for(;this.sinks.length>0;)this.sinks.shift();for(this.parentSinks=`inherit`;this.filters.length>0;)this.filters.shift();this.lowestLevel=`trace`}resetDescendants(){for(let t of Object.values(this.children))(t instanceof e?t:t.deref())?.resetDescendants();this.reset()}with(e){return new LoggerCtx(this,{...e})}filter(e){for(let t of this.filters)if(!t(e))return!1;return this.filters.length<1?this.parent?.filter(e)??!0:!0}*getSinks(e){if(!(this.lowestLevel===null||compareLogLevel(e,this.lowestLevel)<0)){if(this.parent!=null&&this.parentSinks===`inherit`)for(let t of this.parent.getSinks(e))yield t;for(let e of this.sinks)yield e}}emit(e,t){let n=getCategoryPrefix(),r=`category`in e?e.category:this.category,i=n.length>0?[...n,...r]:r,o=Object.getOwnPropertyDescriptors(e);o.category={value:i,enumerable:!0,configurable:!0};let s=Object.defineProperties({},o);if(!(this.lowestLevel===null||compareLogLevel(s.level,this.lowestLevel)<0||!this.filter(s))){for(let e of this.getSinks(s.level))if(!t?.has(e))try{e(s)}catch(n){let r=new Set(t);r.add(e),metaLogger.log(`fatal`,`Failed to emit a log record to sink {sink}: {error}`,{sink:e,error:n,record:s},r)}}}log(e,t,n,r){let i=getImplicitContext(),a,o=typeof n==`function`?{category:this.category,level:e,timestamp:Date.now(),get message(){return parseMessageTemplate(t,this.properties)},rawMessage:t,get properties(){return a??={...i,...n()},a}}:{category:this.category,level:e,timestamp:Date.now(),message:parseMessageTemplate(t,{...i,...n}),rawMessage:t,properties:{...i,...n}};this.emit(o,r)}logLazily(e,t,n={}){let r=getImplicitContext(),i,a;function o(){if((a==null||i==null)&&(a=t((e,...t)=>(i=e,renderMessage(e,t))),i==null))throw TypeError(`No log record was made.`);return[a,i]}this.emit({category:this.category,level:e,get message(){return o()[0]},get rawMessage(){return o()[1]},timestamp:Date.now(),properties:{...r,...n}})}logTemplate(e,t,n,r={}){let i=getImplicitContext();this.emit({category:this.category,level:e,message:renderMessage(t,n),rawMessage:t,timestamp:Date.now(),properties:{...i,...r}})}trace(e,...t){typeof e==`string`?this.log(`trace`,e,t[0]??{}):typeof e==`function`?this.logLazily(`trace`,e):Array.isArray(e)?this.logTemplate(`trace`,e,t):this.log(`trace`,`{*}`,e)}debug(e,...t){typeof e==`string`?this.log(`debug`,e,t[0]??{}):typeof e==`function`?this.logLazily(`debug`,e):Array.isArray(e)?this.logTemplate(`debug`,e,t):this.log(`debug`,`{*}`,e)}info(e,...t){typeof e==`string`?this.log(`info`,e,t[0]??{}):typeof e==`function`?this.logLazily(`info`,e):Array.isArray(e)?this.logTemplate(`info`,e,t):this.log(`info`,`{*}`,e)}warn(e,...t){typeof e==`string`?this.log(`warning`,e,t[0]??{}):typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}warning(e,...t){this.warn(e,...t)}error(e,...t){typeof e==`string`?this.log(`error`,e,t[0]??{}):typeof e==`function`?this.logLazily(`error`,e):Array.isArray(e)?this.logTemplate(`error`,e,t):this.log(`error`,`{*}`,e)}fatal(e,...t){typeof e==`string`?this.log(`fatal`,e,t[0]??{}):typeof e==`function`?this.logLazily(`fatal`,e):Array.isArray(e)?this.logTemplate(`fatal`,e,t):this.log(`fatal`,`{*}`,e)}},LoggerCtx=class e{logger;properties;constructor(e,t){this.logger=e,this.properties=t}get category(){return this.logger.category}get parent(){return this.logger.parent}getChild(e){return this.logger.getChild(e).with(this.properties)}with(t){return new e(this.logger,{...this.properties,...t})}log(e,t,n,r){this.logger.log(e,t,typeof n==`function`?()=>({...this.properties,...n()}):{...this.properties,...n},r)}logLazily(e,t){this.logger.logLazily(e,t,this.properties)}logTemplate(e,t,n){this.logger.logTemplate(e,t,n,this.properties)}emit(e){let t={...e,properties:{...this.properties,...e.properties}};this.logger.emit(t)}trace(e,...t){typeof e==`string`?this.log(`trace`,e,t[0]??{}):typeof e==`function`?this.logLazily(`trace`,e):Array.isArray(e)?this.logTemplate(`trace`,e,t):this.log(`trace`,`{*}`,e)}debug(e,...t){typeof e==`string`?this.log(`debug`,e,t[0]??{}):typeof e==`function`?this.logLazily(`debug`,e):Array.isArray(e)?this.logTemplate(`debug`,e,t):this.log(`debug`,`{*}`,e)}info(e,...t){typeof e==`string`?this.log(`info`,e,t[0]??{}):typeof e==`function`?this.logLazily(`info`,e):Array.isArray(e)?this.logTemplate(`info`,e,t):this.log(`info`,`{*}`,e)}warn(e,...t){typeof e==`string`?this.log(`warning`,e,t[0]??{}):typeof e==`function`?this.logLazily(`warning`,e):Array.isArray(e)?this.logTemplate(`warning`,e,t):this.log(`warning`,`{*}`,e)}warning(e,...t){this.warn(e,...t)}error(e,...t){typeof e==`string`?this.log(`error`,e,t[0]??{}):typeof e==`function`?this.logLazily(`error`,e):Array.isArray(e)?this.logTemplate(`error`,e,t):this.log(`error`,`{*}`,e)}fatal(e,...t){typeof e==`string`?this.log(`fatal`,e,t[0]??{}):typeof e==`function`?this.logLazily(`fatal`,e):Array.isArray(e)?this.logTemplate(`fatal`,e,t):this.log(`fatal`,`{*}`,e)}};const metaLogger=LoggerImpl.getLogger([`logtape`,`meta`]);function isNestedAccess(e){return e.includes(`.`)||e.includes(`[`)||e.includes(`?.`)}function getOwnProperty(e,t){if(!(t===`__proto__`||t===`prototype`||t===`constructor`)&&(typeof e==`object`||typeof e==`function`)&&e!==null)return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function parseNextSegment(e,t){let n=e.length,r=t;if(r>=n)return null;let i;if(e[r]===`[`){if(r++,r>=n)return null;if(e[r]===`"`||e[r]===`'`){let t=e[r];r++;let a=``;for(;r<n&&e[r]!==t;)if(e[r]===`\\`){if(r++,r<n){let t=e[r];switch(t){case`n`:a+=`
|
|
2
|
+
`;break;case`t`:a+=` `;break;case`r`:a+=`\r`;break;case`b`:a+=`\b`;break;case`f`:a+=`\f`;break;case`v`:a+=`\v`;break;case`0`:a+=`\0`;break;case`\\`:a+=`\\`;break;case`"`:a+=`"`;break;case`'`:a+=`'`;break;case`u`:if(r+4<n){let n=e.slice(r+1,r+5),i=Number.parseInt(n,16);Number.isNaN(i)?a+=t:(a+=String.fromCharCode(i),r+=4)}else a+=t;break;default:a+=t}r++}}else a+=e[r],r++;if(r>=n)return null;i=a,r++}else{let t=r;for(;r<n&&e[r]!==`]`&&e[r]!==`'`&&e[r]!==`"`;)r++;if(r>=n)return null;let a=e.slice(t,r);if(a.length===0)return null;let o=Number(a);i=Number.isNaN(o)?a:o}for(;r<n&&e[r]!==`]`;)r++;r<n&&r++}else{let t=r;for(;r<n&&e[r]!==`.`&&e[r]!==`[`&&e[r]!==`?`&&e[r]!==`]`;)r++;if(i=e.slice(t,r),i.length===0)return null}return r<n&&e[r]===`.`&&r++,{segment:i,nextIndex:r}}function accessProperty(e,t){if(typeof t==`string`)return getOwnProperty(e,t);if(Array.isArray(e)&&t>=0&&t<e.length)return e[t]}function resolvePropertyPath(e,t){if(e==null||t.length===0||t.endsWith(`.`))return;let n=e,r=0,i=t.length;for(;r<i;){if(t.slice(r,r+2)===`?.`){if(r+=2,n==null)return}else if(n==null)return;let e=parseNextSegment(t,r);if(e===null)return;let{segment:i,nextIndex:a}=e;if(r=a,n=accessProperty(n,i),n===void 0)return}return n}function parseMessageTemplate(e,t){let n=e.length;if(n===0)return[``];if(!e.includes(`{`))return[e];let r=[],i=0;for(let a=0;a<n;a++){let o=e[a];if(o===`{`){if((a+1<n?e[a+1]:``)===`{`){a++;continue}let o=e.indexOf(`}`,a+1);if(o===-1)continue;let s=e.slice(i,a);r.push(s.replace(/{{/g,`{`).replace(/}}/g,`}`));let c=e.slice(a+1,o),l,u=c.trim();u===`*`?l=c in t?t[c]:`*`in t?t[`*`]:t:(l=c===u||c in t?t[c]:t[u],l===void 0&&isNestedAccess(u)&&(l=resolvePropertyPath(t,u))),r.push(l),a=o,i=a+1}else o===`}`&&a+1<n&&e[a+1]===`}`&&a++}let a=e.slice(i);return r.push(a.replace(/{{/g,`{`).replace(/}}/g,`}`)),r}function renderMessage(e,t){let n=[];for(let r=0;r<e.length;r++)n.push(e[r]),r<t.length&&n.push(t[r]);return n}const categoryPrefixSymbol=Symbol.for(`logtape.categoryPrefix`);function getCategoryPrefix(){let e=LoggerImpl.getLogger().contextLocalStorage?.getStore();if(e==null)return[];let t=e[categoryPrefixSymbol];return Array.isArray(t)?t:[]}function getImplicitContext(){let e=LoggerImpl.getLogger().contextLocalStorage?.getStore();if(e==null)return{};let t={};for(let n of Object.keys(e))t[n]=e[n];return t}var util_node_exports=__exportAll({inspect:()=>inspect$1});function inspect$1(e,n){return util.inspect(e,n)}const levelAbbreviations={trace:`TRC`,debug:`DBG`,info:`INF`,warning:`WRN`,error:`ERR`,fatal:`FTL`},inspect=typeof document<`u`||typeof navigator<`u`&&navigator.product===`ReactNative`?e=>JSON.stringify(e):`Deno`in globalThis&&`inspect`in globalThis.Deno&&typeof globalThis.Deno.inspect==`function`?(e,t)=>globalThis.Deno.inspect(e,{strAbbreviateSize:1/0,iterableLimit:1/0,...t}):util_node_exports!=null&&`inspect`in util_node_exports&&typeof inspect$1==`function`?(e,t)=>inspect$1(e,{maxArrayLength:1/0,maxStringLength:1/0,...t}):e=>JSON.stringify(e);function padZero(e){return e<10?`0${e}`:`${e}`}function padThree(e){return e<10?`00${e}`:e<100?`0${e}`:`${e}`}const timestampFormatters={"date-time-timezone":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00:00`},"date-time-tz":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00`},"date-time":e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())} ${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())}`},"time-timezone":e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00:00`},"time-tz":e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())} +00`},time:e=>{let t=new Date(e);return`${padZero(t.getUTCHours())}:${padZero(t.getUTCMinutes())}:${padZero(t.getUTCSeconds())}.${padThree(t.getUTCMilliseconds())}`},date:e=>{let t=new Date(e);return`${t.getUTCFullYear()}-${padZero(t.getUTCMonth()+1)}-${padZero(t.getUTCDate())}`},rfc3339:e=>new Date(e).toISOString(),none:()=>null},levelRenderersCache={ABBR:levelAbbreviations,abbr:{trace:`trc`,debug:`dbg`,info:`inf`,warning:`wrn`,error:`err`,fatal:`ftl`},FULL:{trace:`TRACE`,debug:`DEBUG`,info:`INFO`,warning:`WARNING`,error:`ERROR`,fatal:`FATAL`},full:{trace:`trace`,debug:`debug`,info:`info`,warning:`warning`,error:`error`,fatal:`fatal`},L:{trace:`T`,debug:`D`,info:`I`,warning:`W`,error:`E`,fatal:`F`},l:{trace:`t`,debug:`d`,info:`i`,warning:`w`,error:`e`,fatal:`f`}};function getTextFormatter(e={}){let t=(()=>{let t=e.timestamp;return t==null?timestampFormatters[`date-time-timezone`]:t===`disabled`?timestampFormatters.none:typeof t==`string`&&t in timestampFormatters?timestampFormatters[t]:t})(),n=e.category??`·`,r=e.value?t=>e.value(t,inspect):inspect,i=(()=>{let t=e.level;return t==null||t===`ABBR`?e=>levelRenderersCache.ABBR[e]:t===`abbr`?e=>levelRenderersCache.abbr[e]:t===`FULL`?e=>levelRenderersCache.FULL[e]:t===`full`?e=>levelRenderersCache.full[e]:t===`L`?e=>levelRenderersCache.L[e]:t===`l`?e=>levelRenderersCache.l[e]:t})(),a=e.format??(({timestamp:e,level:t,category:n,message:r})=>`${e?`${e} `:``}[${t}] ${n}: ${r}`);return e=>{let o=e.message,s=o.length,c;if(s===1)c=o[0];else if(s<=6){c=``;for(let e=0;e<s;e++)c+=e%2==0?o[e]:r(o[e])}else{let e=Array(s);for(let t=0;t<s;t++)e[t]=t%2==0?o[t]:r(o[t]);c=e.join(``)}return`${a({timestamp:t(e.timestamp),level:i(e.level),category:typeof n==`function`?n(e.category):e.category.join(n),message:c,record:e})}\n`}}getTextFormatter();const RESET=`\x1B[0m`,ansiColors={black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},ansiStyles={bold:`\x1B[1m`,dim:`\x1B[2m`,italic:`\x1B[3m`,underline:`\x1B[4m`,strikethrough:`\x1B[9m`},defaultLevelColors={trace:null,debug:`blue`,info:`green`,warning:`yellow`,error:`red`,fatal:`magenta`};function getAnsiColorFormatter(e={}){let t=e.format,n=e.timestampStyle===void 0?`dim`:e.timestampStyle,r=e.timestampColor??null,i=`${n==null?``:ansiStyles[n]}${r==null?``:ansiColors[r]}`,a=n==null&&r==null?``:RESET,o=e.levelStyle===void 0?`bold`:e.levelStyle,s=e.levelColors??defaultLevelColors,c=e.categoryStyle===void 0?`dim`:e.categoryStyle,l=e.categoryColor??null,u=`${c==null?``:ansiStyles[c]}${l==null?``:ansiColors[l]}`,d=c==null&&l==null?``:RESET;return getTextFormatter({timestamp:`date-time-tz`,value(e,t){return t(e,{colors:!0})},...e,format({timestamp:e,level:n,category:r,message:c,record:l}){let f=s[l.level];return e=`${i}${e}${a}`,n=`${o==null?``:ansiStyles[o]}${f==null?``:ansiColors[f]}${n}${o==null&&f==null?``:RESET}`,t==null?`${e} ${n} ${u}${r}:${d} ${c}`:t({timestamp:e,level:n,category:`${u}${r}${d}`,message:c,record:l})}})}getAnsiColorFormatter();function getJsonLinesFormatter(e={}){if(!e.categorySeparator&&!e.message&&!e.properties)return e=>{if(e.message.length===3)return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:e.message[0]+JSON.stringify(e.message[1])+e.message[2],logger:e.category.join(`.`),properties:e.properties})+`
|
|
3
|
+
`;if(e.message.length===1)return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:e.message[0],logger:e.category.join(`.`),properties:e.properties})+`
|
|
4
|
+
`;let t=e.message[0];for(let n=1;n<e.message.length;n++)t+=n&1?JSON.stringify(e.message[n]):e.message[n];return JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:t,logger:e.category.join(`.`),properties:e.properties})+`
|
|
5
|
+
`};let t=e.message===`template`,n=e.properties??`nest:properties`,r;if(typeof e.categorySeparator==`function`)r=e.categorySeparator;else{let t=e.categorySeparator??`.`;r=e=>e.join(t)}let i;if(n===`flatten`)i=e=>e;else if(n.startsWith(`prepend:`)){let e=n.substring(8);if(e===``)throw TypeError(`Invalid properties option: ${JSON.stringify(n)}. It must be of the form "prepend:<prefix>" where <prefix> is a non-empty string.`);i=t=>{let n={};for(let r in t)n[`${e}${r}`]=t[r];return n}}else if(n.startsWith(`nest:`)){let e=n.substring(5);i=t=>({[e]:t})}else throw TypeError(`Invalid properties option: ${JSON.stringify(n)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);let a;return a=t?e=>{if(typeof e.rawMessage==`string`)return e.rawMessage;let t=``;for(let n=0;n<e.rawMessage.length;n++)t+=n%2<1?e.rawMessage[n]:`{}`;return t}:e=>{let t=e.message.length;if(t===1)return e.message[0];let n=``;for(let r=0;r<t;r++)n+=r%2<1?e.message[r]:JSON.stringify(e.message[r]);return n},e=>JSON.stringify({"@timestamp":new Date(e.timestamp).toISOString(),level:e.level===`warning`?`WARN`:e.level.toUpperCase(),message:a(e),logger:r(e.category),...i(e.properties)})+`
|
|
6
|
+
`}getJsonLinesFormatter();const logLevelStyles={trace:`background-color: gray; color: white;`,debug:`background-color: gray; color: white;`,info:`background-color: white; color: black;`,warning:`background-color: orange; color: black;`,error:`background-color: red; color: white;`,fatal:`background-color: maroon; color: white;`};function defaultConsoleFormatter(e){let t=``,n=[];for(let r=0;r<e.message.length;r++)r%2==0?t+=e.message[r]:(t+=`%o`,n.push(e.message[r]));let r=new Date(e.timestamp);return[`%c${`${r.getUTCHours().toString().padStart(2,`0`)}:${r.getUTCMinutes().toString().padStart(2,`0`)}:${r.getUTCSeconds().toString().padStart(2,`0`)}.${r.getUTCMilliseconds().toString().padStart(3,`0`)}`} %c${levelAbbreviations[e.level]}%c %c${e.category.join(`·`)} %c${t}`,`color: gray;`,logLevelStyles[e.level],`background-color: default;`,`color: gray;`,`color: default;`,...n]}function getConsoleSink(e={}){let t=e.formatter??defaultConsoleFormatter,n={trace:`debug`,debug:`debug`,info:`info`,warning:`warn`,error:`error`,fatal:`error`,...e.levelMap??{}},r=e.console??globalThis.console,i=e=>{let i=t(e),a=n[e.level];if(a===void 0)throw TypeError(`Invalid log level: ${e.level}.`);if(typeof i==`string`){let e=i.replace(/\r?\n$/,``);r[a](e)}else r[a](...i)};if(!e.nonBlocking)return i;let a=e.nonBlocking===!0?{}:e.nonBlocking,o=a.bufferSize??100,s=a.flushInterval??100,c=[],l=null,u=!1,d=!1,f=o*2;function p(){if(c.length===0)return;let e=c.splice(0);for(let t of e)try{i(t)}catch{}}function m(){d||(d=!0,setTimeout(()=>{d=!1,p()},0))}function h(){l!==null||u||(l=setInterval(()=>{p()},s))}let g=e=>{u||(c.length>=f&&c.shift(),c.push(e),c.length>=o?m():l===null&&h())};return g[Symbol.dispose]=()=>{u=!0,l!==null&&(clearInterval(l),l=null),p()},g}let currentConfig=null;const strongRefs=new Set,disposables=new Set,asyncDisposables=new Set;function isLoggerConfigMeta(e){return e.category.length===0||e.category.length===1&&e.category[0]===`logtape`||e.category.length===2&&e.category[0]===`logtape`&&e.category[1]===`meta`}function configureSync(e){if(currentConfig!=null&&!e.reset)throw new ConfigError(`Already configured; if you want to reset, turn on the reset flag.`);if(asyncDisposables.size>0)throw new ConfigError(`Previously configured async disposables are still active. Use configure() instead or explicitly dispose them using dispose().`);resetSync();try{configureInternal(e,!1)}catch(e){throw e instanceof ConfigError&&resetSync(),e}}function configureInternal(e,t){currentConfig=e;let r=!1,i=new Set;for(let t of e.loggers){isLoggerConfigMeta(t)&&(r=!0);let a=Array.isArray(t.category)?JSON.stringify(t.category):JSON.stringify([t.category]);if(i.has(a))throw new ConfigError(`Duplicate logger configuration for category: ${a}. Each category can only be configured once.`);i.add(a);let o=LoggerImpl.getLogger(t.category);for(let n of t.sinks??[]){let t=e.sinks[n];if(!t)throw new ConfigError(`Sink not found: ${n}.`);o.sinks.push(t)}o.parentSinks=t.parentSinks??`inherit`,t.lowestLevel!==void 0&&(o.lowestLevel=t.lowestLevel);for(let r of t.filters??[]){let t=e.filters?.[r];if(t===void 0)throw new ConfigError(`Filter not found: ${r}.`);o.filters.push(toFilter(t))}strongRefs.add(o)}LoggerImpl.getLogger().contextLocalStorage=e.contextLocalStorage;for(let n of Object.values(e.sinks)){if(Symbol.asyncDispose in n)if(t)asyncDisposables.add(n);else throw new ConfigError(`Async disposables cannot be used with configureSync().`);Symbol.dispose in n&&disposables.add(n)}for(let n of Object.values(e.filters??{}))if(!(n==null||typeof n==`string`)){if(Symbol.asyncDispose in n)if(t)asyncDisposables.add(n);else throw new ConfigError(`Async disposables cannot be used with configureSync().`);Symbol.dispose in n&&disposables.add(n)}if(typeof globalThis.EdgeRuntime!=`string`&&`process`in globalThis&&!(`Deno`in globalThis)){let e=globalThis.process,n=e?.on;typeof n==`function`&&n.call(e,`exit`,t?dispose:disposeSync)}else addEventListener(`unload`,t?dispose:disposeSync);let a=LoggerImpl.getLogger([`logtape`,`meta`]);r||a.sinks.push(getConsoleSink()),a.info(`LogTape loggers are configured. Note that LogTape itself uses the meta logger, which has category {metaLoggerCategory}. The meta logger purposes to log internal errors such as sink exceptions. If you are seeing this message, the meta logger is automatically configured. It's recommended to configure the meta logger with a separate sink so that you can easily notice if logging itself fails or is misconfigured. To turn off this message, configure the meta logger with higher log levels than {dismissLevel}. See also <https://logtape.org/manual/categories#meta-logger>.`,{metaLoggerCategory:[`logtape`,`meta`],dismissLevel:`info`})}function resetSync(){disposeSync(),resetInternal()}function resetInternal(){let e=LoggerImpl.getLogger([]);e.resetDescendants(),delete e.contextLocalStorage,strongRefs.clear(),currentConfig=null}async function dispose(){disposeSync();let e=[];for(let t of asyncDisposables)e.push(t[Symbol.asyncDispose]()),asyncDisposables.delete(t);await Promise.all(e)}function disposeSync(){for(let e of disposables)e[Symbol.dispose]();disposables.clear()}var ConfigError=class extends Error{constructor(e){super(e),this.name=`ConfigureError`}};export{getLogger as i,getConsoleSink as n,getAnsiColorFormatter as r,configureSync as t};
|