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