@dxos/log 0.8.4-main.e99c46d → 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 +153 -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 +148 -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/browser-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 +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/browser-processor.ts +2 -0
- 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
|
}
|
|
@@ -280,6 +209,8 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
280
209
|
if (context) {
|
|
281
210
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
282
211
|
args.push(context.error);
|
|
212
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
213
|
+
args.push(context.err);
|
|
283
214
|
} else {
|
|
284
215
|
args.push(context);
|
|
285
216
|
}
|
|
@@ -316,7 +247,7 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
316
247
|
}
|
|
317
248
|
let path = "";
|
|
318
249
|
if (entry.meta) {
|
|
319
|
-
path = `${
|
|
250
|
+
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
320
251
|
}
|
|
321
252
|
let args = [];
|
|
322
253
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
@@ -345,22 +276,20 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
345
276
|
};
|
|
346
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
347
278
|
|
|
348
|
-
// src/processors/
|
|
349
|
-
|
|
350
|
-
import
|
|
351
|
-
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";
|
|
352
282
|
|
|
353
|
-
// src/processors/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const [, filePath] = match;
|
|
358
|
-
return filePath;
|
|
359
|
-
}
|
|
360
|
-
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));
|
|
361
287
|
};
|
|
362
288
|
|
|
363
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";
|
|
364
293
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
365
294
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
366
295
|
let fd;
|
|
@@ -385,7 +314,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
385
314
|
timestamp: Date.now(),
|
|
386
315
|
...entry.meta ? {
|
|
387
316
|
meta: {
|
|
388
|
-
file:
|
|
317
|
+
file: getRelativeFilename(entry.meta.F),
|
|
389
318
|
line: entry.meta.L
|
|
390
319
|
}
|
|
391
320
|
} : {},
|
|
@@ -413,7 +342,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
413
342
|
};
|
|
414
343
|
var logFilePath;
|
|
415
344
|
var getLogFilePath = () => {
|
|
416
|
-
logFilePath
|
|
345
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
417
346
|
return logFilePath;
|
|
418
347
|
};
|
|
419
348
|
var FILE_PROCESSOR = createFileProcessor({
|
|
@@ -428,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
428
357
|
|
|
429
358
|
// src/options.ts
|
|
430
359
|
var processors = {
|
|
431
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
432
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
433
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
434
363
|
};
|
|
435
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
436
365
|
var DEFAULT_PROCESSORS = [
|
|
437
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
438
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
439
369
|
var parseFilter = (filter) => {
|
|
440
370
|
if (typeof filter === "number") {
|
|
441
371
|
return [
|
|
@@ -444,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
444
374
|
}
|
|
445
375
|
];
|
|
446
376
|
}
|
|
447
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
448
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
449
378
|
return lines.map((filter2) => {
|
|
450
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -456,55 +385,37 @@ var parseFilter = (filter) => {
|
|
|
456
385
|
};
|
|
457
386
|
});
|
|
458
387
|
};
|
|
459
|
-
var
|
|
460
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
461
390
|
file: process.env.LOG_CONFIG,
|
|
462
391
|
filter: process.env.LOG_FILTER,
|
|
463
392
|
processor: process.env.LOG_PROCESSOR
|
|
464
393
|
} : void 0;
|
|
465
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
466
395
|
return {
|
|
467
396
|
options: mergedOptions,
|
|
468
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
469
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
470
399
|
processors: mergedOptions.processor ? [
|
|
471
400
|
processors[mergedOptions.processor]
|
|
472
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
473
404
|
prefix: mergedOptions.prefix
|
|
474
405
|
};
|
|
475
406
|
};
|
|
476
407
|
|
|
477
408
|
// src/log.ts
|
|
478
|
-
var
|
|
409
|
+
var logCount = 0;
|
|
479
410
|
var createLog = () => {
|
|
480
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
481
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
482
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
483
417
|
get: () => log2._config
|
|
484
418
|
});
|
|
485
|
-
log2.addProcessor = (processor) => {
|
|
486
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
487
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
488
|
-
}
|
|
489
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
490
|
-
log2._config.processors.push(processor);
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
log2.config = (options) => {
|
|
494
|
-
log2._config = getConfig(options);
|
|
495
|
-
};
|
|
496
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
497
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
498
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
499
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
500
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
501
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
502
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
503
|
-
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");
|
|
504
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
505
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
506
|
-
log2.method = createMethodLogDecorator(log2);
|
|
507
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
508
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
509
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
510
421
|
level,
|
|
@@ -514,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
514
425
|
error
|
|
515
426
|
}));
|
|
516
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
|
+
});
|
|
517
469
|
return log2;
|
|
518
470
|
};
|
|
519
|
-
var log =
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
520
472
|
var start = Date.now();
|
|
521
473
|
var last = start;
|
|
522
474
|
var debug = (label, args) => {
|
|
@@ -533,26 +485,32 @@ var debug = (label, args) => {
|
|
|
533
485
|
};
|
|
534
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
535
487
|
|
|
536
|
-
// src/
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
configurable: true,
|
|
544
|
-
writable: true
|
|
545
|
-
});
|
|
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);
|
|
546
495
|
} else {
|
|
547
|
-
|
|
496
|
+
console.log(arg);
|
|
548
497
|
}
|
|
549
|
-
return
|
|
550
|
-
}
|
|
498
|
+
return arg;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/experimental/ownership.ts
|
|
502
|
+
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
551
503
|
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
552
504
|
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
553
505
|
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
554
|
-
var _inspect_custom = inspect3.custom;
|
|
555
506
|
var OwnershipScope = class {
|
|
507
|
+
constr;
|
|
508
|
+
parent;
|
|
509
|
+
instance;
|
|
510
|
+
constructor(constr, parent) {
|
|
511
|
+
this.constr = constr;
|
|
512
|
+
this.parent = parent;
|
|
513
|
+
}
|
|
556
514
|
getInfo() {
|
|
557
515
|
if (!this.instance) {
|
|
558
516
|
return {};
|
|
@@ -564,35 +522,29 @@ var OwnershipScope = class {
|
|
|
564
522
|
}
|
|
565
523
|
return info;
|
|
566
524
|
}
|
|
567
|
-
[
|
|
525
|
+
[inspect3.custom]() {
|
|
568
526
|
return {
|
|
569
527
|
className: this.constr.name,
|
|
570
528
|
info: this.getInfo(),
|
|
571
529
|
parent: this.parent
|
|
572
530
|
};
|
|
573
531
|
}
|
|
574
|
-
constructor(constr, parent) {
|
|
575
|
-
_define_property(this, "constr", void 0);
|
|
576
|
-
_define_property(this, "parent", void 0);
|
|
577
|
-
_define_property(this, "instance", void 0);
|
|
578
|
-
this.constr = constr;
|
|
579
|
-
this.parent = parent;
|
|
580
|
-
}
|
|
581
532
|
};
|
|
582
533
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
583
534
|
export {
|
|
584
535
|
BROWSER_PROCESSOR,
|
|
585
|
-
CONSOLE_PROCESSOR,
|
|
586
536
|
DEBUG_PROCESSOR,
|
|
587
537
|
FILE_PROCESSOR,
|
|
588
538
|
LogLevel,
|
|
589
539
|
LogProcessorType,
|
|
590
540
|
createFileProcessor,
|
|
541
|
+
createLog,
|
|
542
|
+
dbg,
|
|
591
543
|
debug,
|
|
592
544
|
gatherLogInfoFromScope,
|
|
593
545
|
getContextFromEntry,
|
|
594
546
|
getCurrentOwnershipScope,
|
|
595
|
-
|
|
547
|
+
getRelativeFilename,
|
|
596
548
|
levels,
|
|
597
549
|
log,
|
|
598
550
|
logInfo,
|