@dxos/log 0.8.4-main.fffef41 → 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.
- package/dist/lib/browser/chunk-DTUPLFUN.mjs +311 -0
- package/dist/lib/browser/chunk-DTUPLFUN.mjs.map +7 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +187 -199
- 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 +102 -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-KOTHKRYW.mjs +313 -0
- package/dist/lib/node-esm/chunk-KOTHKRYW.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +189 -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 +103 -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/context.d.ts +78 -2
- 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.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 +40 -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 +3 -1
- package/dist/types/src/log.d.ts.map +1 -1
- 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 +30 -12
- package/src/context.ts +242 -2
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +1 -2
- package/src/experimental/classes.test.ts +0 -1
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +158 -0
- package/src/log-buffer.ts +110 -0
- package/src/log.test.ts +0 -1
- package/src/log.ts +7 -12
- package/src/options.ts +3 -1
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +1 -2
- package/src/processors/browser-processor.ts +27 -28
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +7 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,121 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
trace: 5,
|
|
18
|
-
debug: 10,
|
|
19
|
-
verbose: 11,
|
|
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 = /* @__PURE__ */ (function(LogProcessorType2) {
|
|
33
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
34
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
35
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
36
|
-
return LogProcessorType2;
|
|
37
|
-
})({});
|
|
38
|
-
|
|
39
|
-
// 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 = (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
|
+
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";
|
|
60
17
|
|
|
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
|
-
|
|
89
|
-
let context;
|
|
90
|
-
if (entry.meta) {
|
|
91
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
92
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
93
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
97
|
-
if (entryContext) {
|
|
98
|
-
if (entryContext instanceof Error) {
|
|
99
|
-
const c = entryContext.context;
|
|
100
|
-
context = Object.assign(context ?? {}, {
|
|
101
|
-
error: entryContext.stack,
|
|
102
|
-
...c
|
|
103
|
-
});
|
|
104
|
-
} else if (typeof entryContext === "object") {
|
|
105
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (entry.error) {
|
|
109
|
-
context = Object.assign(context ?? {}, {
|
|
110
|
-
error: entry.error
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
114
|
-
};
|
|
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";
|
|
115
46
|
|
|
116
47
|
// src/decorators.ts
|
|
117
|
-
import { inspect } from "@dxos/node-std/util";
|
|
118
48
|
import chalk from "chalk";
|
|
49
|
+
import { inspect } from "@dxos/node-std/util";
|
|
119
50
|
var nextPromiseId = 0;
|
|
120
51
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
121
52
|
const method = descriptor.value;
|
|
@@ -225,47 +156,23 @@ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
|
225
156
|
// src/options.ts
|
|
226
157
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
227
158
|
|
|
228
|
-
// src/platform/
|
|
229
|
-
var
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (typeof localStorage === "undefined") {
|
|
233
|
-
if (globalThis.localStorage_dxlog) {
|
|
234
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
238
|
-
}
|
|
239
|
-
if (!dxlog) {
|
|
240
|
-
return void 0;
|
|
241
|
-
}
|
|
242
|
-
return JSON.parse(dxlog);
|
|
243
|
-
} catch (err) {
|
|
244
|
-
console.info("can't parse dxlog config", err);
|
|
245
|
-
return void 0;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// src/processors/console-stub.ts
|
|
250
|
-
var CONSOLE_PROCESSOR = () => {
|
|
251
|
-
};
|
|
159
|
+
// src/platform/index.ts
|
|
160
|
+
var platform_exports = {};
|
|
161
|
+
__reExport(platform_exports, platform_star);
|
|
162
|
+
import * as platform_star from "#platform";
|
|
252
163
|
|
|
253
|
-
// src/processors/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
+
});
|
|
258
173
|
|
|
259
174
|
// src/processors/browser-processor.ts
|
|
260
|
-
import {
|
|
261
|
-
var getRelativeFilename = (filename) => {
|
|
262
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
263
|
-
if (match) {
|
|
264
|
-
const [, filePath] = match;
|
|
265
|
-
return filePath;
|
|
266
|
-
}
|
|
267
|
-
return filename;
|
|
268
|
-
};
|
|
175
|
+
import { safariCheck } from "@dxos/util";
|
|
269
176
|
var CONFIG = {
|
|
270
177
|
useTestProcessor: false,
|
|
271
178
|
printFileLinks: false
|
|
@@ -276,18 +183,20 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
276
183
|
}
|
|
277
184
|
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
278
185
|
const LOG_BROWSER_CSS = [];
|
|
186
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
279
187
|
let link = "";
|
|
280
|
-
if (
|
|
281
|
-
const filename = getRelativeFilename(entry.meta.F);
|
|
188
|
+
if (filename !== void 0 && lineNumber !== void 0) {
|
|
282
189
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
283
|
-
link = `${filepath}#L${
|
|
190
|
+
link = `${filepath}#L${lineNumber}`;
|
|
284
191
|
}
|
|
285
192
|
let args = [];
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const scopeName = scope.name ||
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
}
|
|
291
200
|
}
|
|
292
201
|
if (entry.message) {
|
|
293
202
|
args.push(entry.message);
|
|
@@ -295,9 +204,9 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
295
204
|
const context = getContextFromEntry(entry);
|
|
296
205
|
if (context) {
|
|
297
206
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
298
|
-
args.push(context.error);
|
|
207
|
+
args.push(unwrapEffectError(context.error));
|
|
299
208
|
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
300
|
-
args.push(context.err);
|
|
209
|
+
args.push(unwrapEffectError(context.err));
|
|
301
210
|
} else {
|
|
302
211
|
args.push(context);
|
|
303
212
|
}
|
|
@@ -332,10 +241,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
332
241
|
if (!shouldLog(entry, config.filters)) {
|
|
333
242
|
return;
|
|
334
243
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;
|
|
338
|
-
}
|
|
244
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
245
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
339
246
|
let args = [];
|
|
340
247
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
341
248
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -362,23 +269,27 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
362
269
|
}
|
|
363
270
|
};
|
|
364
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
|
+
};
|
|
365
279
|
|
|
366
|
-
// src/processors/
|
|
367
|
-
|
|
368
|
-
import
|
|
369
|
-
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";
|
|
370
283
|
|
|
371
|
-
// src/processors/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const [, filePath] = match;
|
|
376
|
-
return filePath;
|
|
377
|
-
}
|
|
378
|
-
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));
|
|
379
288
|
};
|
|
380
289
|
|
|
381
290
|
// src/processors/file-processor.ts
|
|
291
|
+
import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
|
|
292
|
+
import { dirname } from "@dxos/node-std/path";
|
|
382
293
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
383
294
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
384
295
|
let fd;
|
|
@@ -399,15 +310,12 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
399
310
|
fd = openSync(pathOrFd, "a");
|
|
400
311
|
}
|
|
401
312
|
const record = {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
} : {},
|
|
410
|
-
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
|
|
411
319
|
};
|
|
412
320
|
let retryTS = 0;
|
|
413
321
|
while (true) {
|
|
@@ -446,13 +354,13 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
446
354
|
|
|
447
355
|
// src/options.ts
|
|
448
356
|
var processors = {
|
|
449
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
357
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
450
358
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
451
359
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
452
360
|
};
|
|
453
|
-
var browser = typeof window !== "undefined" || typeof navigator !== "undefined";
|
|
361
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
454
362
|
var DEFAULT_PROCESSORS = [
|
|
455
|
-
browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
|
|
363
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
456
364
|
];
|
|
457
365
|
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
458
366
|
var parseFilter = (filter) => {
|
|
@@ -480,7 +388,7 @@ var createConfig = (options) => {
|
|
|
480
388
|
filter: process.env.LOG_FILTER,
|
|
481
389
|
processor: process.env.LOG_PROCESSOR
|
|
482
390
|
} : void 0;
|
|
483
|
-
const mergedOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
|
|
391
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
484
392
|
return {
|
|
485
393
|
options: mergedOptions,
|
|
486
394
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
@@ -506,13 +414,14 @@ var createLog = () => {
|
|
|
506
414
|
get: () => log2._config
|
|
507
415
|
});
|
|
508
416
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
509
|
-
|
|
417
|
+
const entry = new LogEntry({
|
|
510
418
|
level,
|
|
511
419
|
message,
|
|
512
420
|
context,
|
|
513
421
|
meta,
|
|
514
422
|
error
|
|
515
|
-
})
|
|
423
|
+
});
|
|
424
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
516
425
|
};
|
|
517
426
|
Object.assign(log2, {
|
|
518
427
|
/**
|
|
@@ -520,7 +429,7 @@ var createLog = () => {
|
|
|
520
429
|
* NOTE: Preserves any processors that were already added to this logger instance
|
|
521
430
|
* unless an explicit processor option is provided.
|
|
522
431
|
*/
|
|
523
|
-
config: ({ processor, ...options }) => {
|
|
432
|
+
config: ({ processor, ...options } = {}) => {
|
|
524
433
|
const config = createConfig(options);
|
|
525
434
|
const processors2 = processor ? config.processors : log2._config.processors;
|
|
526
435
|
log2._config = {
|
|
@@ -574,11 +483,88 @@ var debug = (label, args) => {
|
|
|
574
483
|
};
|
|
575
484
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
576
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
|
+
|
|
577
565
|
// src/experimental/ownership.ts
|
|
578
566
|
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
579
|
-
var
|
|
580
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
581
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
567
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
582
568
|
var OwnershipScope = class {
|
|
583
569
|
constr;
|
|
584
570
|
parent;
|
|
@@ -609,18 +595,20 @@ var OwnershipScope = class {
|
|
|
609
595
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
610
596
|
export {
|
|
611
597
|
BROWSER_PROCESSOR,
|
|
612
|
-
CONSOLE_PROCESSOR,
|
|
613
598
|
DEBUG_PROCESSOR,
|
|
614
599
|
FILE_PROCESSOR,
|
|
600
|
+
LogBuffer,
|
|
601
|
+
LogEntry,
|
|
615
602
|
LogLevel,
|
|
616
603
|
LogProcessorType,
|
|
617
604
|
createFileProcessor,
|
|
618
605
|
createLog,
|
|
606
|
+
dbg,
|
|
619
607
|
debug,
|
|
620
608
|
gatherLogInfoFromScope,
|
|
621
609
|
getContextFromEntry,
|
|
622
610
|
getCurrentOwnershipScope,
|
|
623
|
-
|
|
611
|
+
getRelativeFilename,
|
|
624
612
|
levels,
|
|
625
613
|
log,
|
|
626
614
|
logInfo,
|