@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.
- 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 +243 -211
- 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 +245 -300
- 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/config.d.ts +2 -3
- package/dist/types/src/config.d.ts.map +1 -1
- 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 +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 +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 +14 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/platform/node/index.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -12
- package/src/config.ts +3 -2
- package/src/context.ts +278 -7
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +4 -5
- 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 +48 -19
- package/src/log.ts +97 -58
- package/src/options.ts +26 -10
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +1 -2
- package/src/processors/browser-processor.ts +28 -27
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +9 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,104 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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/
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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/
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (typeof localStorage === "undefined") {
|
|
216
|
-
if (globalThis.localStorage_dxlog) {
|
|
217
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
221
|
-
}
|
|
222
|
-
if (!dxlog) {
|
|
223
|
-
return void 0;
|
|
224
|
-
}
|
|
225
|
-
return JSON.parse(dxlog);
|
|
226
|
-
} catch (err) {
|
|
227
|
-
console.info("can't parse dxlog config", err);
|
|
228
|
-
return void 0;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
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/
|
|
233
|
-
var
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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 {
|
|
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 (
|
|
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${
|
|
190
|
+
link = `${filepath}#L${lineNumber}`;
|
|
267
191
|
}
|
|
268
192
|
let args = [];
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const scopeName = scope.name ||
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
317
|
-
|
|
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/
|
|
348
|
-
|
|
349
|
-
import
|
|
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/
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
|
361
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
435
362
|
var DEFAULT_PROCESSORS = [
|
|
436
|
-
|
|
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
|
|
459
|
-
const
|
|
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(
|
|
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
|
-
] :
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
611
|
+
getRelativeFilename,
|
|
580
612
|
levels,
|
|
581
613
|
log,
|
|
582
614
|
logInfo,
|