@dxos/log 0.6.13 → 0.6.14-main.1366248

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.
@@ -0,0 +1,626 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // packages/common/log/src/index.ts
4
+ import omit from "lodash.omit";
5
+ import { pick } from "@dxos/util";
6
+
7
+ // packages/common/log/src/config.ts
8
+ var LogLevel;
9
+ (function(LogLevel2) {
10
+ LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
11
+ LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
12
+ LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
13
+ LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
14
+ LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
15
+ LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
16
+ })(LogLevel || (LogLevel = {}));
17
+ var levels = {
18
+ trace: 5,
19
+ debug: 10,
20
+ info: 12,
21
+ warn: 13,
22
+ error: 14
23
+ };
24
+ var shortLevelName = {
25
+ [5]: "T",
26
+ [10]: "D",
27
+ [11]: "V",
28
+ [12]: "I",
29
+ [13]: "W",
30
+ [14]: "E"
31
+ };
32
+ var LogProcessorType;
33
+ (function(LogProcessorType2) {
34
+ LogProcessorType2["CONSOLE"] = "console";
35
+ LogProcessorType2["BROWSER"] = "browser";
36
+ LogProcessorType2["DEBUG"] = "debug";
37
+ })(LogProcessorType || (LogProcessorType = {}));
38
+
39
+ // packages/common/log/src/scope.ts
40
+ var logInfoProperties = Symbol("logInfoProperties");
41
+ var logInfo = (target, propertyKey, descriptor) => {
42
+ (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 = 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
+ };
60
+
61
+ // packages/common/log/src/context.ts
62
+ var matchFilter = (filter, level, path) => {
63
+ return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
64
+ };
65
+ var shouldLog = (entry, filters) => {
66
+ if (filters === void 0) {
67
+ return true;
68
+ } else {
69
+ return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
70
+ }
71
+ };
72
+ var getContextFromEntry = (entry) => {
73
+ let context;
74
+ if (entry.meta) {
75
+ const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
76
+ if (Object.keys(scopeInfo).length > 0) {
77
+ context = Object.assign(context ?? {}, scopeInfo);
78
+ }
79
+ }
80
+ const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
81
+ if (entryContext) {
82
+ if (entryContext instanceof Error) {
83
+ const c = entryContext.context;
84
+ context = Object.assign(context ?? {}, {
85
+ error: entryContext.stack,
86
+ ...c
87
+ });
88
+ } else if (typeof entryContext === "object") {
89
+ context = Object.assign(context ?? {}, entryContext);
90
+ }
91
+ }
92
+ if (entry.error) {
93
+ const errorContext = entry.error.context;
94
+ context = Object.assign(context ?? {}, {
95
+ error: entry.error,
96
+ ...errorContext
97
+ });
98
+ }
99
+ return context && Object.keys(context).length > 0 ? context : void 0;
100
+ };
101
+
102
+ // packages/common/log/src/decorators.ts
103
+ import chalk from "chalk";
104
+ import { inspect } from "node:util";
105
+ var nextPromiseId = 0;
106
+ var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
107
+ const method = descriptor.value;
108
+ const methodName = propertyKey;
109
+ descriptor.value = function(...args) {
110
+ const combinedMeta = {
111
+ F: "",
112
+ L: 0,
113
+ ...meta ?? {},
114
+ S: this
115
+ };
116
+ const formattedArgs = args.map((arg) => inspect(arg, false, 1, true)).join(", ");
117
+ try {
118
+ const startTime = performance.now();
119
+ const result = method.apply(this, args);
120
+ if (isThenable(result)) {
121
+ const id = nextPromiseId++;
122
+ logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
123
+ result.then((resolvedValue) => {
124
+ logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
125
+ }, (err) => {
126
+ logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
127
+ });
128
+ } else {
129
+ logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
130
+ }
131
+ return result;
132
+ } catch (err) {
133
+ logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
134
+ throw err;
135
+ }
136
+ };
137
+ Object.defineProperty(descriptor.value, "name", {
138
+ value: methodName + "$log"
139
+ });
140
+ };
141
+ var isThenable = (obj) => obj && typeof obj.then === "function";
142
+ var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
143
+ log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray("=>")} ${inspect(result, false, 1, true)}`, {}, combinedMeta);
144
+ };
145
+ var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
146
+ log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
147
+ };
148
+ var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
149
+ log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${chalk.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
150
+ };
151
+ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
152
+ if (resolvedValue !== void 0) {
153
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${inspect(resolvedValue, false, 1, true)}`, {}, combinedMeta);
154
+ } else {
155
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
156
+ }
157
+ };
158
+ var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
159
+ log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
160
+ };
161
+ var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
162
+ var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
163
+ var COLOR_FUNCTION = [
164
+ 220,
165
+ 220,
166
+ 170
167
+ ];
168
+ var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
169
+ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
170
+
171
+ // packages/common/log/src/options.ts
172
+ import defaultsDeep from "lodash.defaultsdeep";
173
+
174
+ // packages/common/log/src/platform/node/index.ts
175
+ import yaml from "js-yaml";
176
+ import fs from "node:fs";
177
+ var loadOptions = (filepath) => {
178
+ if (filepath) {
179
+ try {
180
+ const text = fs.readFileSync(filepath, "utf-8");
181
+ if (text) {
182
+ return yaml.load(text);
183
+ }
184
+ } catch (err) {
185
+ console.warn(`Invalid log file: ${filepath}`);
186
+ }
187
+ }
188
+ };
189
+
190
+ // packages/common/log/src/processors/console-processor.ts
191
+ import chalk2 from "chalk";
192
+ import { inspect as inspect2 } from "node:util";
193
+ import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
194
+
195
+ // packages/common/log/src/processors/common.ts
196
+ var getRelativeFilename = (filename) => {
197
+ const match = filename.match(/.+\/(packages\/.+\/.+)/);
198
+ if (match) {
199
+ const [, filePath] = match;
200
+ return filePath;
201
+ }
202
+ return filename;
203
+ };
204
+
205
+ // packages/common/log/src/processors/console-processor.ts
206
+ var LEVEL_COLORS = {
207
+ [LogLevel.TRACE]: "gray",
208
+ [LogLevel.DEBUG]: "gray",
209
+ [LogLevel.VERBOSE]: "gray",
210
+ [LogLevel.INFO]: "white",
211
+ [LogLevel.WARN]: "yellow",
212
+ [LogLevel.ERROR]: "red"
213
+ };
214
+ var truncate = (text, length = 0, right = false) => {
215
+ const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
216
+ return right ? str.padStart(length, " ") : str.padEnd(length, " ");
217
+ };
218
+ var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
219
+ const column = config.options?.formatter?.column;
220
+ const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
221
+ let instance;
222
+ if (scope) {
223
+ const prototype = Object.getPrototypeOf(scope);
224
+ const id = getPrototypeSpecificInstanceId(scope);
225
+ instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
226
+ }
227
+ const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
228
+ const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
229
+ const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
230
+ return config.options?.formatter?.timestampFirst ? [
231
+ formattedTimestamp,
232
+ filepath,
233
+ padding,
234
+ formattedLevel,
235
+ instance,
236
+ message,
237
+ context,
238
+ error
239
+ ] : [
240
+ // NOTE: File path must come fist for console hyperlinks.
241
+ // Must not truncate for terminal output.
242
+ filepath,
243
+ padding,
244
+ formattedTimestamp,
245
+ formattedLevel,
246
+ instance,
247
+ message,
248
+ context,
249
+ error
250
+ ];
251
+ };
252
+ var SHORT_FORMATTER = (config, { path, level, message }) => {
253
+ return [
254
+ chalk2.grey(truncate(path, 16, true)),
255
+ chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
256
+ message
257
+ ];
258
+ };
259
+ var formatter = DEFAULT_FORMATTER;
260
+ var CONSOLE_PROCESSOR = (config, entry) => {
261
+ const { level, message, meta, error } = entry;
262
+ if (!shouldLog(entry, config.filters)) {
263
+ return;
264
+ }
265
+ const parts = {
266
+ level,
267
+ message,
268
+ error,
269
+ path: void 0,
270
+ line: void 0,
271
+ scope: void 0,
272
+ context: void 0
273
+ };
274
+ if (meta) {
275
+ parts.path = getRelativeFilename(meta.F);
276
+ parts.line = meta.L;
277
+ parts.scope = meta.S;
278
+ }
279
+ const context = getContextFromEntry(entry);
280
+ if (context) {
281
+ parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
282
+ depth: config.options.depth,
283
+ colors: true,
284
+ maxArrayLength: 8,
285
+ sorted: false
286
+ });
287
+ }
288
+ const line = formatter(config, parts).filter(Boolean).join(" ");
289
+ console.log(line);
290
+ };
291
+
292
+ // packages/common/log/src/processors/debug-processor.ts
293
+ import { inspect as inspect3 } from "node:util";
294
+ var DEBUG_PROCESSOR = (config, entry) => {
295
+ console.log(inspect3(entry, false, null, true));
296
+ };
297
+
298
+ // packages/common/log/src/processors/browser-processor.ts
299
+ import { getDebugName, safariCheck } from "@dxos/util";
300
+ var getRelativeFilename2 = (filename) => {
301
+ const match = filename.match(/.+\/(packages\/.+\/.+)/);
302
+ if (match) {
303
+ const [, filePath] = match;
304
+ return filePath;
305
+ }
306
+ return filename;
307
+ };
308
+ var CONFIG = {
309
+ useTestProcessor: false,
310
+ printFileLinks: false
311
+ };
312
+ var APP_BROWSER_PROCESSOR = (config, entry) => {
313
+ if (!shouldLog(entry, config.filters)) {
314
+ return;
315
+ }
316
+ const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
317
+ const LOG_BROWSER_CSS = [];
318
+ let link = "";
319
+ if (entry.meta) {
320
+ const filename = getRelativeFilename2(entry.meta.F);
321
+ const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
322
+ link = `${filepath}#L${entry.meta.L}`;
323
+ }
324
+ let args = [];
325
+ if (entry.meta?.S) {
326
+ const scope = entry.meta?.S;
327
+ const scopeName = scope.name || getDebugName(scope);
328
+ const processPrefix = entry.meta.S?.hostSessionId ? "[worker] " : "";
329
+ args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
330
+ }
331
+ args.push(entry.message);
332
+ const context = getContextFromEntry(entry);
333
+ if (context) {
334
+ args.push(context);
335
+ }
336
+ const levels2 = {
337
+ [LogLevel.ERROR]: console.error.bind(console),
338
+ [LogLevel.WARN]: console.warn.bind(console),
339
+ [LogLevel.DEBUG]: console.log.bind(console)
340
+ };
341
+ if (CONFIG.printFileLinks || safariCheck()) {
342
+ if (LOG_BROWSER_CSS?.length) {
343
+ args = [
344
+ `%c${link}
345
+ %c${args.join(" ")}`,
346
+ ...LOG_BROWSER_CSS
347
+ ];
348
+ } else {
349
+ args = [
350
+ link + "\n",
351
+ ...args
352
+ ];
353
+ }
354
+ }
355
+ const level = levels2[entry.level] ?? console.log.bind(console);
356
+ if (typeof entry.meta?.C === "function") {
357
+ entry.meta.C(level, args);
358
+ } else {
359
+ level(...args);
360
+ }
361
+ };
362
+ var TEST_BROWSER_PROCESSOR = (config, entry) => {
363
+ if (!shouldLog(entry, config.filters)) {
364
+ return;
365
+ }
366
+ let path = "";
367
+ if (entry.meta) {
368
+ path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
369
+ }
370
+ let args = [];
371
+ const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
372
+ args.push(`${processPrefix}${entry.message}`);
373
+ const context = getContextFromEntry(entry);
374
+ if (context) {
375
+ args.push(context);
376
+ }
377
+ const levels2 = {
378
+ [LogLevel.ERROR]: console.error,
379
+ [LogLevel.WARN]: console.warn,
380
+ [LogLevel.DEBUG]: console.log
381
+ };
382
+ if (CONFIG.printFileLinks) {
383
+ args = [
384
+ path,
385
+ ...args
386
+ ];
387
+ }
388
+ const level = levels2[entry.level] ?? console.log;
389
+ if (typeof entry.meta?.C === "function") {
390
+ entry.meta.C(level, args);
391
+ } else {
392
+ level(...args);
393
+ }
394
+ };
395
+ var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
396
+
397
+ // packages/common/log/src/processors/file-processor.ts
398
+ import { appendFileSync, mkdirSync, openSync } from "node:fs";
399
+ import { dirname } from "node:path";
400
+ import { jsonlogify } from "@dxos/util";
401
+ var EAGAIN_MAX_DURATION = 1e3;
402
+ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
403
+ let fd;
404
+ return (config, entry) => {
405
+ if (levels2.length > 0 && !levels2.includes(entry.level)) {
406
+ return;
407
+ }
408
+ if (!shouldLog(entry, filters)) {
409
+ return;
410
+ }
411
+ if (typeof pathOrFd === "number") {
412
+ fd = pathOrFd;
413
+ } else {
414
+ try {
415
+ mkdirSync(dirname(pathOrFd));
416
+ } catch {
417
+ }
418
+ fd = openSync(pathOrFd, "a");
419
+ }
420
+ const record = {
421
+ ...entry,
422
+ timestamp: Date.now(),
423
+ ...entry.meta ? {
424
+ meta: {
425
+ file: getRelativeFilename(entry.meta.F),
426
+ line: entry.meta.L
427
+ }
428
+ } : {},
429
+ context: jsonlogify(getContextFromEntry(entry))
430
+ };
431
+ let retryTS = 0;
432
+ while (true) {
433
+ try {
434
+ return appendFileSync(fd, JSON.stringify(record) + "\n");
435
+ } catch (err) {
436
+ if (err.code !== "EAGAIN") {
437
+ throw err;
438
+ }
439
+ if (retryTS === 0) {
440
+ retryTS = performance.now();
441
+ } else {
442
+ if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
443
+ console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
444
+ throw err;
445
+ }
446
+ }
447
+ }
448
+ }
449
+ };
450
+ };
451
+ var logFilePath;
452
+ var getLogFilePath = () => {
453
+ logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
454
+ return logFilePath;
455
+ };
456
+ var FILE_PROCESSOR = createFileProcessor({
457
+ pathOrFd: getLogFilePath(),
458
+ levels: [
459
+ LogLevel.ERROR,
460
+ LogLevel.WARN,
461
+ LogLevel.INFO,
462
+ LogLevel.TRACE
463
+ ]
464
+ });
465
+
466
+ // packages/common/log/src/options.ts
467
+ var processors = {
468
+ [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
469
+ [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
470
+ [LogProcessorType.DEBUG]: DEBUG_PROCESSOR
471
+ };
472
+ var IS_BROWSER = typeof window !== "undefined" || typeof navigator !== "undefined";
473
+ var DEFAULT_PROCESSORS = [
474
+ IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
475
+ ];
476
+ var parseFilter = (filter) => {
477
+ if (typeof filter === "number") {
478
+ return [
479
+ {
480
+ level: filter
481
+ }
482
+ ];
483
+ }
484
+ const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
485
+ const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
486
+ return lines.map((filter2) => {
487
+ const [pattern, level] = filter2.split(":");
488
+ return level ? {
489
+ level: parseLogLevel(level),
490
+ pattern
491
+ } : {
492
+ level: parseLogLevel(pattern)
493
+ };
494
+ });
495
+ };
496
+ var getConfig = (options) => {
497
+ const nodeOptions = "process" in globalThis ? {
498
+ file: process.env.LOG_CONFIG,
499
+ filter: process.env.LOG_FILTER,
500
+ processor: process.env.LOG_PROCESSOR
501
+ } : void 0;
502
+ const mergedOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);
503
+ return {
504
+ options: mergedOptions,
505
+ filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
506
+ captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
507
+ processors: mergedOptions.processor ? [
508
+ processors[mergedOptions.processor]
509
+ ] : DEFAULT_PROCESSORS,
510
+ prefix: mergedOptions.prefix
511
+ };
512
+ };
513
+
514
+ // packages/common/log/src/log.ts
515
+ var createLog = () => {
516
+ const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
517
+ log2._config = getConfig();
518
+ Object.defineProperty(log2, "runtimeConfig", {
519
+ get: () => log2._config
520
+ });
521
+ log2.addProcessor = (processor) => {
522
+ if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
523
+ DEFAULT_PROCESSORS.push(processor);
524
+ }
525
+ if (log2._config.processors.filter((p) => p === processor).length === 0) {
526
+ log2._config.processors.push(processor);
527
+ }
528
+ };
529
+ log2.config = (options) => {
530
+ log2._config = getConfig(options);
531
+ };
532
+ log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
533
+ log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
534
+ log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
535
+ log2.info = (...params) => processLog(LogLevel.INFO, ...params);
536
+ log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
537
+ log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
538
+ log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);
539
+ 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");
540
+ log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
541
+ ${getFormattedStackTrace()}`, context, meta);
542
+ log2.method = createMethodLogDecorator(log2);
543
+ const processLog = (level, message, context = {}, meta, error) => {
544
+ log2._config.processors.forEach((processor) => processor(log2._config, {
545
+ level,
546
+ message,
547
+ context,
548
+ meta,
549
+ error
550
+ }));
551
+ };
552
+ return log2;
553
+ };
554
+ var log = globalThis.dx_log ??= createLog();
555
+ var start = Date.now();
556
+ var last = start;
557
+ var debug = (label, args) => {
558
+ const now = Date.now();
559
+ const err = new Error();
560
+ console.group(`DEBUG[${label}]`, JSON.stringify({
561
+ t: Number(now - start).toLocaleString(),
562
+ dt: Number(now - last).toLocaleString(),
563
+ ...args
564
+ }));
565
+ console.warn(err.stack);
566
+ console.groupEnd();
567
+ last = Date.now();
568
+ };
569
+ var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
570
+
571
+ // packages/common/log/src/experimental/ownership.ts
572
+ import { inspect as inspect4 } from "node:util";
573
+ var kOwnershipScope = Symbol("kOwnershipScope");
574
+ var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
575
+ var kDebugInfoProperties = Symbol("kDebugInfoProperties");
576
+ var OwnershipScope = class {
577
+ constructor(constr, parent) {
578
+ this.constr = constr;
579
+ this.parent = parent;
580
+ }
581
+ getInfo() {
582
+ if (!this.instance) {
583
+ return {};
584
+ }
585
+ const props = this.constr.prototype[kDebugInfoProperties] ?? [];
586
+ const info = {};
587
+ for (const prop of props) {
588
+ info[prop] = this.instance[prop];
589
+ }
590
+ return info;
591
+ }
592
+ [inspect4.custom]() {
593
+ return {
594
+ className: this.constr.name,
595
+ info: this.getInfo(),
596
+ parent: this.parent
597
+ };
598
+ }
599
+ };
600
+ var getCurrentOwnershipScope = (thisRef) => thisRef;
601
+ export {
602
+ BROWSER_PROCESSOR,
603
+ CONSOLE_PROCESSOR,
604
+ DEBUG_PROCESSOR,
605
+ DEFAULT_FORMATTER,
606
+ FILE_PROCESSOR,
607
+ LogLevel,
608
+ LogProcessorType,
609
+ SHORT_FORMATTER,
610
+ createFileProcessor,
611
+ debug,
612
+ gatherLogInfoFromScope,
613
+ getContextFromEntry,
614
+ getCurrentOwnershipScope,
615
+ getRelativeFilename,
616
+ levels,
617
+ log,
618
+ logInfo,
619
+ omit,
620
+ parseFilter,
621
+ pick,
622
+ shortLevelName,
623
+ shouldLog,
624
+ truncate
625
+ };
626
+ //# sourceMappingURL=index.mjs.map