@dxos/log 0.8.4-main.c1de068 → 0.8.4-main.c85a9c8dae
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-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs +133 -0
- package/dist/lib/browser/chunk-M2YHSBML.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +218 -182
- 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-62VKC2WQ.mjs +135 -0
- package/dist/lib/node-esm/chunk-62VKC2WQ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +215 -264
- 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 +2 -3
- 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 +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log-buffer.d.ts +36 -0
- package/dist/types/src/log-buffer.d.ts.map +1 -0
- package/dist/types/src/log-buffer.test.d.ts +2 -0
- package/dist/types/src/log-buffer.test.d.ts.map +1 -0
- package/dist/types/src/log.d.ts +14 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/platform/node/index.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -14
- package/src/config.ts +3 -2
- package/src/context.ts +36 -5
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +5 -4
- package/src/experimental/classes.test.ts +2 -1
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +156 -0
- package/src/log-buffer.ts +108 -0
- package/src/log.test.ts +49 -18
- package/src/log.ts +103 -57
- package/src/options.ts +27 -11
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +2 -1
- package/src/processors/browser-processor.ts +3 -1
- package/src/processors/console-processor.ts +9 -5
- package/src/processors/file-processor.ts +4 -1
- package/src/processors/index.ts +3 -3
- package/src/scope.ts +1 -1
|
@@ -1,106 +1,51 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
LogLevel,
|
|
4
|
+
LogProcessorType,
|
|
5
|
+
gatherLogInfoFromScope,
|
|
6
|
+
getContextFromEntry,
|
|
7
|
+
getRelativeFilename,
|
|
8
|
+
levels,
|
|
9
|
+
logInfo,
|
|
10
|
+
shortLevelName,
|
|
11
|
+
shouldLog
|
|
12
|
+
} from "./chunk-62VKC2WQ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__export,
|
|
15
|
+
__reExport
|
|
16
|
+
} from "./chunk-2SZHAWBN.mjs";
|
|
2
17
|
|
|
3
18
|
// src/index.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[13]: "W",
|
|
31
|
-
[14]: "E"
|
|
32
|
-
};
|
|
33
|
-
var LogProcessorType = /* @__PURE__ */ function(LogProcessorType2) {
|
|
34
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
35
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
36
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
37
|
-
return LogProcessorType2;
|
|
38
|
-
}({});
|
|
39
|
-
|
|
40
|
-
// src/scope.ts
|
|
41
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
42
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
43
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
44
|
-
};
|
|
45
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
46
|
-
if (!scope) {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
const res = {};
|
|
50
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
51
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
52
|
-
for (const prop of infoProps) {
|
|
53
|
-
try {
|
|
54
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
55
|
-
} catch (err) {
|
|
56
|
-
res[prop] = err.message;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return res;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/context.ts
|
|
63
|
-
var matchFilter = (filter, level, path) => {
|
|
64
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
65
|
-
};
|
|
66
|
-
var shouldLog = (entry, filters) => {
|
|
67
|
-
if (filters === void 0) {
|
|
68
|
-
return true;
|
|
69
|
-
} else {
|
|
70
|
-
return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var getContextFromEntry = (entry) => {
|
|
74
|
-
let context;
|
|
75
|
-
if (entry.meta) {
|
|
76
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
77
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
78
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
82
|
-
if (entryContext) {
|
|
83
|
-
if (entryContext instanceof Error) {
|
|
84
|
-
const c = entryContext.context;
|
|
85
|
-
context = Object.assign(context ?? {}, {
|
|
86
|
-
error: entryContext.stack,
|
|
87
|
-
...c
|
|
88
|
-
});
|
|
89
|
-
} else if (typeof entryContext === "object") {
|
|
90
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (entry.error) {
|
|
94
|
-
context = Object.assign(context ?? {}, {
|
|
95
|
-
error: entry.error
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
99
|
-
};
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
22
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
23
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
24
|
+
LogBuffer: () => LogBuffer,
|
|
25
|
+
LogLevel: () => LogLevel,
|
|
26
|
+
LogProcessorType: () => LogProcessorType,
|
|
27
|
+
createFileProcessor: () => createFileProcessor,
|
|
28
|
+
createLog: () => createLog,
|
|
29
|
+
dbg: () => dbg,
|
|
30
|
+
debug: () => debug,
|
|
31
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
32
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
33
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
34
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
35
|
+
levels: () => levels,
|
|
36
|
+
log: () => log,
|
|
37
|
+
logInfo: () => logInfo,
|
|
38
|
+
omit: () => omit,
|
|
39
|
+
parseFilter: () => parseFilter,
|
|
40
|
+
pick: () => pick,
|
|
41
|
+
shortLevelName: () => shortLevelName,
|
|
42
|
+
shouldLog: () => shouldLog
|
|
43
|
+
});
|
|
44
|
+
import { omit, pick } from "@dxos/util";
|
|
100
45
|
|
|
101
46
|
// src/decorators.ts
|
|
102
|
-
import chalk from "chalk";
|
|
103
47
|
import { inspect } from "node:util";
|
|
48
|
+
import chalk from "chalk";
|
|
104
49
|
var nextPromiseId = 0;
|
|
105
50
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
106
51
|
const method = descriptor.value;
|
|
@@ -197,142 +142,33 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
197
142
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
198
143
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
199
144
|
};
|
|
200
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
201
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
202
145
|
var COLOR_FUNCTION = [
|
|
203
146
|
220,
|
|
204
147
|
220,
|
|
205
148
|
170
|
|
206
149
|
];
|
|
150
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
151
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
207
152
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
208
153
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
209
154
|
|
|
210
155
|
// src/options.ts
|
|
211
156
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
212
157
|
|
|
213
|
-
// src/platform/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (filepath) {
|
|
218
|
-
try {
|
|
219
|
-
const text = fs.readFileSync(filepath, "utf-8");
|
|
220
|
-
if (text) {
|
|
221
|
-
return yaml.load(text);
|
|
222
|
-
}
|
|
223
|
-
} catch (err) {
|
|
224
|
-
console.warn(`Invalid log file: ${filepath}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
// src/processors/console-processor.ts
|
|
230
|
-
import chalk2 from "chalk";
|
|
231
|
-
import { inspect as inspect2 } from "node:util";
|
|
232
|
-
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
233
|
-
|
|
234
|
-
// src/processors/common.ts
|
|
235
|
-
var getRelativeFilename = (filename) => {
|
|
236
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
237
|
-
if (match) {
|
|
238
|
-
const [, filePath] = match;
|
|
239
|
-
return filePath;
|
|
240
|
-
}
|
|
241
|
-
return filename;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
// src/processors/console-processor.ts
|
|
245
|
-
var LEVEL_COLORS = {
|
|
246
|
-
[LogLevel.TRACE]: "gray",
|
|
247
|
-
[LogLevel.DEBUG]: "gray",
|
|
248
|
-
[LogLevel.VERBOSE]: "gray",
|
|
249
|
-
[LogLevel.INFO]: "white",
|
|
250
|
-
[LogLevel.WARN]: "yellow",
|
|
251
|
-
[LogLevel.ERROR]: "red"
|
|
252
|
-
};
|
|
253
|
-
var truncate = (text, length = 0, right = false) => {
|
|
254
|
-
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
255
|
-
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
256
|
-
};
|
|
257
|
-
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
258
|
-
const column = config.options?.formatter?.column;
|
|
259
|
-
const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
|
|
260
|
-
let instance;
|
|
261
|
-
if (scope) {
|
|
262
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
263
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
264
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
265
|
-
}
|
|
266
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
267
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
268
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
269
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
270
|
-
formattedTimestamp,
|
|
271
|
-
filepath,
|
|
272
|
-
padding,
|
|
273
|
-
formattedLevel,
|
|
274
|
-
instance,
|
|
275
|
-
message,
|
|
276
|
-
context,
|
|
277
|
-
error
|
|
278
|
-
] : [
|
|
279
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
280
|
-
// Must not truncate for terminal output.
|
|
281
|
-
filepath,
|
|
282
|
-
padding,
|
|
283
|
-
formattedTimestamp,
|
|
284
|
-
formattedLevel,
|
|
285
|
-
instance,
|
|
286
|
-
message,
|
|
287
|
-
context,
|
|
288
|
-
error
|
|
289
|
-
];
|
|
290
|
-
};
|
|
291
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
292
|
-
return [
|
|
293
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
294
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
295
|
-
message
|
|
296
|
-
];
|
|
297
|
-
};
|
|
298
|
-
var formatter = DEFAULT_FORMATTER;
|
|
299
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
300
|
-
const { level, message, meta, error } = entry;
|
|
301
|
-
if (!shouldLog(entry, config.filters)) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const parts = {
|
|
305
|
-
level,
|
|
306
|
-
message,
|
|
307
|
-
error,
|
|
308
|
-
path: void 0,
|
|
309
|
-
line: void 0,
|
|
310
|
-
scope: void 0,
|
|
311
|
-
context: void 0
|
|
312
|
-
};
|
|
313
|
-
if (meta) {
|
|
314
|
-
parts.path = getRelativeFilename(meta.F);
|
|
315
|
-
parts.line = meta.L;
|
|
316
|
-
parts.scope = meta.S;
|
|
317
|
-
}
|
|
318
|
-
const context = getContextFromEntry(entry);
|
|
319
|
-
if (context) {
|
|
320
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
321
|
-
depth: config.options.depth,
|
|
322
|
-
colors: true,
|
|
323
|
-
maxArrayLength: 8,
|
|
324
|
-
sorted: false
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
328
|
-
console.log(line);
|
|
329
|
-
};
|
|
158
|
+
// src/platform/index.ts
|
|
159
|
+
var platform_exports = {};
|
|
160
|
+
__reExport(platform_exports, platform_star);
|
|
161
|
+
import * as platform_star from "#platform";
|
|
330
162
|
|
|
331
|
-
// src/processors/
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
163
|
+
// src/processors/index.ts
|
|
164
|
+
var processors_exports = {};
|
|
165
|
+
__export(processors_exports, {
|
|
166
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
167
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
168
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
169
|
+
createFileProcessor: () => createFileProcessor,
|
|
170
|
+
getRelativeFilename: () => getRelativeFilename
|
|
171
|
+
});
|
|
336
172
|
|
|
337
173
|
// src/processors/browser-processor.ts
|
|
338
174
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
@@ -374,6 +210,8 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
374
210
|
if (context) {
|
|
375
211
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
376
212
|
args.push(context.error);
|
|
213
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
214
|
+
args.push(context.err);
|
|
377
215
|
} else {
|
|
378
216
|
args.push(context);
|
|
379
217
|
}
|
|
@@ -439,6 +277,16 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
439
277
|
};
|
|
440
278
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
441
279
|
|
|
280
|
+
// src/processors/index.ts
|
|
281
|
+
__reExport(processors_exports, console_processor_star);
|
|
282
|
+
import * as console_processor_star from "#console-processor";
|
|
283
|
+
|
|
284
|
+
// src/processors/debug-processor.ts
|
|
285
|
+
import { inspect as inspect2 } from "node:util";
|
|
286
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
287
|
+
console.log(inspect2(entry, false, null, true));
|
|
288
|
+
};
|
|
289
|
+
|
|
442
290
|
// src/processors/file-processor.ts
|
|
443
291
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
444
292
|
import { dirname } from "node:path";
|
|
@@ -510,14 +358,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
510
358
|
|
|
511
359
|
// src/options.ts
|
|
512
360
|
var processors = {
|
|
513
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
361
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
514
362
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
515
363
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
516
364
|
};
|
|
517
|
-
var
|
|
365
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
518
366
|
var DEFAULT_PROCESSORS = [
|
|
519
|
-
|
|
367
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
520
368
|
];
|
|
369
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
521
370
|
var parseFilter = (filter) => {
|
|
522
371
|
if (typeof filter === "number") {
|
|
523
372
|
return [
|
|
@@ -526,7 +375,6 @@ var parseFilter = (filter) => {
|
|
|
526
375
|
}
|
|
527
376
|
];
|
|
528
377
|
}
|
|
529
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
530
378
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
531
379
|
return lines.map((filter2) => {
|
|
532
380
|
const [pattern, level] = filter2.split(":");
|
|
@@ -538,54 +386,37 @@ var parseFilter = (filter) => {
|
|
|
538
386
|
};
|
|
539
387
|
});
|
|
540
388
|
};
|
|
541
|
-
var
|
|
542
|
-
const
|
|
389
|
+
var createConfig = (options) => {
|
|
390
|
+
const envOptions = "process" in globalThis ? {
|
|
543
391
|
file: process.env.LOG_CONFIG,
|
|
544
392
|
filter: process.env.LOG_FILTER,
|
|
545
393
|
processor: process.env.LOG_PROCESSOR
|
|
546
394
|
} : void 0;
|
|
547
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
395
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
548
396
|
return {
|
|
549
397
|
options: mergedOptions,
|
|
550
398
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
551
399
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
552
400
|
processors: mergedOptions.processor ? [
|
|
553
401
|
processors[mergedOptions.processor]
|
|
554
|
-
] :
|
|
402
|
+
] : [
|
|
403
|
+
...DEFAULT_PROCESSORS
|
|
404
|
+
],
|
|
555
405
|
prefix: mergedOptions.prefix
|
|
556
406
|
};
|
|
557
407
|
};
|
|
558
408
|
|
|
559
409
|
// src/log.ts
|
|
410
|
+
var logCount = 0;
|
|
560
411
|
var createLog = () => {
|
|
561
412
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
562
|
-
log2
|
|
413
|
+
Object.assign(log2, {
|
|
414
|
+
_id: `log-${++logCount}`,
|
|
415
|
+
_config: createConfig()
|
|
416
|
+
});
|
|
563
417
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
564
418
|
get: () => log2._config
|
|
565
419
|
});
|
|
566
|
-
log2.addProcessor = (processor) => {
|
|
567
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
568
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
569
|
-
}
|
|
570
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
571
|
-
log2._config.processors.push(processor);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
log2.config = (options) => {
|
|
575
|
-
log2._config = getConfig(options);
|
|
576
|
-
};
|
|
577
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
578
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
579
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
580
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
581
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
582
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
583
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
584
|
-
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");
|
|
585
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
586
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
587
|
-
log2.method = createMethodLogDecorator(log2);
|
|
588
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
589
420
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
590
421
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
591
422
|
level,
|
|
@@ -595,9 +426,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
595
426
|
error
|
|
596
427
|
}));
|
|
597
428
|
};
|
|
429
|
+
Object.assign(log2, {
|
|
430
|
+
/**
|
|
431
|
+
* Update config.
|
|
432
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
433
|
+
* unless an explicit processor option is provided.
|
|
434
|
+
*/
|
|
435
|
+
config: ({ processor, ...options } = {}) => {
|
|
436
|
+
const config = createConfig(options);
|
|
437
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
438
|
+
log2._config = {
|
|
439
|
+
...config,
|
|
440
|
+
processors: processors2
|
|
441
|
+
};
|
|
442
|
+
return log2;
|
|
443
|
+
},
|
|
444
|
+
/**
|
|
445
|
+
* Adds a processor to the logger.
|
|
446
|
+
*/
|
|
447
|
+
addProcessor: (processor) => {
|
|
448
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
449
|
+
log2._config.processors.push(processor);
|
|
450
|
+
}
|
|
451
|
+
return () => {
|
|
452
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
453
|
+
};
|
|
454
|
+
},
|
|
455
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
456
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
457
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
458
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
459
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
460
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
461
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
462
|
+
method: createMethodLogDecorator(log2),
|
|
463
|
+
function: createFunctionLogDecorator(log2),
|
|
464
|
+
break: () => log2.info("-".repeat(80)),
|
|
465
|
+
stack: (message, context, meta) => {
|
|
466
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
467
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
598
470
|
return log2;
|
|
599
471
|
};
|
|
600
|
-
var log = globalThis.
|
|
472
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
601
473
|
var start = Date.now();
|
|
602
474
|
var last = start;
|
|
603
475
|
var debug = (label, args) => {
|
|
@@ -614,12 +486,92 @@ var debug = (label, args) => {
|
|
|
614
486
|
};
|
|
615
487
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
616
488
|
|
|
489
|
+
// src/index.ts
|
|
490
|
+
__reExport(index_exports, processors_exports);
|
|
491
|
+
|
|
492
|
+
// src/dbg.ts
|
|
493
|
+
var dbg = (arg, meta) => {
|
|
494
|
+
if (meta?.A) {
|
|
495
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
496
|
+
} else {
|
|
497
|
+
console.log(arg);
|
|
498
|
+
}
|
|
499
|
+
return arg;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/log-buffer.ts
|
|
503
|
+
import { CircularBuffer } from "@dxos/util";
|
|
504
|
+
var DEFAULT_BUFFER_SIZE = 2e3;
|
|
505
|
+
var MAX_CONTEXT_LENGTH = 500;
|
|
506
|
+
var LogBuffer = class {
|
|
507
|
+
_buffer;
|
|
508
|
+
constructor(size = DEFAULT_BUFFER_SIZE) {
|
|
509
|
+
this._buffer = new CircularBuffer(size);
|
|
510
|
+
}
|
|
511
|
+
/** Log processor that can be registered with `log.runtimeConfig.processors`. */
|
|
512
|
+
logProcessor = (_config, entry) => {
|
|
513
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const record = {
|
|
517
|
+
t: (/* @__PURE__ */ new Date()).toISOString(),
|
|
518
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
519
|
+
m: entry.message ?? ""
|
|
520
|
+
};
|
|
521
|
+
if (entry.meta) {
|
|
522
|
+
record.f = getRelativeFilename3(entry.meta.F);
|
|
523
|
+
record.n = entry.meta.L;
|
|
524
|
+
}
|
|
525
|
+
if (entry.error) {
|
|
526
|
+
record.e = entry.error.stack ?? entry.error.message;
|
|
527
|
+
}
|
|
528
|
+
if (entry.context != null) {
|
|
529
|
+
try {
|
|
530
|
+
const ctx = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
531
|
+
if (ctx != null && !(ctx instanceof Error)) {
|
|
532
|
+
let json = JSON.stringify(ctx);
|
|
533
|
+
if (json.length > MAX_CONTEXT_LENGTH) {
|
|
534
|
+
json = json.slice(0, MAX_CONTEXT_LENGTH);
|
|
535
|
+
}
|
|
536
|
+
record.c = json;
|
|
537
|
+
}
|
|
538
|
+
} catch {
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
this._buffer.push(record);
|
|
542
|
+
};
|
|
543
|
+
/** Number of entries currently in the buffer. */
|
|
544
|
+
get size() {
|
|
545
|
+
return this._buffer.elementCount;
|
|
546
|
+
}
|
|
547
|
+
/** Discard all buffered entries. */
|
|
548
|
+
clear() {
|
|
549
|
+
this._buffer.clear();
|
|
550
|
+
}
|
|
551
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
552
|
+
serialize() {
|
|
553
|
+
const lines = [];
|
|
554
|
+
for (const record of this._buffer) {
|
|
555
|
+
lines.push(JSON.stringify(record));
|
|
556
|
+
}
|
|
557
|
+
return lines.join("\n");
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
var getRelativeFilename3 = (filename) => {
|
|
561
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
562
|
+
if (match) {
|
|
563
|
+
return match[1];
|
|
564
|
+
}
|
|
565
|
+
return filename;
|
|
566
|
+
};
|
|
567
|
+
|
|
617
568
|
// src/experimental/ownership.ts
|
|
618
|
-
import { inspect as
|
|
619
|
-
var
|
|
620
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
621
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
569
|
+
import { inspect as inspect3 } from "node:util";
|
|
570
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
622
571
|
var OwnershipScope = class {
|
|
572
|
+
constr;
|
|
573
|
+
parent;
|
|
574
|
+
instance;
|
|
623
575
|
constructor(constr, parent) {
|
|
624
576
|
this.constr = constr;
|
|
625
577
|
this.parent = parent;
|
|
@@ -635,7 +587,7 @@ var OwnershipScope = class {
|
|
|
635
587
|
}
|
|
636
588
|
return info;
|
|
637
589
|
}
|
|
638
|
-
[
|
|
590
|
+
[inspect3.custom]() {
|
|
639
591
|
return {
|
|
640
592
|
className: this.constr.name,
|
|
641
593
|
info: this.getInfo(),
|
|
@@ -646,14 +598,14 @@ var OwnershipScope = class {
|
|
|
646
598
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
647
599
|
export {
|
|
648
600
|
BROWSER_PROCESSOR,
|
|
649
|
-
CONSOLE_PROCESSOR,
|
|
650
601
|
DEBUG_PROCESSOR,
|
|
651
|
-
DEFAULT_FORMATTER,
|
|
652
602
|
FILE_PROCESSOR,
|
|
603
|
+
LogBuffer,
|
|
653
604
|
LogLevel,
|
|
654
605
|
LogProcessorType,
|
|
655
|
-
SHORT_FORMATTER,
|
|
656
606
|
createFileProcessor,
|
|
607
|
+
createLog,
|
|
608
|
+
dbg,
|
|
657
609
|
debug,
|
|
658
610
|
gatherLogInfoFromScope,
|
|
659
611
|
getContextFromEntry,
|
|
@@ -666,7 +618,6 @@ export {
|
|
|
666
618
|
parseFilter,
|
|
667
619
|
pick,
|
|
668
620
|
shortLevelName,
|
|
669
|
-
shouldLog
|
|
670
|
-
truncate
|
|
621
|
+
shouldLog
|
|
671
622
|
};
|
|
672
623
|
//# sourceMappingURL=index.mjs.map
|