@dxos/log 0.8.4-main.ead640a → 0.8.4-main.ef1bc66f44
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-GPOFUMLO.mjs +133 -0
- package/dist/lib/browser/chunk-GPOFUMLO.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 +151 -201
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/platform/browser/index.mjs +26 -0
- package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
- package/dist/lib/browser/platform/node/index.mjs +21 -0
- package/dist/lib/browser/platform/node/index.mjs.map +7 -0
- package/dist/lib/browser/processors/console-processor.mjs +107 -0
- package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
- package/dist/lib/browser/processors/console-stub.mjs +9 -0
- package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs +135 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +146 -283
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
- package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
- package/dist/lib/node-esm/platform/node/index.mjs +22 -0
- package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-processor.mjs +108 -0
- package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
- package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/dbg.d.ts +23 -0
- package/dist/types/src/dbg.d.ts.map +1 -0
- package/dist/types/src/decorators.d.ts +1 -1
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log.d.ts +12 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -9
- package/src/config.ts +1 -0
- package/src/context.ts +36 -5
- package/src/dbg.ts +35 -0
- package/src/decorators.ts +3 -3
- package/src/index.ts +1 -0
- package/src/log.test.ts +48 -18
- package/src/log.ts +101 -57
- package/src/options.ts +26 -10
- package/src/platform/index.ts +1 -1
- package/src/processors/file-processor.ts +2 -0
- package/src/processors/index.ts +3 -3
|
@@ -1,102 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LogLevel,
|
|
3
|
+
LogProcessorType,
|
|
4
|
+
gatherLogInfoFromScope,
|
|
5
|
+
getContextFromEntry,
|
|
6
|
+
getRelativeFilename,
|
|
7
|
+
levels,
|
|
8
|
+
logInfo,
|
|
9
|
+
shortLevelName,
|
|
10
|
+
shouldLog
|
|
11
|
+
} from "./chunk-GPOFUMLO.mjs";
|
|
12
|
+
import {
|
|
13
|
+
__export,
|
|
14
|
+
__reExport
|
|
15
|
+
} from "./chunk-IEP6GGEX.mjs";
|
|
16
|
+
|
|
1
17
|
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
__export(index_exports, {
|
|
20
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
21
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
22
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
23
|
+
LogLevel: () => LogLevel,
|
|
24
|
+
LogProcessorType: () => LogProcessorType,
|
|
25
|
+
createFileProcessor: () => createFileProcessor,
|
|
26
|
+
createLog: () => createLog,
|
|
27
|
+
dbg: () => dbg,
|
|
28
|
+
debug: () => debug,
|
|
29
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
30
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
31
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
32
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
33
|
+
levels: () => levels,
|
|
34
|
+
log: () => log,
|
|
35
|
+
logInfo: () => logInfo,
|
|
36
|
+
omit: () => omit,
|
|
37
|
+
parseFilter: () => parseFilter,
|
|
38
|
+
pick: () => pick,
|
|
39
|
+
shortLevelName: () => shortLevelName,
|
|
40
|
+
shouldLog: () => shouldLog
|
|
41
|
+
});
|
|
2
42
|
import omit from "lodash.omit";
|
|
3
43
|
import { pick } from "@dxos/util";
|
|
4
44
|
|
|
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
|
-
var _target, _logInfoProperties;
|
|
42
|
-
((_target = target)[_logInfoProperties = logInfoProperties] ?? (_target[_logInfoProperties] = [])).push(propertyKey);
|
|
43
|
-
};
|
|
44
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
45
|
-
if (!scope) {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
const res = {};
|
|
49
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
50
|
-
const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
|
|
51
|
-
for (const prop of infoProps) {
|
|
52
|
-
try {
|
|
53
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
54
|
-
} catch (err) {
|
|
55
|
-
res[prop] = err.message;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return res;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// 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
|
-
context = Object.assign(context ?? {}, {
|
|
94
|
-
error: entry.error
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
45
|
// src/decorators.ts
|
|
101
46
|
import { inspect } from "@dxos/node-std/util";
|
|
102
47
|
import chalk from "chalk";
|
|
@@ -196,53 +141,37 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
196
141
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
197
142
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
198
143
|
};
|
|
199
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
200
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
201
144
|
var COLOR_FUNCTION = [
|
|
202
145
|
220,
|
|
203
146
|
220,
|
|
204
147
|
170
|
|
205
148
|
];
|
|
149
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
150
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
206
151
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
207
152
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
208
153
|
|
|
209
154
|
// src/options.ts
|
|
210
155
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
211
156
|
|
|
212
|
-
// src/platform/
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (typeof localStorage === "undefined") {
|
|
217
|
-
if (globalThis.localStorage_dxlog) {
|
|
218
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
222
|
-
}
|
|
223
|
-
if (!dxlog) {
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
return JSON.parse(dxlog);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.info("can't parse dxlog config", err);
|
|
229
|
-
return void 0;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/processors/console-stub.ts
|
|
234
|
-
var CONSOLE_PROCESSOR = () => {
|
|
235
|
-
};
|
|
157
|
+
// src/platform/index.ts
|
|
158
|
+
var platform_exports = {};
|
|
159
|
+
__reExport(platform_exports, platform_star);
|
|
160
|
+
import * as platform_star from "#platform";
|
|
236
161
|
|
|
237
|
-
// src/processors/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
162
|
+
// src/processors/index.ts
|
|
163
|
+
var processors_exports = {};
|
|
164
|
+
__export(processors_exports, {
|
|
165
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
166
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
167
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
168
|
+
createFileProcessor: () => createFileProcessor,
|
|
169
|
+
getRelativeFilename: () => getRelativeFilename
|
|
170
|
+
});
|
|
242
171
|
|
|
243
172
|
// src/processors/browser-processor.ts
|
|
244
173
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
245
|
-
var
|
|
174
|
+
var getRelativeFilename2 = (filename) => {
|
|
246
175
|
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
247
176
|
if (match) {
|
|
248
177
|
const [, filePath] = match;
|
|
@@ -262,7 +191,7 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
262
191
|
const LOG_BROWSER_CSS = [];
|
|
263
192
|
let link = "";
|
|
264
193
|
if (entry.meta) {
|
|
265
|
-
const filename =
|
|
194
|
+
const filename = getRelativeFilename2(entry.meta.F);
|
|
266
195
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
267
196
|
link = `${filepath}#L${entry.meta.L}`;
|
|
268
197
|
}
|
|
@@ -318,7 +247,7 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
318
247
|
}
|
|
319
248
|
let path = "";
|
|
320
249
|
if (entry.meta) {
|
|
321
|
-
path = `${
|
|
250
|
+
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
322
251
|
}
|
|
323
252
|
let args = [];
|
|
324
253
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
@@ -347,22 +276,20 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
347
276
|
};
|
|
348
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
349
278
|
|
|
350
|
-
// src/processors/
|
|
351
|
-
|
|
352
|
-
import
|
|
353
|
-
import { jsonlogify } from "@dxos/util";
|
|
279
|
+
// src/processors/index.ts
|
|
280
|
+
__reExport(processors_exports, console_processor_star);
|
|
281
|
+
import * as console_processor_star from "#console-processor";
|
|
354
282
|
|
|
355
|
-
// src/processors/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const [, filePath] = match;
|
|
360
|
-
return filePath;
|
|
361
|
-
}
|
|
362
|
-
return filename;
|
|
283
|
+
// src/processors/debug-processor.ts
|
|
284
|
+
import { inspect as inspect2 } from "@dxos/node-std/util";
|
|
285
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
286
|
+
console.log(inspect2(entry, false, null, true));
|
|
363
287
|
};
|
|
364
288
|
|
|
365
289
|
// src/processors/file-processor.ts
|
|
290
|
+
import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
|
|
291
|
+
import { dirname } from "@dxos/node-std/path";
|
|
292
|
+
import { jsonlogify } from "@dxos/util";
|
|
366
293
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
367
294
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
368
295
|
let fd;
|
|
@@ -387,7 +314,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
387
314
|
timestamp: Date.now(),
|
|
388
315
|
...entry.meta ? {
|
|
389
316
|
meta: {
|
|
390
|
-
file:
|
|
317
|
+
file: getRelativeFilename(entry.meta.F),
|
|
391
318
|
line: entry.meta.L
|
|
392
319
|
}
|
|
393
320
|
} : {},
|
|
@@ -415,7 +342,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
415
342
|
};
|
|
416
343
|
var logFilePath;
|
|
417
344
|
var getLogFilePath = () => {
|
|
418
|
-
logFilePath
|
|
345
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
419
346
|
return logFilePath;
|
|
420
347
|
};
|
|
421
348
|
var FILE_PROCESSOR = createFileProcessor({
|
|
@@ -430,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
430
357
|
|
|
431
358
|
// src/options.ts
|
|
432
359
|
var processors = {
|
|
433
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
434
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
435
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
436
363
|
};
|
|
437
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
438
365
|
var DEFAULT_PROCESSORS = [
|
|
439
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
440
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
441
369
|
var parseFilter = (filter) => {
|
|
442
370
|
if (typeof filter === "number") {
|
|
443
371
|
return [
|
|
@@ -446,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
446
374
|
}
|
|
447
375
|
];
|
|
448
376
|
}
|
|
449
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
450
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
451
378
|
return lines.map((filter2) => {
|
|
452
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -458,55 +385,37 @@ var parseFilter = (filter) => {
|
|
|
458
385
|
};
|
|
459
386
|
});
|
|
460
387
|
};
|
|
461
|
-
var
|
|
462
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
463
390
|
file: process.env.LOG_CONFIG,
|
|
464
391
|
filter: process.env.LOG_FILTER,
|
|
465
392
|
processor: process.env.LOG_PROCESSOR
|
|
466
393
|
} : void 0;
|
|
467
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
468
395
|
return {
|
|
469
396
|
options: mergedOptions,
|
|
470
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
471
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
472
399
|
processors: mergedOptions.processor ? [
|
|
473
400
|
processors[mergedOptions.processor]
|
|
474
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
475
404
|
prefix: mergedOptions.prefix
|
|
476
405
|
};
|
|
477
406
|
};
|
|
478
407
|
|
|
479
408
|
// src/log.ts
|
|
480
|
-
var
|
|
409
|
+
var logCount = 0;
|
|
481
410
|
var createLog = () => {
|
|
482
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
483
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
484
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
485
417
|
get: () => log2._config
|
|
486
418
|
});
|
|
487
|
-
log2.addProcessor = (processor) => {
|
|
488
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
489
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
490
|
-
}
|
|
491
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
492
|
-
log2._config.processors.push(processor);
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
log2.config = (options) => {
|
|
496
|
-
log2._config = getConfig(options);
|
|
497
|
-
};
|
|
498
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
499
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
500
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
501
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
502
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
503
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
504
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
505
|
-
log2.break = () => log2.info("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014");
|
|
506
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
507
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
508
|
-
log2.method = createMethodLogDecorator(log2);
|
|
509
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
510
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
511
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
512
421
|
level,
|
|
@@ -516,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
516
425
|
error
|
|
517
426
|
}));
|
|
518
427
|
};
|
|
428
|
+
Object.assign(log2, {
|
|
429
|
+
/**
|
|
430
|
+
* Update config.
|
|
431
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
432
|
+
* unless an explicit processor option is provided.
|
|
433
|
+
*/
|
|
434
|
+
config: ({ processor, ...options }) => {
|
|
435
|
+
const config = createConfig(options);
|
|
436
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
437
|
+
log2._config = {
|
|
438
|
+
...config,
|
|
439
|
+
processors: processors2
|
|
440
|
+
};
|
|
441
|
+
return log2;
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
444
|
+
* Adds a processor to the logger.
|
|
445
|
+
*/
|
|
446
|
+
addProcessor: (processor) => {
|
|
447
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
448
|
+
log2._config.processors.push(processor);
|
|
449
|
+
}
|
|
450
|
+
return () => {
|
|
451
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
455
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
456
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
457
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
458
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
459
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
460
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
461
|
+
method: createMethodLogDecorator(log2),
|
|
462
|
+
function: createFunctionLogDecorator(log2),
|
|
463
|
+
break: () => log2.info("-".repeat(80)),
|
|
464
|
+
stack: (message, context, meta) => {
|
|
465
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
466
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
519
469
|
return log2;
|
|
520
470
|
};
|
|
521
|
-
var log =
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
522
472
|
var start = Date.now();
|
|
523
473
|
var last = start;
|
|
524
474
|
var debug = (label, args) => {
|
|
@@ -535,26 +485,32 @@ var debug = (label, args) => {
|
|
|
535
485
|
};
|
|
536
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
537
487
|
|
|
538
|
-
// src/
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
configurable: true,
|
|
546
|
-
writable: true
|
|
547
|
-
});
|
|
488
|
+
// src/index.ts
|
|
489
|
+
__reExport(index_exports, processors_exports);
|
|
490
|
+
|
|
491
|
+
// src/dbg.ts
|
|
492
|
+
var dbg = (arg, meta) => {
|
|
493
|
+
if (meta?.A) {
|
|
494
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
548
495
|
} else {
|
|
549
|
-
|
|
496
|
+
console.log(arg);
|
|
550
497
|
}
|
|
551
|
-
return
|
|
552
|
-
}
|
|
498
|
+
return arg;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/experimental/ownership.ts
|
|
502
|
+
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
553
503
|
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
554
504
|
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
555
505
|
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
556
|
-
var _inspect_custom = inspect3.custom;
|
|
557
506
|
var OwnershipScope = class {
|
|
507
|
+
constr;
|
|
508
|
+
parent;
|
|
509
|
+
instance;
|
|
510
|
+
constructor(constr, parent) {
|
|
511
|
+
this.constr = constr;
|
|
512
|
+
this.parent = parent;
|
|
513
|
+
}
|
|
558
514
|
getInfo() {
|
|
559
515
|
if (!this.instance) {
|
|
560
516
|
return {};
|
|
@@ -566,35 +522,29 @@ var OwnershipScope = class {
|
|
|
566
522
|
}
|
|
567
523
|
return info;
|
|
568
524
|
}
|
|
569
|
-
[
|
|
525
|
+
[inspect3.custom]() {
|
|
570
526
|
return {
|
|
571
527
|
className: this.constr.name,
|
|
572
528
|
info: this.getInfo(),
|
|
573
529
|
parent: this.parent
|
|
574
530
|
};
|
|
575
531
|
}
|
|
576
|
-
constructor(constr, parent) {
|
|
577
|
-
_define_property(this, "constr", void 0);
|
|
578
|
-
_define_property(this, "parent", void 0);
|
|
579
|
-
_define_property(this, "instance", void 0);
|
|
580
|
-
this.constr = constr;
|
|
581
|
-
this.parent = parent;
|
|
582
|
-
}
|
|
583
532
|
};
|
|
584
533
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
585
534
|
export {
|
|
586
535
|
BROWSER_PROCESSOR,
|
|
587
|
-
CONSOLE_PROCESSOR,
|
|
588
536
|
DEBUG_PROCESSOR,
|
|
589
537
|
FILE_PROCESSOR,
|
|
590
538
|
LogLevel,
|
|
591
539
|
LogProcessorType,
|
|
592
540
|
createFileProcessor,
|
|
541
|
+
createLog,
|
|
542
|
+
dbg,
|
|
593
543
|
debug,
|
|
594
544
|
gatherLogInfoFromScope,
|
|
595
545
|
getContextFromEntry,
|
|
596
546
|
getCurrentOwnershipScope,
|
|
597
|
-
|
|
547
|
+
getRelativeFilename,
|
|
598
548
|
levels,
|
|
599
549
|
log,
|
|
600
550
|
logInfo,
|