@dxos/log 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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 +221 -206
- 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 +216 -288
- 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.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 +36 -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/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 +30 -12
- package/src/config.ts +1 -0
- package/src/context.ts +36 -5
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +3 -3
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +156 -0
- package/src/log-buffer.ts +108 -0
- package/src/log.test.ts +48 -18
- package/src/log.ts +103 -57
- package/src/options.ts +26 -10
- package/src/platform/index.ts +1 -1
- package/src/processors/file-processor.ts +2 -0
- package/src/processors/index.ts +3 -3
|
@@ -1,101 +1,46 @@
|
|
|
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
|
-
var _target, _logInfoProperties;
|
|
42
|
-
((_target = target)[_logInfoProperties = logInfoProperties] ?? (_target[_logInfoProperties] = [])).push(propertyKey);
|
|
43
|
-
};
|
|
44
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
45
|
-
if (!scope) {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
const res = {};
|
|
49
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
50
|
-
const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
|
|
51
|
-
for (const prop of infoProps) {
|
|
52
|
-
try {
|
|
53
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
54
|
-
} catch (err) {
|
|
55
|
-
res[prop] = err.message;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return res;
|
|
59
|
-
};
|
|
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";
|
|
60
16
|
|
|
61
|
-
// src/
|
|
62
|
-
var
|
|
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
|
-
|
|
88
|
-
} else if (typeof entryContext === "object") {
|
|
89
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (entry.error) {
|
|
93
|
-
context = Object.assign(context ?? {}, {
|
|
94
|
-
error: entry.error
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
98
|
-
};
|
|
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";
|
|
99
44
|
|
|
100
45
|
// src/decorators.ts
|
|
101
46
|
import { inspect } from "@dxos/node-std/util";
|
|
@@ -196,53 +141,37 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
196
141
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
197
142
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
198
143
|
};
|
|
199
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
200
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
201
144
|
var COLOR_FUNCTION = [
|
|
202
145
|
220,
|
|
203
146
|
220,
|
|
204
147
|
170
|
|
205
148
|
];
|
|
149
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
150
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
206
151
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
207
152
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
208
153
|
|
|
209
154
|
// src/options.ts
|
|
210
155
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
211
156
|
|
|
212
|
-
// src/platform/
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (typeof localStorage === "undefined") {
|
|
217
|
-
if (globalThis.localStorage_dxlog) {
|
|
218
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
222
|
-
}
|
|
223
|
-
if (!dxlog) {
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
return JSON.parse(dxlog);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.info("can't parse dxlog config", err);
|
|
229
|
-
return void 0;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
157
|
+
// src/platform/index.ts
|
|
158
|
+
var platform_exports = {};
|
|
159
|
+
__reExport(platform_exports, platform_star);
|
|
160
|
+
import * as platform_star from "#platform";
|
|
232
161
|
|
|
233
|
-
// src/processors/
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
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
|
+
});
|
|
242
171
|
|
|
243
172
|
// src/processors/browser-processor.ts
|
|
244
173
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
245
|
-
var
|
|
174
|
+
var getRelativeFilename2 = (filename) => {
|
|
246
175
|
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
247
176
|
if (match) {
|
|
248
177
|
const [, filePath] = match;
|
|
@@ -262,7 +191,7 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
262
191
|
const LOG_BROWSER_CSS = [];
|
|
263
192
|
let link = "";
|
|
264
193
|
if (entry.meta) {
|
|
265
|
-
const filename =
|
|
194
|
+
const filename = getRelativeFilename2(entry.meta.F);
|
|
266
195
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
267
196
|
link = `${filepath}#L${entry.meta.L}`;
|
|
268
197
|
}
|
|
@@ -318,7 +247,7 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
318
247
|
}
|
|
319
248
|
let path = "";
|
|
320
249
|
if (entry.meta) {
|
|
321
|
-
path = `${
|
|
250
|
+
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
322
251
|
}
|
|
323
252
|
let args = [];
|
|
324
253
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
@@ -347,22 +276,20 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
347
276
|
};
|
|
348
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
349
278
|
|
|
350
|
-
// src/processors/
|
|
351
|
-
|
|
352
|
-
import
|
|
353
|
-
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";
|
|
354
282
|
|
|
355
|
-
// src/processors/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const [, filePath] = match;
|
|
360
|
-
return filePath;
|
|
361
|
-
}
|
|
362
|
-
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));
|
|
363
287
|
};
|
|
364
288
|
|
|
365
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";
|
|
366
293
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
367
294
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
368
295
|
let fd;
|
|
@@ -387,7 +314,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
387
314
|
timestamp: Date.now(),
|
|
388
315
|
...entry.meta ? {
|
|
389
316
|
meta: {
|
|
390
|
-
file:
|
|
317
|
+
file: getRelativeFilename(entry.meta.F),
|
|
391
318
|
line: entry.meta.L
|
|
392
319
|
}
|
|
393
320
|
} : {},
|
|
@@ -415,7 +342,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
415
342
|
};
|
|
416
343
|
var logFilePath;
|
|
417
344
|
var getLogFilePath = () => {
|
|
418
|
-
logFilePath
|
|
345
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
419
346
|
return logFilePath;
|
|
420
347
|
};
|
|
421
348
|
var FILE_PROCESSOR = createFileProcessor({
|
|
@@ -430,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
430
357
|
|
|
431
358
|
// src/options.ts
|
|
432
359
|
var processors = {
|
|
433
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
434
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
435
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
436
363
|
};
|
|
437
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
438
365
|
var DEFAULT_PROCESSORS = [
|
|
439
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
440
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
441
369
|
var parseFilter = (filter) => {
|
|
442
370
|
if (typeof filter === "number") {
|
|
443
371
|
return [
|
|
@@ -446,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
446
374
|
}
|
|
447
375
|
];
|
|
448
376
|
}
|
|
449
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
450
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
451
378
|
return lines.map((filter2) => {
|
|
452
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -458,55 +385,37 @@ var parseFilter = (filter) => {
|
|
|
458
385
|
};
|
|
459
386
|
});
|
|
460
387
|
};
|
|
461
|
-
var
|
|
462
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
463
390
|
file: process.env.LOG_CONFIG,
|
|
464
391
|
filter: process.env.LOG_FILTER,
|
|
465
392
|
processor: process.env.LOG_PROCESSOR
|
|
466
393
|
} : void 0;
|
|
467
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
468
395
|
return {
|
|
469
396
|
options: mergedOptions,
|
|
470
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
471
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
472
399
|
processors: mergedOptions.processor ? [
|
|
473
400
|
processors[mergedOptions.processor]
|
|
474
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
475
404
|
prefix: mergedOptions.prefix
|
|
476
405
|
};
|
|
477
406
|
};
|
|
478
407
|
|
|
479
408
|
// src/log.ts
|
|
480
|
-
var
|
|
409
|
+
var logCount = 0;
|
|
481
410
|
var createLog = () => {
|
|
482
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
483
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
484
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
485
417
|
get: () => log2._config
|
|
486
418
|
});
|
|
487
|
-
log2.addProcessor = (processor) => {
|
|
488
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
489
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
490
|
-
}
|
|
491
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
492
|
-
log2._config.processors.push(processor);
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
log2.config = (options) => {
|
|
496
|
-
log2._config = getConfig(options);
|
|
497
|
-
};
|
|
498
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
499
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
500
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
501
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
502
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
503
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
504
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
505
|
-
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");
|
|
506
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
507
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
508
|
-
log2.method = createMethodLogDecorator(log2);
|
|
509
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
510
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
511
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
512
421
|
level,
|
|
@@ -516,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
516
425
|
error
|
|
517
426
|
}));
|
|
518
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
|
+
});
|
|
519
469
|
return log2;
|
|
520
470
|
};
|
|
521
|
-
var log =
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
522
472
|
var start = Date.now();
|
|
523
473
|
var last = start;
|
|
524
474
|
var debug = (label, args) => {
|
|
@@ -535,26 +485,96 @@ var debug = (label, args) => {
|
|
|
535
485
|
};
|
|
536
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
537
487
|
|
|
538
|
-
// src/
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
configurable: true,
|
|
546
|
-
writable: true
|
|
547
|
-
});
|
|
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);
|
|
548
495
|
} else {
|
|
549
|
-
|
|
496
|
+
console.log(arg);
|
|
497
|
+
}
|
|
498
|
+
return arg;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/log-buffer.ts
|
|
502
|
+
import { CircularBuffer } 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
|
+
this._buffer.push(record);
|
|
541
|
+
};
|
|
542
|
+
/** Number of entries currently in the buffer. */
|
|
543
|
+
get size() {
|
|
544
|
+
return this._buffer.elementCount;
|
|
545
|
+
}
|
|
546
|
+
/** Discard all buffered entries. */
|
|
547
|
+
clear() {
|
|
548
|
+
this._buffer.clear();
|
|
549
|
+
}
|
|
550
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
551
|
+
serialize() {
|
|
552
|
+
const lines = [];
|
|
553
|
+
for (const record of this._buffer) {
|
|
554
|
+
lines.push(JSON.stringify(record));
|
|
555
|
+
}
|
|
556
|
+
return lines.join("\n");
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
var getRelativeFilename3 = (filename) => {
|
|
560
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
561
|
+
if (match) {
|
|
562
|
+
return match[1];
|
|
550
563
|
}
|
|
551
|
-
return
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
var
|
|
564
|
+
return filename;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// src/experimental/ownership.ts
|
|
568
|
+
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
569
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
557
570
|
var OwnershipScope = class {
|
|
571
|
+
constr;
|
|
572
|
+
parent;
|
|
573
|
+
instance;
|
|
574
|
+
constructor(constr, parent) {
|
|
575
|
+
this.constr = constr;
|
|
576
|
+
this.parent = parent;
|
|
577
|
+
}
|
|
558
578
|
getInfo() {
|
|
559
579
|
if (!this.instance) {
|
|
560
580
|
return {};
|
|
@@ -566,35 +586,30 @@ var OwnershipScope = class {
|
|
|
566
586
|
}
|
|
567
587
|
return info;
|
|
568
588
|
}
|
|
569
|
-
[
|
|
589
|
+
[inspect3.custom]() {
|
|
570
590
|
return {
|
|
571
591
|
className: this.constr.name,
|
|
572
592
|
info: this.getInfo(),
|
|
573
593
|
parent: this.parent
|
|
574
594
|
};
|
|
575
595
|
}
|
|
576
|
-
constructor(constr, parent) {
|
|
577
|
-
_define_property(this, "constr", void 0);
|
|
578
|
-
_define_property(this, "parent", void 0);
|
|
579
|
-
_define_property(this, "instance", void 0);
|
|
580
|
-
this.constr = constr;
|
|
581
|
-
this.parent = parent;
|
|
582
|
-
}
|
|
583
596
|
};
|
|
584
597
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
585
598
|
export {
|
|
586
599
|
BROWSER_PROCESSOR,
|
|
587
|
-
CONSOLE_PROCESSOR,
|
|
588
600
|
DEBUG_PROCESSOR,
|
|
589
601
|
FILE_PROCESSOR,
|
|
602
|
+
LogBuffer,
|
|
590
603
|
LogLevel,
|
|
591
604
|
LogProcessorType,
|
|
592
605
|
createFileProcessor,
|
|
606
|
+
createLog,
|
|
607
|
+
dbg,
|
|
593
608
|
debug,
|
|
594
609
|
gatherLogInfoFromScope,
|
|
595
610
|
getContextFromEntry,
|
|
596
611
|
getCurrentOwnershipScope,
|
|
597
|
-
|
|
612
|
+
getRelativeFilename,
|
|
598
613
|
levels,
|
|
599
614
|
log,
|
|
600
615
|
logInfo,
|