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