@dxos/log 0.8.4-main.fd6878d → 0.8.4-staging.ac66bdf99f

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