@dxos/log 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs +133 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +222 -182
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/platform/browser/index.mjs +26 -0
- package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
- package/dist/lib/browser/platform/node/index.mjs +21 -0
- package/dist/lib/browser/platform/node/index.mjs.map +7 -0
- package/dist/lib/browser/processors/console-processor.mjs +107 -0
- package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
- package/dist/lib/browser/processors/console-stub.mjs +9 -0
- package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-62VKC2WQ.mjs +135 -0
- package/dist/lib/node-esm/chunk-62VKC2WQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +219 -264
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
- package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
- package/dist/lib/node-esm/platform/node/index.mjs +22 -0
- package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-processor.mjs +108 -0
- package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
- package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
- package/dist/types/src/config.d.ts +2 -3
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/dbg.d.ts +23 -0
- package/dist/types/src/dbg.d.ts.map +1 -0
- package/dist/types/src/decorators.d.ts +1 -1
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log-buffer.d.ts +37 -0
- package/dist/types/src/log-buffer.d.ts.map +1 -0
- package/dist/types/src/log-buffer.test.d.ts +2 -0
- package/dist/types/src/log-buffer.test.d.ts.map +1 -0
- package/dist/types/src/log.d.ts +14 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/platform/node/index.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -14
- package/src/config.ts +3 -2
- package/src/context.ts +36 -5
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +5 -4
- package/src/experimental/classes.test.ts +2 -1
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +156 -0
- package/src/log-buffer.ts +114 -0
- package/src/log.test.ts +49 -18
- package/src/log.ts +103 -57
- package/src/options.ts +27 -11
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +2 -1
- package/src/processors/browser-processor.ts +3 -1
- package/src/processors/console-processor.ts +9 -5
- package/src/processors/file-processor.ts +4 -1
- package/src/processors/index.ts +3 -3
- package/src/scope.ts +1 -1
|
@@ -1,104 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
trace: 5,
|
|
17
|
-
debug: 10,
|
|
18
|
-
verbose: 11,
|
|
19
|
-
info: 12,
|
|
20
|
-
warn: 13,
|
|
21
|
-
error: 14
|
|
22
|
-
};
|
|
23
|
-
var shortLevelName = {
|
|
24
|
-
[5]: "T",
|
|
25
|
-
[10]: "D",
|
|
26
|
-
[11]: "V",
|
|
27
|
-
[12]: "I",
|
|
28
|
-
[13]: "W",
|
|
29
|
-
[14]: "E"
|
|
30
|
-
};
|
|
31
|
-
var LogProcessorType = /* @__PURE__ */ function(LogProcessorType2) {
|
|
32
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
33
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
34
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
35
|
-
return LogProcessorType2;
|
|
36
|
-
}({});
|
|
37
|
-
|
|
38
|
-
// src/scope.ts
|
|
39
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
40
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
41
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
42
|
-
};
|
|
43
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
44
|
-
if (!scope) {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
const res = {};
|
|
48
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
49
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
50
|
-
for (const prop of infoProps) {
|
|
51
|
-
try {
|
|
52
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
53
|
-
} catch (err) {
|
|
54
|
-
res[prop] = err.message;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return res;
|
|
58
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
LogLevel,
|
|
3
|
+
LogProcessorType,
|
|
4
|
+
gatherLogInfoFromScope,
|
|
5
|
+
getContextFromEntry,
|
|
6
|
+
getRelativeFilename,
|
|
7
|
+
levels,
|
|
8
|
+
logInfo,
|
|
9
|
+
shortLevelName,
|
|
10
|
+
shouldLog
|
|
11
|
+
} from "./chunk-M2YHSBML.mjs";
|
|
12
|
+
import {
|
|
13
|
+
__export,
|
|
14
|
+
__reExport
|
|
15
|
+
} from "./chunk-IEP6GGEX.mjs";
|
|
59
16
|
|
|
60
|
-
// src/
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else if (typeof entryContext === "object") {
|
|
88
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (entry.error) {
|
|
92
|
-
context = Object.assign(context ?? {}, {
|
|
93
|
-
error: entry.error
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
97
|
-
};
|
|
17
|
+
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
21
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
22
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
23
|
+
LogBuffer: () => LogBuffer,
|
|
24
|
+
LogLevel: () => LogLevel,
|
|
25
|
+
LogProcessorType: () => LogProcessorType,
|
|
26
|
+
createFileProcessor: () => createFileProcessor,
|
|
27
|
+
createLog: () => createLog,
|
|
28
|
+
dbg: () => dbg,
|
|
29
|
+
debug: () => debug,
|
|
30
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
31
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
32
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
33
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
34
|
+
levels: () => levels,
|
|
35
|
+
log: () => log,
|
|
36
|
+
logInfo: () => logInfo,
|
|
37
|
+
omit: () => omit,
|
|
38
|
+
parseFilter: () => parseFilter,
|
|
39
|
+
pick: () => pick,
|
|
40
|
+
shortLevelName: () => shortLevelName,
|
|
41
|
+
shouldLog: () => shouldLog
|
|
42
|
+
});
|
|
43
|
+
import { omit, pick } from "@dxos/util";
|
|
98
44
|
|
|
99
45
|
// src/decorators.ts
|
|
100
|
-
import chalk from "chalk";
|
|
101
46
|
import { inspect } from "@dxos/node-std/util";
|
|
47
|
+
import chalk from "chalk";
|
|
102
48
|
var nextPromiseId = 0;
|
|
103
49
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
104
50
|
const method = descriptor.value;
|
|
@@ -195,53 +141,37 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
195
141
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
196
142
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
197
143
|
};
|
|
198
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
199
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
200
144
|
var COLOR_FUNCTION = [
|
|
201
145
|
220,
|
|
202
146
|
220,
|
|
203
147
|
170
|
|
204
148
|
];
|
|
149
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
150
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
205
151
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
206
152
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
207
153
|
|
|
208
154
|
// src/options.ts
|
|
209
155
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
210
156
|
|
|
211
|
-
// src/platform/
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (typeof localStorage === "undefined") {
|
|
216
|
-
if (globalThis.localStorage_dxlog) {
|
|
217
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
221
|
-
}
|
|
222
|
-
if (!dxlog) {
|
|
223
|
-
return void 0;
|
|
224
|
-
}
|
|
225
|
-
return JSON.parse(dxlog);
|
|
226
|
-
} catch (err) {
|
|
227
|
-
console.info("can't parse dxlog config", err);
|
|
228
|
-
return void 0;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// src/processors/console-stub.ts
|
|
233
|
-
var CONSOLE_PROCESSOR = () => {
|
|
234
|
-
};
|
|
157
|
+
// src/platform/index.ts
|
|
158
|
+
var platform_exports = {};
|
|
159
|
+
__reExport(platform_exports, platform_star);
|
|
160
|
+
import * as platform_star from "#platform";
|
|
235
161
|
|
|
236
|
-
// src/processors/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
162
|
+
// src/processors/index.ts
|
|
163
|
+
var processors_exports = {};
|
|
164
|
+
__export(processors_exports, {
|
|
165
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
166
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
167
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
168
|
+
createFileProcessor: () => createFileProcessor,
|
|
169
|
+
getRelativeFilename: () => getRelativeFilename
|
|
170
|
+
});
|
|
241
171
|
|
|
242
172
|
// src/processors/browser-processor.ts
|
|
243
173
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
244
|
-
var
|
|
174
|
+
var getRelativeFilename2 = (filename) => {
|
|
245
175
|
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
246
176
|
if (match) {
|
|
247
177
|
const [, filePath] = match;
|
|
@@ -261,7 +191,7 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
261
191
|
const LOG_BROWSER_CSS = [];
|
|
262
192
|
let link = "";
|
|
263
193
|
if (entry.meta) {
|
|
264
|
-
const filename =
|
|
194
|
+
const filename = getRelativeFilename2(entry.meta.F);
|
|
265
195
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
266
196
|
link = `${filepath}#L${entry.meta.L}`;
|
|
267
197
|
}
|
|
@@ -279,6 +209,8 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
279
209
|
if (context) {
|
|
280
210
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
281
211
|
args.push(context.error);
|
|
212
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
213
|
+
args.push(context.err);
|
|
282
214
|
} else {
|
|
283
215
|
args.push(context);
|
|
284
216
|
}
|
|
@@ -315,7 +247,7 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
315
247
|
}
|
|
316
248
|
let path = "";
|
|
317
249
|
if (entry.meta) {
|
|
318
|
-
path = `${
|
|
250
|
+
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
319
251
|
}
|
|
320
252
|
let args = [];
|
|
321
253
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
@@ -344,22 +276,20 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
344
276
|
};
|
|
345
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
346
278
|
|
|
347
|
-
// src/processors/
|
|
348
|
-
|
|
349
|
-
import
|
|
350
|
-
import { jsonlogify } from "@dxos/util";
|
|
279
|
+
// src/processors/index.ts
|
|
280
|
+
__reExport(processors_exports, console_processor_star);
|
|
281
|
+
import * as console_processor_star from "#console-processor";
|
|
351
282
|
|
|
352
|
-
// src/processors/
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const [, filePath] = match;
|
|
357
|
-
return filePath;
|
|
358
|
-
}
|
|
359
|
-
return filename;
|
|
283
|
+
// src/processors/debug-processor.ts
|
|
284
|
+
import { inspect as inspect2 } from "@dxos/node-std/util";
|
|
285
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
286
|
+
console.log(inspect2(entry, false, null, true));
|
|
360
287
|
};
|
|
361
288
|
|
|
362
289
|
// src/processors/file-processor.ts
|
|
290
|
+
import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
|
|
291
|
+
import { dirname } from "@dxos/node-std/path";
|
|
292
|
+
import { jsonlogify } from "@dxos/util";
|
|
363
293
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
364
294
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
365
295
|
let fd;
|
|
@@ -384,7 +314,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
384
314
|
timestamp: Date.now(),
|
|
385
315
|
...entry.meta ? {
|
|
386
316
|
meta: {
|
|
387
|
-
file:
|
|
317
|
+
file: getRelativeFilename(entry.meta.F),
|
|
388
318
|
line: entry.meta.L
|
|
389
319
|
}
|
|
390
320
|
} : {},
|
|
@@ -427,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
427
357
|
|
|
428
358
|
// src/options.ts
|
|
429
359
|
var processors = {
|
|
430
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
431
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
432
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
433
363
|
};
|
|
434
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
435
365
|
var DEFAULT_PROCESSORS = [
|
|
436
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
437
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
438
369
|
var parseFilter = (filter) => {
|
|
439
370
|
if (typeof filter === "number") {
|
|
440
371
|
return [
|
|
@@ -443,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
443
374
|
}
|
|
444
375
|
];
|
|
445
376
|
}
|
|
446
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
447
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
448
378
|
return lines.map((filter2) => {
|
|
449
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -455,54 +385,37 @@ var parseFilter = (filter) => {
|
|
|
455
385
|
};
|
|
456
386
|
});
|
|
457
387
|
};
|
|
458
|
-
var
|
|
459
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
460
390
|
file: process.env.LOG_CONFIG,
|
|
461
391
|
filter: process.env.LOG_FILTER,
|
|
462
392
|
processor: process.env.LOG_PROCESSOR
|
|
463
393
|
} : void 0;
|
|
464
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
465
395
|
return {
|
|
466
396
|
options: mergedOptions,
|
|
467
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
468
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
469
399
|
processors: mergedOptions.processor ? [
|
|
470
400
|
processors[mergedOptions.processor]
|
|
471
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
472
404
|
prefix: mergedOptions.prefix
|
|
473
405
|
};
|
|
474
406
|
};
|
|
475
407
|
|
|
476
408
|
// src/log.ts
|
|
409
|
+
var logCount = 0;
|
|
477
410
|
var createLog = () => {
|
|
478
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
479
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
480
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
481
417
|
get: () => log2._config
|
|
482
418
|
});
|
|
483
|
-
log2.addProcessor = (processor) => {
|
|
484
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
485
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
486
|
-
}
|
|
487
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
488
|
-
log2._config.processors.push(processor);
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
log2.config = (options) => {
|
|
492
|
-
log2._config = getConfig(options);
|
|
493
|
-
};
|
|
494
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
495
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
496
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
497
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
498
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
499
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
500
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
501
|
-
log2.break = () => log2.info("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014");
|
|
502
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
503
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
504
|
-
log2.method = createMethodLogDecorator(log2);
|
|
505
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
506
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
507
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
508
421
|
level,
|
|
@@ -512,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
512
425
|
error
|
|
513
426
|
}));
|
|
514
427
|
};
|
|
428
|
+
Object.assign(log2, {
|
|
429
|
+
/**
|
|
430
|
+
* Update config.
|
|
431
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
432
|
+
* unless an explicit processor option is provided.
|
|
433
|
+
*/
|
|
434
|
+
config: ({ processor, ...options } = {}) => {
|
|
435
|
+
const config = createConfig(options);
|
|
436
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
437
|
+
log2._config = {
|
|
438
|
+
...config,
|
|
439
|
+
processors: processors2
|
|
440
|
+
};
|
|
441
|
+
return log2;
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
444
|
+
* Adds a processor to the logger.
|
|
445
|
+
*/
|
|
446
|
+
addProcessor: (processor) => {
|
|
447
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
448
|
+
log2._config.processors.push(processor);
|
|
449
|
+
}
|
|
450
|
+
return () => {
|
|
451
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
455
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
456
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
457
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
458
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
459
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
460
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
461
|
+
method: createMethodLogDecorator(log2),
|
|
462
|
+
function: createFunctionLogDecorator(log2),
|
|
463
|
+
break: () => log2.info("-".repeat(80)),
|
|
464
|
+
stack: (message, context, meta) => {
|
|
465
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
466
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
515
469
|
return log2;
|
|
516
470
|
};
|
|
517
|
-
var log = globalThis.
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
518
472
|
var start = Date.now();
|
|
519
473
|
var last = start;
|
|
520
474
|
var debug = (label, args) => {
|
|
@@ -531,12 +485,96 @@ var debug = (label, args) => {
|
|
|
531
485
|
};
|
|
532
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
533
487
|
|
|
488
|
+
// src/index.ts
|
|
489
|
+
__reExport(index_exports, processors_exports);
|
|
490
|
+
|
|
491
|
+
// src/dbg.ts
|
|
492
|
+
var dbg = (arg, meta) => {
|
|
493
|
+
if (meta?.A) {
|
|
494
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
495
|
+
} else {
|
|
496
|
+
console.log(arg);
|
|
497
|
+
}
|
|
498
|
+
return arg;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/log-buffer.ts
|
|
502
|
+
import { CircularBuffer, getDebugName as getDebugName2 } from "@dxos/util";
|
|
503
|
+
var DEFAULT_BUFFER_SIZE = 2e3;
|
|
504
|
+
var MAX_CONTEXT_LENGTH = 500;
|
|
505
|
+
var LogBuffer = class {
|
|
506
|
+
_buffer;
|
|
507
|
+
constructor(size = DEFAULT_BUFFER_SIZE) {
|
|
508
|
+
this._buffer = new CircularBuffer(size);
|
|
509
|
+
}
|
|
510
|
+
/** Log processor that can be registered with `log.runtimeConfig.processors`. */
|
|
511
|
+
logProcessor = (_config, entry) => {
|
|
512
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const record = {
|
|
516
|
+
t: (/* @__PURE__ */ new Date()).toISOString(),
|
|
517
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
518
|
+
m: entry.message ?? ""
|
|
519
|
+
};
|
|
520
|
+
if (entry.meta) {
|
|
521
|
+
record.f = getRelativeFilename3(entry.meta.F);
|
|
522
|
+
record.n = entry.meta.L;
|
|
523
|
+
}
|
|
524
|
+
if (entry.error) {
|
|
525
|
+
record.e = entry.error.stack ?? entry.error.message;
|
|
526
|
+
}
|
|
527
|
+
if (entry.context != null) {
|
|
528
|
+
try {
|
|
529
|
+
const ctx = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
530
|
+
if (ctx != null && !(ctx instanceof Error)) {
|
|
531
|
+
let json = JSON.stringify(ctx);
|
|
532
|
+
if (json.length > MAX_CONTEXT_LENGTH) {
|
|
533
|
+
json = json.slice(0, MAX_CONTEXT_LENGTH);
|
|
534
|
+
}
|
|
535
|
+
record.c = json;
|
|
536
|
+
}
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const scope = entry.meta?.S;
|
|
541
|
+
if (typeof scope === "object" && scope !== null && Object.getPrototypeOf(scope) !== Object.prototype) {
|
|
542
|
+
record.o = getDebugName2(scope);
|
|
543
|
+
}
|
|
544
|
+
this._buffer.push(record);
|
|
545
|
+
};
|
|
546
|
+
/** Number of entries currently in the buffer. */
|
|
547
|
+
get size() {
|
|
548
|
+
return this._buffer.elementCount;
|
|
549
|
+
}
|
|
550
|
+
/** Discard all buffered entries. */
|
|
551
|
+
clear() {
|
|
552
|
+
this._buffer.clear();
|
|
553
|
+
}
|
|
554
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
555
|
+
serialize() {
|
|
556
|
+
const lines = [];
|
|
557
|
+
for (const record of this._buffer) {
|
|
558
|
+
lines.push(JSON.stringify(record));
|
|
559
|
+
}
|
|
560
|
+
return lines.join("\n");
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
var getRelativeFilename3 = (filename) => {
|
|
564
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
565
|
+
if (match) {
|
|
566
|
+
return match[1];
|
|
567
|
+
}
|
|
568
|
+
return filename;
|
|
569
|
+
};
|
|
570
|
+
|
|
534
571
|
// src/experimental/ownership.ts
|
|
535
572
|
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
536
|
-
var
|
|
537
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
538
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
573
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
539
574
|
var OwnershipScope = class {
|
|
575
|
+
constr;
|
|
576
|
+
parent;
|
|
577
|
+
instance;
|
|
540
578
|
constructor(constr, parent) {
|
|
541
579
|
this.constr = constr;
|
|
542
580
|
this.parent = parent;
|
|
@@ -563,17 +601,19 @@ var OwnershipScope = class {
|
|
|
563
601
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
564
602
|
export {
|
|
565
603
|
BROWSER_PROCESSOR,
|
|
566
|
-
CONSOLE_PROCESSOR,
|
|
567
604
|
DEBUG_PROCESSOR,
|
|
568
605
|
FILE_PROCESSOR,
|
|
606
|
+
LogBuffer,
|
|
569
607
|
LogLevel,
|
|
570
608
|
LogProcessorType,
|
|
571
609
|
createFileProcessor,
|
|
610
|
+
createLog,
|
|
611
|
+
dbg,
|
|
572
612
|
debug,
|
|
573
613
|
gatherLogInfoFromScope,
|
|
574
614
|
getContextFromEntry,
|
|
575
615
|
getCurrentOwnershipScope,
|
|
576
|
-
|
|
616
|
+
getRelativeFilename,
|
|
577
617
|
levels,
|
|
578
618
|
log,
|
|
579
619
|
logInfo,
|