halua 1.0.0 → 2.0.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/lib/index.cjs +475 -489
- package/lib/index.d.cts +91 -80
- package/lib/index.d.ts +91 -80
- package/lib/index.js +474 -488
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/types/log.ts
|
|
2
2
|
var Level = /* @__PURE__ */ ((Level2) => {
|
|
3
3
|
Level2["Trace"] = "TRACE";
|
|
4
4
|
Level2["Debug"] = "DEBUG";
|
|
@@ -10,82 +10,51 @@ var Level = /* @__PURE__ */ ((Level2) => {
|
|
|
10
10
|
return Level2;
|
|
11
11
|
})(Level || {});
|
|
12
12
|
|
|
13
|
-
// src/
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
debug: "DEBUG" /* Debug */,
|
|
18
|
-
info: "INFO" /* Info */,
|
|
19
|
-
warn: "WARN" /* Warn */,
|
|
20
|
-
notice: "NOTICE" /* Notice */,
|
|
21
|
-
error: "ERROR" /* Error */,
|
|
22
|
-
fatal: "FATAL" /* Fatal */,
|
|
23
|
-
assert: "ERROR" /* Error */
|
|
24
|
-
}[v];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/util/string.ts
|
|
28
|
-
var defaultIgnored = /* @__PURE__ */ new Set();
|
|
29
|
-
function stringMatchesVar(str, ignoredStrings = defaultIgnored) {
|
|
30
|
-
return !ignoredStrings.has(str) && str.trim().indexOf(" ") === -1;
|
|
31
|
-
}
|
|
32
|
-
var messageFormatExcludes = /* @__PURE__ */ new Set([" ", "%a", "%w", "%t", "%l"]);
|
|
33
|
-
function extractNonFormatChars(f) {
|
|
34
|
-
let total = /* @__PURE__ */ new Set();
|
|
35
|
-
for (let char of f) {
|
|
36
|
-
if (!messageFormatExcludes.has(char)) {
|
|
37
|
-
total.add(char);
|
|
38
|
-
}
|
|
13
|
+
// src/main/getType.ts
|
|
14
|
+
function getType(arg) {
|
|
15
|
+
if (typeof arg === "undefined") {
|
|
16
|
+
return "undefined";
|
|
39
17
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function extractTaken(f) {
|
|
43
|
-
let total = [];
|
|
44
|
-
let seq = "";
|
|
45
|
-
for (let rune of f) {
|
|
46
|
-
if (seq && (rune === "%" || rune === " ")) {
|
|
47
|
-
total.push(seq);
|
|
48
|
-
seq = "";
|
|
49
|
-
if (rune === "%") {
|
|
50
|
-
seq += rune;
|
|
51
|
-
}
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
seq += rune;
|
|
18
|
+
if (typeof arg === "object" && String(arg) === "null") {
|
|
19
|
+
return "null";
|
|
55
20
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
21
|
+
if (Array.isArray(arg)) {
|
|
22
|
+
return "array";
|
|
58
23
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function removeTailingUndefinedValues(format, log) {
|
|
62
|
-
if (!argsInDisposition(format) || log.withArgs) {
|
|
63
|
-
return format;
|
|
24
|
+
if (ArrayBuffer.isView(arg)) {
|
|
25
|
+
return "typedarray";
|
|
64
26
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (withArgsIndex < argsIndex) {
|
|
68
|
-
return format;
|
|
27
|
+
if (arg instanceof ArrayBuffer) {
|
|
28
|
+
return "arraybuffer";
|
|
69
29
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
30
|
+
if (arg instanceof Map) {
|
|
31
|
+
return "map";
|
|
32
|
+
}
|
|
33
|
+
if (arg instanceof Set) {
|
|
34
|
+
return "set";
|
|
35
|
+
}
|
|
36
|
+
if (arg instanceof WeakMap) {
|
|
37
|
+
return "weakmap";
|
|
38
|
+
}
|
|
39
|
+
if (arg instanceof WeakSet) {
|
|
40
|
+
return "weakset";
|
|
41
|
+
}
|
|
42
|
+
if (arg instanceof Date) {
|
|
43
|
+
return "date";
|
|
83
44
|
}
|
|
84
|
-
if (
|
|
85
|
-
return
|
|
45
|
+
if (arg instanceof Error) {
|
|
46
|
+
return "error";
|
|
86
47
|
}
|
|
87
|
-
|
|
48
|
+
if (Number.isNaN(arg)) {
|
|
49
|
+
return "nan";
|
|
50
|
+
}
|
|
51
|
+
if (typeof arg === "number" && !Number.isFinite(arg)) {
|
|
52
|
+
return "infinity";
|
|
53
|
+
}
|
|
54
|
+
return typeof arg;
|
|
88
55
|
}
|
|
56
|
+
|
|
57
|
+
// src/main/util/string.ts
|
|
89
58
|
function extractLevels(level) {
|
|
90
59
|
if (typeof level !== "string") {
|
|
91
60
|
return ["INFO" /* Info */, 0];
|
|
@@ -102,11 +71,33 @@ function extractLevels(level) {
|
|
|
102
71
|
return [data[0], Math.trunc(data[1]) || 0];
|
|
103
72
|
}
|
|
104
73
|
|
|
105
|
-
// src/errors.ts
|
|
106
|
-
var
|
|
74
|
+
// src/main/errors.ts
|
|
75
|
+
var HaluaFailedToCallHandler = class extends Error {
|
|
76
|
+
constructor(message, options = {}) {
|
|
77
|
+
super(`HaluaFailedToCallHandlerError: ${message}`, options);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var HaluaUnableToDetermineHandler = class extends Error {
|
|
81
|
+
constructor(message, options = {}) {
|
|
82
|
+
super(`HaluaUnableToDetermineHandlerError: ${message}`, options);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var HaluaParse = class extends Error {
|
|
86
|
+
constructor(message, options = {}) {
|
|
87
|
+
super(`HaluaParseError: ${message}`, options);
|
|
88
|
+
}
|
|
107
89
|
};
|
|
108
90
|
|
|
109
|
-
// src/
|
|
91
|
+
// src/main/util/errors.ts
|
|
92
|
+
function tryReportAnError(err) {
|
|
93
|
+
try {
|
|
94
|
+
let log = "self" in window ? self.console : console;
|
|
95
|
+
log.error(err);
|
|
96
|
+
} catch (_) {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/main/handlers/Balancer.ts
|
|
110
101
|
var MajorLevelMap = /* @__PURE__ */ new Map([
|
|
111
102
|
["FATAL" /* Fatal */, /* @__PURE__ */ new Set(["FATAL" /* Fatal */])],
|
|
112
103
|
["ERROR" /* Error */, /* @__PURE__ */ new Set(["FATAL" /* Fatal */, "ERROR" /* Error */])],
|
|
@@ -117,14 +108,17 @@ var MajorLevelMap = /* @__PURE__ */ new Map([
|
|
|
117
108
|
["TRACE" /* Trace */, /* @__PURE__ */ new Set(["FATAL" /* Fatal */, "ERROR" /* Error */, "WARN" /* Warn */, "NOTICE" /* Notice */, "INFO" /* Info */, "DEBUG" /* Debug */, "TRACE" /* Trace */])]
|
|
118
109
|
]);
|
|
119
110
|
var HandlersBalancer = class {
|
|
120
|
-
constructor(level, handlers) {
|
|
111
|
+
constructor(level, handlers, format2) {
|
|
121
112
|
this.level = level;
|
|
122
113
|
this.handlers = handlers;
|
|
114
|
+
this.format = format2;
|
|
115
|
+
this.sendLog = this.sendLog.bind(this);
|
|
116
|
+
this.reset = this.reset.bind(this);
|
|
123
117
|
}
|
|
124
118
|
map = /* @__PURE__ */ new Map();
|
|
125
|
-
sendLog(
|
|
126
|
-
this.discover(
|
|
127
|
-
this.send(
|
|
119
|
+
sendLog(meta, args) {
|
|
120
|
+
this.discover(meta.level);
|
|
121
|
+
this.send(meta, args);
|
|
128
122
|
}
|
|
129
123
|
reset() {
|
|
130
124
|
this.map.clear();
|
|
@@ -142,23 +136,44 @@ var HandlersBalancer = class {
|
|
|
142
136
|
}
|
|
143
137
|
continue;
|
|
144
138
|
}
|
|
145
|
-
if (this.canSend(
|
|
139
|
+
if (this.canSend(level, h.level ?? this.level)) {
|
|
146
140
|
discovered.push(h);
|
|
147
141
|
}
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
|
-
send(
|
|
144
|
+
send(meta, args) {
|
|
151
145
|
try {
|
|
152
|
-
|
|
153
|
-
h.skipDeepCopyWhenSendingLog ? h.log(log) : h.log(structuredClone(log));
|
|
154
|
-
}
|
|
146
|
+
this.sendToHandlers(meta, args);
|
|
155
147
|
} catch (e) {
|
|
156
|
-
|
|
148
|
+
tryReportAnError(new HaluaFailedToCallHandler(`Unable to call execution method of a handler`, { cause: e }));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
sendToHandlers(meta, args) {
|
|
152
|
+
let generators = (this.map.get(meta.level) ?? []).map((h) => h.execute(meta));
|
|
153
|
+
generators.forEach((e) => e.next({ type: "init", value: null }));
|
|
154
|
+
let state = Array.from({ length: generators.length }).fill(void 0);
|
|
155
|
+
for (let arg of args) {
|
|
156
|
+
generators.forEach((e, i) => {
|
|
157
|
+
try {
|
|
158
|
+
let result = e.next({ type: "arg", value: arg, prev: state[i] });
|
|
159
|
+
state[i] = void 0;
|
|
160
|
+
if (result.value?.type === "pass") {
|
|
161
|
+
state[i] = this.format({ type: getType(arg), value: arg });
|
|
162
|
+
}
|
|
163
|
+
} catch (e2) {
|
|
164
|
+
tryReportAnError(new HaluaParse(`Failed to parse an argument`, { cause: e2 }));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
157
167
|
}
|
|
168
|
+
generators.forEach((e, i) => {
|
|
169
|
+
e.next({ type: "done", value: null, prev: state[i] });
|
|
170
|
+
});
|
|
171
|
+
state = [];
|
|
158
172
|
}
|
|
159
173
|
canSend(l, to = this.level || "TRACE" /* Trace */) {
|
|
160
|
-
let
|
|
161
|
-
|
|
174
|
+
let lvl = extractLevels(l);
|
|
175
|
+
let toLvl = extractLevels(to);
|
|
176
|
+
return this.majorLevelCheck(lvl[0], toLvl[0]) + this.minorLevelCheck(lvl[1], toLvl[1]) > 0;
|
|
162
177
|
}
|
|
163
178
|
majorLevelCheck(l, to) {
|
|
164
179
|
if (!MajorLevelMap.get(to).has(l)) {
|
|
@@ -171,506 +186,477 @@ var HandlersBalancer = class {
|
|
|
171
186
|
}
|
|
172
187
|
};
|
|
173
188
|
|
|
174
|
-
// src/
|
|
189
|
+
// src/util/spacing.ts
|
|
190
|
+
var Spacing = /* @__PURE__ */ ((Spacing2) => {
|
|
191
|
+
Spacing2["Space"] = " ";
|
|
192
|
+
Spacing2["Tab"] = " ";
|
|
193
|
+
Spacing2["Empty"] = "";
|
|
194
|
+
Spacing2["Line"] = "\n";
|
|
195
|
+
return Spacing2;
|
|
196
|
+
})(Spacing || {});
|
|
197
|
+
var EmptySpacing = /* @__PURE__ */ ((EmptySpacing2) => {
|
|
198
|
+
EmptySpacing2["Space"] = " ";
|
|
199
|
+
EmptySpacing2["Tab"] = "";
|
|
200
|
+
EmptySpacing2["Empty"] = "";
|
|
201
|
+
EmptySpacing2["Line"] = "";
|
|
202
|
+
return EmptySpacing2;
|
|
203
|
+
})(EmptySpacing || {});
|
|
204
|
+
|
|
205
|
+
// src/util/string.ts
|
|
206
|
+
function printTimes(n, value) {
|
|
207
|
+
let str = "";
|
|
208
|
+
for (let i = n; i !== 0; i -= 1) {
|
|
209
|
+
str += value;
|
|
210
|
+
}
|
|
211
|
+
return str;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/main/format.ts
|
|
215
|
+
var FormatAsIs = [
|
|
216
|
+
"undefined",
|
|
217
|
+
"null",
|
|
218
|
+
"string",
|
|
219
|
+
"number",
|
|
220
|
+
"boolean",
|
|
221
|
+
"symbol",
|
|
222
|
+
"typedarray",
|
|
223
|
+
"bigint",
|
|
224
|
+
"date",
|
|
225
|
+
"nan",
|
|
226
|
+
"infinity"
|
|
227
|
+
];
|
|
228
|
+
var FormatNeeded = [
|
|
229
|
+
"array",
|
|
230
|
+
"object",
|
|
231
|
+
"arraybuffer",
|
|
232
|
+
"map",
|
|
233
|
+
"set",
|
|
234
|
+
"weakmap",
|
|
235
|
+
"weakset",
|
|
236
|
+
"function",
|
|
237
|
+
"error"
|
|
238
|
+
];
|
|
239
|
+
function format(arg, spacing = true) {
|
|
240
|
+
try {
|
|
241
|
+
const SpacingEnum = spacing ? Spacing : EmptySpacing;
|
|
242
|
+
if (FormatAsIs.some((f) => f === arg.type)) {
|
|
243
|
+
return formatAsIs(arg.value, arg.type);
|
|
244
|
+
}
|
|
245
|
+
if (FormatNeeded.some((f) => f === arg.type)) {
|
|
246
|
+
return formatComplex(arg.value, arg.type, SpacingEnum);
|
|
247
|
+
}
|
|
248
|
+
} catch (err) {
|
|
249
|
+
return new HaluaParse(err?.message || "").message;
|
|
250
|
+
}
|
|
251
|
+
return arg.value;
|
|
252
|
+
}
|
|
253
|
+
function formatJSON(arg) {
|
|
254
|
+
if (arg.type === "error") {
|
|
255
|
+
return `${arg.value.toString()} stack: ${arg.value.stack?.replace("\n", "")}`;
|
|
256
|
+
}
|
|
257
|
+
return format(arg, false);
|
|
258
|
+
}
|
|
259
|
+
function formatAsIs(arg, type) {
|
|
260
|
+
if (type === "number") {
|
|
261
|
+
return arg;
|
|
262
|
+
}
|
|
263
|
+
if (type === "boolean") {
|
|
264
|
+
return arg;
|
|
265
|
+
}
|
|
266
|
+
return String(arg);
|
|
267
|
+
}
|
|
268
|
+
function formatComplex(arg, type, spacing, nestingLevel = 1) {
|
|
269
|
+
if (type === "set") {
|
|
270
|
+
return `Set${formatArray(convertSetToArray(arg), spacing)}`;
|
|
271
|
+
}
|
|
272
|
+
if (type === "weakset") {
|
|
273
|
+
return `WeakSet [inaccessible]`;
|
|
274
|
+
}
|
|
275
|
+
if (type === "weakmap") {
|
|
276
|
+
return `WeakMap {inaccessible}`;
|
|
277
|
+
}
|
|
278
|
+
if (type === "function") {
|
|
279
|
+
let name = arg.name;
|
|
280
|
+
return `Function ${name === "value" ? "anonymous" : name}`;
|
|
281
|
+
}
|
|
282
|
+
if (type === "array") {
|
|
283
|
+
return formatArray(arg, spacing);
|
|
284
|
+
}
|
|
285
|
+
if (type === "arraybuffer") {
|
|
286
|
+
return `ArrayBuffer []`;
|
|
287
|
+
}
|
|
288
|
+
if (type === "map") {
|
|
289
|
+
return formatObject(convertMapToObj(arg), spacing, nestingLevel, ` => `);
|
|
290
|
+
}
|
|
291
|
+
if (type === "error") {
|
|
292
|
+
return `${arg.toString()} stack: ${arg.stack}`;
|
|
293
|
+
}
|
|
294
|
+
if (type === "object") {
|
|
295
|
+
return formatObject(arg, spacing, nestingLevel);
|
|
296
|
+
}
|
|
297
|
+
return arg;
|
|
298
|
+
}
|
|
299
|
+
function formatArray(arg, spacing) {
|
|
300
|
+
let stringify = "[";
|
|
301
|
+
let len = arg.length;
|
|
302
|
+
for (let entry of arg) {
|
|
303
|
+
len -= 1;
|
|
304
|
+
let entryType = getType(entry);
|
|
305
|
+
let formatted = format({ type: entryType, value: entry });
|
|
306
|
+
let entryValue = entryType === "string" ? `"${formatted}"` : formatted;
|
|
307
|
+
stringify += `${entryValue}${len ? `,${spacing.Space}` : spacing.Empty}`;
|
|
308
|
+
}
|
|
309
|
+
stringify += "]";
|
|
310
|
+
return stringify;
|
|
311
|
+
}
|
|
312
|
+
function formatObject(arg, spacing, nestingLevel = 1, delimiter = `: `) {
|
|
313
|
+
let stringify = `{${spacing.Line}`;
|
|
314
|
+
let len = Object.keys(arg).length;
|
|
315
|
+
for (let key in arg) {
|
|
316
|
+
len -= 1;
|
|
317
|
+
let entryType = getType(arg[key]);
|
|
318
|
+
let formatted = entryType === "object" ? formatComplex(arg[key], entryType, spacing, nestingLevel + 1) : format({
|
|
319
|
+
type: entryType,
|
|
320
|
+
value: arg[key]
|
|
321
|
+
});
|
|
322
|
+
let entryValue = entryType === "string" ? `"${formatted}"` : formatted;
|
|
323
|
+
stringify += `${printTimes(nestingLevel, spacing.Tab)}"${key}"${delimiter}${entryValue}${len ? `,${spacing.Line}` : spacing.Empty}`;
|
|
324
|
+
}
|
|
325
|
+
let level = nestingLevel - 1;
|
|
326
|
+
stringify += `${spacing.Line}${printTimes(level, spacing.Tab)}}`;
|
|
327
|
+
return stringify;
|
|
328
|
+
}
|
|
329
|
+
function convertMapToObj(value) {
|
|
330
|
+
let obj = {};
|
|
331
|
+
for (let [key, v] of value) {
|
|
332
|
+
let keyType = getType(key);
|
|
333
|
+
let objKey = keyType === "string" ? key : format({ type: keyType, value: key });
|
|
334
|
+
let valueType = getType(v);
|
|
335
|
+
obj[objKey] = format({ type: valueType, value: v });
|
|
336
|
+
}
|
|
337
|
+
return obj;
|
|
338
|
+
}
|
|
339
|
+
function convertSetToArray(value) {
|
|
340
|
+
let arr = [];
|
|
341
|
+
for (let entry of value) {
|
|
342
|
+
arr.push(entry);
|
|
343
|
+
}
|
|
344
|
+
return arr;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/main/util/cast.ts
|
|
348
|
+
function toarray(value) {
|
|
349
|
+
return Array.isArray(value) ? value : typeof value === "undefined" ? [] : [value];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/main/halua.ts
|
|
175
353
|
var Halua = class _Halua {
|
|
176
354
|
constructor(passed, options = {}) {
|
|
177
355
|
this.options = options;
|
|
178
356
|
this.passedHandlers = passed;
|
|
179
|
-
this.options.messageFormat ??= "%t %l %a | %w";
|
|
180
|
-
this.validateHandlers(this.buildHandlers(passed));
|
|
181
357
|
this.handlers = this.buildHandlers(passed);
|
|
182
|
-
this.balancer = new HandlersBalancer(this.options.level || "TRACE" /* Trace */, this.handlers);
|
|
358
|
+
this.balancer = new HandlersBalancer(this.options.level || "TRACE" /* Trace */, this.handlers, format);
|
|
359
|
+
this.bindMethods();
|
|
183
360
|
}
|
|
361
|
+
passedHandlers = [];
|
|
184
362
|
handlers = [];
|
|
185
|
-
passedHandlers;
|
|
186
363
|
balancer;
|
|
187
364
|
New(arg1 = this.passedHandlers, arg2 = this.options) {
|
|
188
365
|
if (Array.isArray(arg1)) {
|
|
189
|
-
this.validateHandlers(this.buildHandlers(arg1));
|
|
190
366
|
return new _Halua(arg1, { ...arg2 });
|
|
191
367
|
}
|
|
192
|
-
if (this.supposeIsHandler(arg1)) {
|
|
368
|
+
if (this.supposeIsHandler(arg1, false)) {
|
|
193
369
|
return new _Halua(arg1, { ...arg2 });
|
|
194
370
|
}
|
|
195
371
|
if (Object.keys(arg1).length) {
|
|
196
372
|
return new _Halua(this.passedHandlers, { ...arg1 });
|
|
197
373
|
}
|
|
198
|
-
this.validateHandlers(this.buildHandlers(arg1));
|
|
199
374
|
return new _Halua(arg1, { ...arg2 });
|
|
200
375
|
}
|
|
201
376
|
With(...args) {
|
|
202
377
|
return new _Halua(this.passedHandlers, { ...this.options, withArgs: (this.options.withArgs || []).concat(args) });
|
|
203
378
|
}
|
|
204
|
-
|
|
205
|
-
this.unlinkInheritance();
|
|
206
|
-
this.options.messageFormat = f;
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
setHandler(handler) {
|
|
210
|
-
this.validateHandlers(this.buildHandlers(handler));
|
|
379
|
+
setHandlers(handler) {
|
|
211
380
|
this.handlers = this.buildHandlers(handler);
|
|
212
381
|
this.updateBalancer();
|
|
213
382
|
}
|
|
214
|
-
|
|
215
|
-
this.
|
|
216
|
-
this.handlers.push(...
|
|
383
|
+
appendHandlers(handler) {
|
|
384
|
+
let handlers = this.buildHandlers(handler);
|
|
385
|
+
this.handlers.push(...handlers);
|
|
217
386
|
this.updateBalancer();
|
|
218
387
|
}
|
|
219
388
|
logTo(level, ...args) {
|
|
220
|
-
this.
|
|
389
|
+
this.sendToBalancer(level, args);
|
|
221
390
|
}
|
|
222
391
|
trace(...args) {
|
|
223
|
-
this.
|
|
392
|
+
this.sendToBalancer("TRACE" /* Trace */, args);
|
|
224
393
|
}
|
|
225
394
|
debug(...args) {
|
|
226
|
-
this.
|
|
395
|
+
this.sendToBalancer("DEBUG" /* Debug */, args);
|
|
227
396
|
}
|
|
228
397
|
info(...args) {
|
|
229
|
-
this.
|
|
398
|
+
this.sendToBalancer("INFO" /* Info */, args);
|
|
230
399
|
}
|
|
231
400
|
warn(...args) {
|
|
232
|
-
this.
|
|
401
|
+
this.sendToBalancer("WARN" /* Warn */, args);
|
|
233
402
|
}
|
|
234
403
|
notice(...args) {
|
|
235
|
-
this.
|
|
404
|
+
this.sendToBalancer("NOTICE" /* Notice */, args);
|
|
236
405
|
}
|
|
237
406
|
error(...args) {
|
|
238
|
-
this.
|
|
407
|
+
this.sendToBalancer("ERROR" /* Error */, args);
|
|
239
408
|
}
|
|
240
409
|
fatal(...args) {
|
|
241
|
-
this.
|
|
410
|
+
this.sendToBalancer("FATAL" /* Fatal */, args);
|
|
242
411
|
}
|
|
243
412
|
assert(assertion, ...args) {
|
|
244
413
|
if (assertion) {
|
|
245
414
|
return;
|
|
246
415
|
}
|
|
247
|
-
this.
|
|
416
|
+
this.sendToBalancer("ERROR" /* Error */, args);
|
|
248
417
|
}
|
|
249
418
|
updateBalancer() {
|
|
250
|
-
this.balancer = new HandlersBalancer(this.options.level || "TRACE" /* Trace */, this.handlers);
|
|
251
|
-
}
|
|
252
|
-
sendToHandler(field, assertion = true, ...args) {
|
|
253
|
-
this.balancer.sendLog(this.composeLog(toLevel(field), assertion, ...args));
|
|
254
|
-
}
|
|
255
|
-
composeLog(level, assertion, ...args) {
|
|
256
|
-
return {
|
|
257
|
-
timestamp: Date.now(),
|
|
258
|
-
args: args || [],
|
|
259
|
-
withArgs: this.options?.withArgs || null,
|
|
260
|
-
messageFormat: this.options.messageFormat,
|
|
261
|
-
assertion,
|
|
262
|
-
level,
|
|
263
|
-
leveling: extractLevels(level)
|
|
264
|
-
};
|
|
419
|
+
this.balancer = new HandlersBalancer(this.options.level || "TRACE" /* Trace */, this.handlers, format);
|
|
265
420
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (this.options.errorPolicy === "throw") {
|
|
269
|
-
for (let h of handlers) {
|
|
270
|
-
if (!this.supposeIsHandler(h)) {
|
|
271
|
-
throw new Error("Passed handlers does not satisfy Handler interface");
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
supposeIsHandler(v) {
|
|
277
|
-
return Object.prototype.hasOwnProperty.call(v.__proto__, "log") || Object.prototype.hasOwnProperty.call(v, "log");
|
|
421
|
+
sendToBalancer(level, args) {
|
|
422
|
+
this.balancer.sendLog({ level, timestamp: Date.now() }, args.concat(this.options.withArgs ?? []));
|
|
278
423
|
}
|
|
279
|
-
|
|
280
|
-
|
|
424
|
+
supposeIsHandler(v, reportError = true) {
|
|
425
|
+
const isHandler = Object.prototype.hasOwnProperty.call(v.__proto__, "execute") || Object.prototype.hasOwnProperty.call(v, "execute");
|
|
426
|
+
if (!isHandler && reportError) {
|
|
427
|
+
tryReportAnError(new HaluaUnableToDetermineHandler(`Unable to find execute method of a handler`));
|
|
428
|
+
}
|
|
429
|
+
return isHandler;
|
|
281
430
|
}
|
|
282
431
|
buildHandlers(passed) {
|
|
283
|
-
let entries =
|
|
284
|
-
return entries.map((
|
|
432
|
+
let entries = toarray(passed);
|
|
433
|
+
return entries.map((b) => b()).filter((h) => this.supposeIsHandler(h));
|
|
434
|
+
}
|
|
435
|
+
bindMethods() {
|
|
436
|
+
this.New = this.New.bind(this);
|
|
437
|
+
this.With = this.With.bind(this);
|
|
438
|
+
this.setHandlers = this.setHandlers.bind(this);
|
|
439
|
+
this.appendHandlers = this.appendHandlers.bind(this);
|
|
440
|
+
this.logTo = this.logTo.bind(this);
|
|
441
|
+
this.trace = this.trace.bind(this);
|
|
442
|
+
this.debug = this.debug.bind(this);
|
|
443
|
+
this.info = this.info.bind(this);
|
|
444
|
+
this.warn = this.warn.bind(this);
|
|
445
|
+
this.notice = this.notice.bind(this);
|
|
446
|
+
this.error = this.error.bind(this);
|
|
447
|
+
this.fatal = this.fatal.bind(this);
|
|
448
|
+
this.assert = this.assert.bind(this);
|
|
449
|
+
this.supposeIsHandler = this.supposeIsHandler.bind(this);
|
|
285
450
|
}
|
|
286
451
|
};
|
|
287
452
|
|
|
288
|
-
// src/handlers/
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
function NewWebConsoleHandler(c = console, options = {}) {
|
|
314
|
-
return () => new class WebConsoleLog {
|
|
315
|
-
constructor(options2) {
|
|
316
|
-
this.options = options2;
|
|
317
|
-
this.level = options2.level;
|
|
318
|
-
this.exact = options2.exact ? arrayed(options2.exact) : void 0;
|
|
319
|
-
this.options = options2 || {};
|
|
320
|
-
this.options.fetchBrowserThemeOnInstanceCreation ??= true;
|
|
321
|
-
this.messageFormatRaw = options2.messageFormat ?? this.messageFormatRaw;
|
|
322
|
-
this.messageFormat = Array.from(extractTaken(this.messageFormatRaw));
|
|
323
|
-
if (!this.options.pretty) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
if (this.options.fetchBrowserThemeOnInstanceCreation) {
|
|
327
|
-
if (window?.matchMedia && window?.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
328
|
-
this.colors = new Map(this.darkColors);
|
|
329
|
-
} else {
|
|
330
|
-
this.colors = new Map(this.lightColors);
|
|
331
|
-
}
|
|
332
|
-
delete this.options.fetchBrowserThemeOnInstanceCreation;
|
|
333
|
-
} else {
|
|
334
|
-
this.colors = new Map(this.lightColors);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
skipDeepCopyWhenSendingLog = false;
|
|
338
|
-
messageFormat = [];
|
|
339
|
-
level;
|
|
340
|
-
exact;
|
|
341
|
-
messageFormatRaw = "%t %l %a | %w";
|
|
342
|
-
colors = /* @__PURE__ */ new Map([]);
|
|
343
|
-
// bg chrome #fefbff
|
|
344
|
-
lightColors = /* @__PURE__ */ new Map([
|
|
345
|
-
["grey", "#565656"],
|
|
346
|
-
["green", "#224912"],
|
|
347
|
-
["blue", "#195367"],
|
|
348
|
-
["purple", "#8A228A"],
|
|
349
|
-
["orange", "#7F3E1E"],
|
|
350
|
-
["red", "#A51818"]
|
|
351
|
-
]);
|
|
352
|
-
// bg chrome #27242a
|
|
353
|
-
darkColors = /* @__PURE__ */ new Map([
|
|
354
|
-
["grey", "#C9C9C9"],
|
|
355
|
-
["green", "#73CE73"],
|
|
356
|
-
["blue", "#93B9E7"],
|
|
357
|
-
["purple", "#DCA4E9"],
|
|
358
|
-
["orange", "#EEC5A8"],
|
|
359
|
-
["red", "#FC9292"]
|
|
360
|
-
]);
|
|
361
|
-
get linkArguments() {
|
|
362
|
-
return this.options.linkArguments !== void 0 && !this.options.linkArguments;
|
|
363
|
-
}
|
|
364
|
-
log(log) {
|
|
365
|
-
this.sendLog(log);
|
|
366
|
-
}
|
|
367
|
-
setDateGetter(dateGetter) {
|
|
368
|
-
this.options.dateGetter = dateGetter;
|
|
369
|
-
}
|
|
370
|
-
sendLog(log) {
|
|
371
|
-
let args = this.insertInternalEntries(log);
|
|
372
|
-
if (log.level === "DEBUG" /* Debug */) {
|
|
373
|
-
c.debug(this.composeConsoleSubstitution(args), ...args);
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
if (log.level === "WARN" /* Warn */ && this.options.useWarn) {
|
|
377
|
-
c.warn(this.composeConsoleSubstitution(args), ...args);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (log.level === "ERROR" /* Error */ && this.options.useError) {
|
|
381
|
-
c.error(this.composeConsoleSubstitution(args), ...args);
|
|
382
|
-
return;
|
|
453
|
+
// src/main/handlers/HandlerBase.ts
|
|
454
|
+
var HandlerBase = class {
|
|
455
|
+
sendMethod;
|
|
456
|
+
formatArg = void 0;
|
|
457
|
+
level;
|
|
458
|
+
exact = null;
|
|
459
|
+
printTimestamp = true;
|
|
460
|
+
printLevel = true;
|
|
461
|
+
constructor(send) {
|
|
462
|
+
this.execute = this.execute.bind(this);
|
|
463
|
+
this.sendMethod = send ?? (() => {
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
*execute(meta) {
|
|
467
|
+
let arg = "";
|
|
468
|
+
let current = { value: null, type: "init" };
|
|
469
|
+
if (this.printTimestamp) {
|
|
470
|
+
arg += `${this.formatTimestamp(meta.timestamp)}`;
|
|
471
|
+
}
|
|
472
|
+
if (this.printLevel) {
|
|
473
|
+
arg += ` ${meta.level}`;
|
|
474
|
+
}
|
|
475
|
+
while (true) {
|
|
476
|
+
if (current.type === "init") {
|
|
477
|
+
current = yield { type: "init" };
|
|
383
478
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
insertInternalEntries(log) {
|
|
387
|
-
if (this.options.pretty) {
|
|
388
|
-
return this.prepareMessagePretty(log);
|
|
479
|
+
if (current.prev) {
|
|
480
|
+
arg += " " + current.prev;
|
|
389
481
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
composeConsoleSubstitution(data, startingVarConvertIndex = 2) {
|
|
393
|
-
let str = "";
|
|
394
|
-
startingVarConvertIndex = getConvertStartingIndex(this.messageFormatRaw);
|
|
395
|
-
if (this.options.pretty) {
|
|
396
|
-
startingVarConvertIndex = 3;
|
|
482
|
+
if (current.type === "done") {
|
|
483
|
+
break;
|
|
397
484
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
let vWithEqualSign = typeof v === "string" && stringMatchesVar(v, /* @__PURE__ */ new Set([]));
|
|
403
|
-
let nextVWithEqualSign = !last && typeof data[i + 1] === "string" && stringMatchesVar(data[i + 1], /* @__PURE__ */ new Set([]));
|
|
404
|
-
if (nextVWithEqualSign) {
|
|
405
|
-
startingVarConvertIndex = Math.max(startingVarConvertIndex, i);
|
|
406
|
-
}
|
|
407
|
-
if (!this.linkArguments && !takenNames.includes(v) && !last && i > startingVarConvertIndex && vWithEqualSign) {
|
|
408
|
-
data[i] = `${v} =`;
|
|
409
|
-
}
|
|
410
|
-
if (typeof v === "string") {
|
|
411
|
-
str += `%s${last ? "" : " "}`;
|
|
485
|
+
if (current.type === "arg") {
|
|
486
|
+
if (typeof this.formatArg === "function") {
|
|
487
|
+
arg += " " + this.formatArg(current.value);
|
|
488
|
+
current = yield { type: "done" };
|
|
412
489
|
continue;
|
|
413
490
|
}
|
|
414
|
-
if (typeof v === "number") {
|
|
415
|
-
str += `%d${last ? "" : " "}`;
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
str += `%o${last ? "" : " "}`;
|
|
419
491
|
}
|
|
420
|
-
|
|
492
|
+
current = yield { type: "pass" };
|
|
493
|
+
}
|
|
494
|
+
this.sendMethod(arg.trimStart());
|
|
495
|
+
}
|
|
496
|
+
formatTimestamp(t) {
|
|
497
|
+
let d = new Date(t);
|
|
498
|
+
return `${d.toLocaleDateString()} ${d.toLocaleTimeString()}`;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/main/handlers/ConsoleHandler.ts
|
|
503
|
+
function NewConsoleHandler(console2, options) {
|
|
504
|
+
return () => new class ConsoleHandler extends HandlerBase {
|
|
505
|
+
constructor(console3, options2 = {}) {
|
|
506
|
+
super();
|
|
507
|
+
this.console = console3;
|
|
508
|
+
this.applyOptionalOptions(options2);
|
|
509
|
+
this.level = options2.level;
|
|
510
|
+
this.exact = options2.exact ? toarray(options2.exact) : null;
|
|
421
511
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
512
|
+
level;
|
|
513
|
+
exact = null;
|
|
514
|
+
formatArg = (arg) => arg;
|
|
515
|
+
applyOptionalOptions(options2) {
|
|
516
|
+
this.printTimestamp = options2.printTimestamp ?? true;
|
|
517
|
+
this.printLevel = options2.printLevel ?? true;
|
|
518
|
+
}
|
|
519
|
+
*execute(meta) {
|
|
520
|
+
let args = [];
|
|
521
|
+
let current = { value: null, type: "init" };
|
|
522
|
+
if (this.printTimestamp) {
|
|
523
|
+
args.push(`${this.formatTimestamp(meta.timestamp)}`);
|
|
426
524
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
525
|
+
if (this.printLevel) {
|
|
526
|
+
let margin = this.printTimestamp ? " " : "";
|
|
527
|
+
args.push(`${margin}${meta.level}`);
|
|
528
|
+
}
|
|
529
|
+
while (true) {
|
|
530
|
+
if (current.type === "init") {
|
|
531
|
+
current = yield { type: "init" };
|
|
434
532
|
}
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
colorKeys.push(`color:${this.options.customColors?.get("grey") || this.colors.get("grey")}`);
|
|
438
|
-
continue;
|
|
533
|
+
if (current.prev) {
|
|
534
|
+
args.push(current.prev);
|
|
439
535
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
colorKeys.push(`color:${this.options.customColors?.get("green") || this.colors.get("green")}`);
|
|
443
|
-
message.push(...log.args);
|
|
444
|
-
continue;
|
|
536
|
+
if (current.type === "done") {
|
|
537
|
+
break;
|
|
445
538
|
}
|
|
446
|
-
if (
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
539
|
+
if (current.type === "arg") {
|
|
540
|
+
if (typeof this.formatArg === "function") {
|
|
541
|
+
args.push(current.value);
|
|
542
|
+
current = yield { type: "done" };
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
451
545
|
}
|
|
452
|
-
|
|
546
|
+
current = yield { type: "pass" };
|
|
453
547
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
let format = [...this.messageFormat];
|
|
458
|
-
if (!log.withArgs) {
|
|
459
|
-
format = format.slice(0, format.indexOf("%a") + 1);
|
|
548
|
+
if (meta.level.startsWith("DEBUG")) {
|
|
549
|
+
this.console.debug(...args);
|
|
550
|
+
return;
|
|
460
551
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
message.push(...log.withArgs || []);
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
if (format[i] === "%t") {
|
|
468
|
-
message.push(this.prepareDate(log.timestamp));
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
if (format[i] === "%a") {
|
|
472
|
-
message.push(...log.args);
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
if (format[i] === "%l") {
|
|
476
|
-
message.push(log.level);
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
|
-
message.push(format[i]);
|
|
552
|
+
if (meta.level.startsWith("WARN")) {
|
|
553
|
+
this.console.warn(...args);
|
|
554
|
+
return;
|
|
480
555
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (this.options.dateGetter) {
|
|
485
|
-
return this.options.dateGetter(t);
|
|
556
|
+
if (meta.level.startsWith("ERROR") || meta.level.startsWith("FATAL")) {
|
|
557
|
+
this.console.error(...args);
|
|
558
|
+
return;
|
|
486
559
|
}
|
|
487
|
-
|
|
560
|
+
this.console.info(...args);
|
|
488
561
|
}
|
|
489
|
-
}(options);
|
|
562
|
+
}(console2, options);
|
|
490
563
|
}
|
|
491
564
|
|
|
492
|
-
// src/
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
return value.toString();
|
|
496
|
-
}
|
|
497
|
-
if (value instanceof Set) {
|
|
498
|
-
return Array.from(value);
|
|
499
|
-
}
|
|
500
|
-
if (value instanceof Map) {
|
|
501
|
-
let obj = {};
|
|
502
|
-
for (let key of value.keys()) {
|
|
503
|
-
obj[key] = value.get(key);
|
|
504
|
-
}
|
|
505
|
-
return obj;
|
|
506
|
-
}
|
|
507
|
-
return value;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// src/handlers/JSONHandler/JSONHandler.ts
|
|
511
|
-
function NewJSONHandler(send, options = {}) {
|
|
512
|
-
return () => new class JSONLog {
|
|
513
|
-
constructor(options2) {
|
|
514
|
-
this.options = options2;
|
|
515
|
-
this.level = options2.level;
|
|
516
|
-
this.exact = options2.exact ? arrayed(options2.exact) : void 0;
|
|
517
|
-
this.options = options2 || {};
|
|
518
|
-
}
|
|
565
|
+
// src/main/handlers/JSONHandler.ts
|
|
566
|
+
function NewJSONHandler(send, options) {
|
|
567
|
+
return () => new class JSONHandler extends HandlerBase {
|
|
519
568
|
level;
|
|
520
|
-
exact;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
this.options.dateGetter = getter;
|
|
527
|
-
}
|
|
528
|
-
sendLog(log) {
|
|
529
|
-
try {
|
|
530
|
-
delete log.assertion;
|
|
531
|
-
delete log.messageFormat;
|
|
532
|
-
delete log.leveling;
|
|
533
|
-
log.timestamp = this.formatDate(log.timestamp);
|
|
534
|
-
send(JSON.stringify(this.flattenLinkedArguments(log), this.replacer.bind(this)));
|
|
535
|
-
} catch (err) {
|
|
536
|
-
if (log.level !== "ERROR" /* Error */) {
|
|
537
|
-
this.log({
|
|
538
|
-
args: [`err while trying to stringify JSON ${err}`],
|
|
539
|
-
timestamp: log.timestamp,
|
|
540
|
-
level: "ERROR" /* Error */,
|
|
541
|
-
leveling: ["ERROR" /* Error */, 0]
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
}
|
|
569
|
+
exact = null;
|
|
570
|
+
constructor(send2, options2 = {}) {
|
|
571
|
+
super(send2);
|
|
572
|
+
this.applyOptionalOptions(options2);
|
|
573
|
+
this.level = options2.level;
|
|
574
|
+
this.exact = options2.exact ? toarray(options2.exact) : null;
|
|
545
575
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
576
|
+
formatArg = (arg) => {
|
|
577
|
+
let type = getType(arg);
|
|
578
|
+
let formatted = formatJSON({ type, value: arg });
|
|
579
|
+
if (type !== "object" && type !== "map") {
|
|
580
|
+
return `"${formatted}"`;
|
|
549
581
|
}
|
|
550
|
-
return
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
582
|
+
return formatted;
|
|
583
|
+
};
|
|
584
|
+
*execute(meta) {
|
|
585
|
+
let arg = "{";
|
|
586
|
+
let current = { value: null, type: "init" };
|
|
587
|
+
if (this.printTimestamp) {
|
|
588
|
+
arg += `"timestamp":"${this.formatTimestamp(meta.timestamp)}",`;
|
|
555
589
|
}
|
|
556
|
-
if (
|
|
557
|
-
|
|
590
|
+
if (this.printLevel) {
|
|
591
|
+
arg += `"level":"${meta.level}",`;
|
|
558
592
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
let composedLog = log;
|
|
564
|
-
let name = "";
|
|
565
|
-
for (let arg of log.withArgs) {
|
|
566
|
-
if (typeof arg === "string" && stringMatchesVar(arg)) {
|
|
567
|
-
name = arg;
|
|
568
|
-
continue;
|
|
593
|
+
arg += `"args":[`;
|
|
594
|
+
while (true) {
|
|
595
|
+
if (current.type === "init") {
|
|
596
|
+
current = yield { type: "init" };
|
|
569
597
|
}
|
|
570
|
-
if (
|
|
571
|
-
|
|
572
|
-
name = "";
|
|
573
|
-
continue;
|
|
598
|
+
if (current.prev) {
|
|
599
|
+
arg += `"${current.prev}",`;
|
|
574
600
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
return log;
|
|
578
|
-
}
|
|
579
|
-
replacer(_, value) {
|
|
580
|
-
if (this.options.replaceBeforeStringify) {
|
|
581
|
-
let v = this.options.replaceBeforeStringify(value);
|
|
582
|
-
if (v !== null) {
|
|
583
|
-
return v;
|
|
601
|
+
if (current.type === "done") {
|
|
602
|
+
break;
|
|
584
603
|
}
|
|
604
|
+
if (current.type === "arg") {
|
|
605
|
+
if (typeof this.formatArg === "function") {
|
|
606
|
+
arg += `${this.formatArg(current.value)},`;
|
|
607
|
+
current = yield { type: "done" };
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
current = yield { type: "pass" };
|
|
612
|
+
}
|
|
613
|
+
if (arg.at(-1) === ",") {
|
|
614
|
+
arg = arg.slice(0, arg.length - 1);
|
|
585
615
|
}
|
|
586
|
-
|
|
616
|
+
arg += `]}`;
|
|
617
|
+
this.sendMethod(arg);
|
|
587
618
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
if (value instanceof Set) {
|
|
597
|
-
return `Set[${Array.from(value)}]`;
|
|
598
|
-
}
|
|
599
|
-
if (Array.isArray(value)) {
|
|
600
|
-
return `[${value}]`;
|
|
601
|
-
}
|
|
602
|
-
if (typeof value === "string") {
|
|
603
|
-
return `${value}`;
|
|
604
|
-
}
|
|
605
|
-
return stringifier(value, (_, data) => replaceDataBeforeStringify(data));
|
|
619
|
+
formatTimestamp(t) {
|
|
620
|
+
return new Date(t).toISOString();
|
|
621
|
+
}
|
|
622
|
+
applyOptionalOptions(options2) {
|
|
623
|
+
this.printTimestamp = options2.printTimestamp ?? true;
|
|
624
|
+
this.printLevel = options2.printLevel ?? true;
|
|
625
|
+
}
|
|
626
|
+
}(send, options);
|
|
606
627
|
}
|
|
607
628
|
|
|
608
|
-
// src/handlers/TextHandler
|
|
609
|
-
function NewTextHandler(send, options
|
|
610
|
-
return () => new class
|
|
611
|
-
constructor(options2) {
|
|
612
|
-
this.options = options2;
|
|
613
|
-
this.level = options2.level;
|
|
614
|
-
this.exact = options2.exact ? arrayed(options2.exact) : void 0;
|
|
615
|
-
}
|
|
616
|
-
skipDeepCopyWhenSendingLog = true;
|
|
629
|
+
// src/main/handlers/TextHandler.ts
|
|
630
|
+
function NewTextHandler(send, options) {
|
|
631
|
+
return () => new class TextHandler extends HandlerBase {
|
|
617
632
|
level;
|
|
618
|
-
exact;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
this.
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
let args = "";
|
|
627
|
-
let withArgs = "";
|
|
628
|
-
let msg = this.options.messageFormat || log.messageFormat;
|
|
629
|
-
if (log.args) {
|
|
630
|
-
args = this.composeVariablesString(msg, log.args);
|
|
631
|
-
}
|
|
632
|
-
if (log.withArgs) {
|
|
633
|
-
withArgs = this.composeVariablesString(msg, log.withArgs);
|
|
634
|
-
}
|
|
635
|
-
msg = removeTailingUndefinedValues(msg, log);
|
|
636
|
-
send(
|
|
637
|
-
msg.replace("%w", withArgs).replace("%a", args).replace("%l", log.level).replace("%t", getPrettyDate(log.timestamp))
|
|
638
|
-
);
|
|
639
|
-
}
|
|
640
|
-
composeVariablesString(format, data) {
|
|
641
|
-
let str = "";
|
|
642
|
-
let excluded = extractNonFormatChars(format);
|
|
643
|
-
for (let i = 0; i < data.length; i++) {
|
|
644
|
-
let last = i === data.length - 1;
|
|
645
|
-
let nextIsNotLinked = typeof data[i + 1] === "string" && stringMatchesVar(data[i + 1], excluded);
|
|
646
|
-
let v = data[i];
|
|
647
|
-
if (!this.linkArguments && !last && typeof v === "string" && stringMatchesVar(v, excluded) && !nextIsNotLinked) {
|
|
648
|
-
str += `${v}=${this.formatValue(data[i + 1])} `;
|
|
649
|
-
i += 1;
|
|
650
|
-
continue;
|
|
651
|
-
}
|
|
652
|
-
str += `${this.formatValue(v)}${last ? "" : " "}`;
|
|
653
|
-
}
|
|
654
|
-
return str.trim();
|
|
633
|
+
exact = null;
|
|
634
|
+
formatArg;
|
|
635
|
+
constructor(send2, options2 = {}) {
|
|
636
|
+
super(send2);
|
|
637
|
+
this.applyOptionalOptions(options2);
|
|
638
|
+
this.level = options2.level;
|
|
639
|
+
this.exact = options2.exact ? toarray(options2.exact) : null;
|
|
640
|
+
this.formatArg = (value) => format({ type: getType(value), value }, options2.spacing);
|
|
655
641
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (val !== null) {
|
|
660
|
-
return val;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return stringifyValue(v, this.options.stringifier);
|
|
642
|
+
applyOptionalOptions(options2) {
|
|
643
|
+
this.printTimestamp = options2.printTimestamp ?? true;
|
|
644
|
+
this.printLevel = options2.printLevel ?? true;
|
|
664
645
|
}
|
|
665
|
-
}(options);
|
|
646
|
+
}(send, options);
|
|
666
647
|
}
|
|
667
648
|
|
|
668
649
|
// src/index.ts
|
|
669
|
-
var
|
|
650
|
+
var logConsole = null;
|
|
651
|
+
try {
|
|
652
|
+
logConsole = "self" in window ? self.console : console;
|
|
653
|
+
} catch (_) {
|
|
654
|
+
}
|
|
655
|
+
var halua = new Halua(logConsole ? NewConsoleHandler(logConsole) : []);
|
|
670
656
|
export {
|
|
671
657
|
Level,
|
|
658
|
+
NewConsoleHandler,
|
|
672
659
|
NewJSONHandler,
|
|
673
660
|
NewTextHandler,
|
|
674
|
-
NewWebConsoleHandler,
|
|
675
661
|
halua
|
|
676
662
|
};
|