@dxos/log 0.8.4-main.fd6878d → 0.8.4-staging.ac66bdf99f
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-DTUPLFUN.mjs +311 -0
- package/dist/lib/browser/chunk-DTUPLFUN.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 +243 -211
- 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 +102 -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-KOTHKRYW.mjs +313 -0
- package/dist/lib/node-esm/chunk-KOTHKRYW.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +245 -300
- 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 +103 -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 +78 -2
- 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 +40 -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 +30 -12
- package/src/config.ts +3 -2
- package/src/context.ts +278 -7
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +4 -5
- package/src/experimental/classes.test.ts +0 -1
- package/src/index.ts +3 -3
- package/src/log-buffer.test.ts +158 -0
- package/src/log-buffer.ts +110 -0
- package/src/log.test.ts +48 -19
- package/src/log.ts +97 -58
- package/src/options.ts +26 -10
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +1 -2
- package/src/processors/browser-processor.ts +28 -27
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +9 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,106 +1,53 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
LogEntry,
|
|
4
|
+
LogLevel,
|
|
5
|
+
LogProcessorType,
|
|
6
|
+
gatherLogInfoFromScope,
|
|
7
|
+
getContextFromEntry,
|
|
8
|
+
getRelativeFilename,
|
|
9
|
+
levels,
|
|
10
|
+
logInfo,
|
|
11
|
+
shortLevelName,
|
|
12
|
+
shouldLog
|
|
13
|
+
} from "./chunk-KOTHKRYW.mjs";
|
|
14
|
+
import {
|
|
15
|
+
__export,
|
|
16
|
+
__reExport
|
|
17
|
+
} from "./chunk-2SZHAWBN.mjs";
|
|
2
18
|
|
|
3
19
|
// 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
|
-
|
|
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 = (typeof prototype === "object" && prototype !== null ? 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
|
-
};
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
23
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
24
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
25
|
+
LogBuffer: () => LogBuffer,
|
|
26
|
+
LogEntry: () => LogEntry,
|
|
27
|
+
LogLevel: () => LogLevel,
|
|
28
|
+
LogProcessorType: () => LogProcessorType,
|
|
29
|
+
createFileProcessor: () => createFileProcessor,
|
|
30
|
+
createLog: () => createLog,
|
|
31
|
+
dbg: () => dbg,
|
|
32
|
+
debug: () => debug,
|
|
33
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
34
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
35
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
36
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
37
|
+
levels: () => levels,
|
|
38
|
+
log: () => log,
|
|
39
|
+
logInfo: () => logInfo,
|
|
40
|
+
omit: () => omit,
|
|
41
|
+
parseFilter: () => parseFilter,
|
|
42
|
+
pick: () => pick,
|
|
43
|
+
shortLevelName: () => shortLevelName,
|
|
44
|
+
shouldLog: () => shouldLog
|
|
45
|
+
});
|
|
46
|
+
import { omit, pick } from "@dxos/util";
|
|
100
47
|
|
|
101
48
|
// src/decorators.ts
|
|
102
|
-
import { inspect } from "node:util";
|
|
103
49
|
import chalk from "chalk";
|
|
50
|
+
import { inspect } from "node:util";
|
|
104
51
|
var nextPromiseId = 0;
|
|
105
52
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
106
53
|
const method = descriptor.value;
|
|
@@ -197,155 +144,36 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
197
144
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
198
145
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
199
146
|
};
|
|
200
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
201
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
202
147
|
var COLOR_FUNCTION = [
|
|
203
148
|
220,
|
|
204
149
|
220,
|
|
205
150
|
170
|
|
206
151
|
];
|
|
152
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
153
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
207
154
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
208
155
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
209
156
|
|
|
210
157
|
// src/options.ts
|
|
211
158
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
212
159
|
|
|
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 { inspect as inspect2 } from "node:util";
|
|
231
|
-
import chalk2 from "chalk";
|
|
232
|
-
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
160
|
+
// src/platform/index.ts
|
|
161
|
+
var platform_exports = {};
|
|
162
|
+
__reExport(platform_exports, platform_star);
|
|
163
|
+
import * as platform_star from "#platform";
|
|
233
164
|
|
|
234
|
-
// src/processors/
|
|
235
|
-
var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
if (prototype !== null) {
|
|
264
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
265
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
269
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
270
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
271
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
272
|
-
formattedTimestamp,
|
|
273
|
-
filepath,
|
|
274
|
-
padding,
|
|
275
|
-
formattedLevel,
|
|
276
|
-
instance,
|
|
277
|
-
message,
|
|
278
|
-
context,
|
|
279
|
-
error
|
|
280
|
-
] : [
|
|
281
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
282
|
-
// Must not truncate for terminal output.
|
|
283
|
-
filepath,
|
|
284
|
-
padding,
|
|
285
|
-
formattedTimestamp,
|
|
286
|
-
formattedLevel,
|
|
287
|
-
instance,
|
|
288
|
-
message,
|
|
289
|
-
context,
|
|
290
|
-
error
|
|
291
|
-
];
|
|
292
|
-
};
|
|
293
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
294
|
-
return [
|
|
295
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
296
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
297
|
-
message
|
|
298
|
-
];
|
|
299
|
-
};
|
|
300
|
-
var formatter = DEFAULT_FORMATTER;
|
|
301
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
302
|
-
const { level, message, meta, error } = entry;
|
|
303
|
-
if (!shouldLog(entry, config.filters)) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const parts = {
|
|
307
|
-
level,
|
|
308
|
-
message,
|
|
309
|
-
error,
|
|
310
|
-
path: void 0,
|
|
311
|
-
line: void 0,
|
|
312
|
-
scope: void 0,
|
|
313
|
-
context: void 0
|
|
314
|
-
};
|
|
315
|
-
if (meta) {
|
|
316
|
-
parts.path = getRelativeFilename(meta.F);
|
|
317
|
-
parts.line = meta.L;
|
|
318
|
-
parts.scope = meta.S;
|
|
319
|
-
}
|
|
320
|
-
const context = getContextFromEntry(entry);
|
|
321
|
-
if (context) {
|
|
322
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
323
|
-
depth: config.options.depth,
|
|
324
|
-
colors: true,
|
|
325
|
-
maxArrayLength: 8,
|
|
326
|
-
sorted: false
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
330
|
-
console.log(line);
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
// src/processors/debug-processor.ts
|
|
334
|
-
import { inspect as inspect3 } from "node:util";
|
|
335
|
-
var DEBUG_PROCESSOR = (config, entry) => {
|
|
336
|
-
console.log(inspect3(entry, false, null, true));
|
|
337
|
-
};
|
|
165
|
+
// src/processors/index.ts
|
|
166
|
+
var processors_exports = {};
|
|
167
|
+
__export(processors_exports, {
|
|
168
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
169
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
170
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
171
|
+
createFileProcessor: () => createFileProcessor,
|
|
172
|
+
getRelativeFilename: () => getRelativeFilename
|
|
173
|
+
});
|
|
338
174
|
|
|
339
175
|
// src/processors/browser-processor.ts
|
|
340
|
-
import {
|
|
341
|
-
var getRelativeFilename2 = (filename) => {
|
|
342
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
343
|
-
if (match) {
|
|
344
|
-
const [, filePath] = match;
|
|
345
|
-
return filePath;
|
|
346
|
-
}
|
|
347
|
-
return filename;
|
|
348
|
-
};
|
|
176
|
+
import { safariCheck } from "@dxos/util";
|
|
349
177
|
var CONFIG = {
|
|
350
178
|
useTestProcessor: false,
|
|
351
179
|
printFileLinks: false
|
|
@@ -356,18 +184,20 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
356
184
|
}
|
|
357
185
|
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
358
186
|
const LOG_BROWSER_CSS = [];
|
|
187
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
359
188
|
let link = "";
|
|
360
|
-
if (
|
|
361
|
-
const filename = getRelativeFilename2(entry.meta.F);
|
|
189
|
+
if (filename !== void 0 && lineNumber !== void 0) {
|
|
362
190
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
363
|
-
link = `${filepath}#L${
|
|
191
|
+
link = `${filepath}#L${lineNumber}`;
|
|
364
192
|
}
|
|
365
193
|
let args = [];
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const scopeName = scope.name ||
|
|
369
|
-
|
|
370
|
-
|
|
194
|
+
const scope = entry.meta?.S;
|
|
195
|
+
if (scope) {
|
|
196
|
+
const scopeName = scope.name || scopeDebugName;
|
|
197
|
+
if (scopeName) {
|
|
198
|
+
const processPrefix = scope.hostSessionId ? "[worker] " : "";
|
|
199
|
+
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
200
|
+
}
|
|
371
201
|
}
|
|
372
202
|
if (entry.message) {
|
|
373
203
|
args.push(entry.message);
|
|
@@ -375,7 +205,9 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
375
205
|
const context = getContextFromEntry(entry);
|
|
376
206
|
if (context) {
|
|
377
207
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
378
|
-
args.push(context.error);
|
|
208
|
+
args.push(unwrapEffectError(context.error));
|
|
209
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
210
|
+
args.push(unwrapEffectError(context.err));
|
|
379
211
|
} else {
|
|
380
212
|
args.push(context);
|
|
381
213
|
}
|
|
@@ -410,10 +242,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
410
242
|
if (!shouldLog(entry, config.filters)) {
|
|
411
243
|
return;
|
|
412
244
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
416
|
-
}
|
|
245
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
246
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
417
247
|
let args = [];
|
|
418
248
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
419
249
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -440,11 +270,27 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
440
270
|
}
|
|
441
271
|
};
|
|
442
272
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
273
|
+
var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
|
|
274
|
+
var unwrapEffectError = (error) => {
|
|
275
|
+
if (typeof error === "object" && error !== null && originalSymbol in error) {
|
|
276
|
+
return error[originalSymbol];
|
|
277
|
+
}
|
|
278
|
+
return error;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// src/processors/index.ts
|
|
282
|
+
__reExport(processors_exports, console_processor_star);
|
|
283
|
+
import * as console_processor_star from "#console-processor";
|
|
284
|
+
|
|
285
|
+
// src/processors/debug-processor.ts
|
|
286
|
+
import { inspect as inspect2 } from "node:util";
|
|
287
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
288
|
+
console.log(inspect2(entry, false, null, true));
|
|
289
|
+
};
|
|
443
290
|
|
|
444
291
|
// src/processors/file-processor.ts
|
|
445
292
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
446
293
|
import { dirname } from "node:path";
|
|
447
|
-
import { jsonlogify } from "@dxos/util";
|
|
448
294
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
449
295
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
450
296
|
let fd;
|
|
@@ -465,15 +311,12 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
465
311
|
fd = openSync(pathOrFd, "a");
|
|
466
312
|
}
|
|
467
313
|
const record = {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
} : {},
|
|
476
|
-
context: jsonlogify(getContextFromEntry(entry))
|
|
314
|
+
level: entry.level,
|
|
315
|
+
message: entry.message,
|
|
316
|
+
timestamp: entry.timestamp,
|
|
317
|
+
meta: entry.computedMeta,
|
|
318
|
+
context: entry.computedContext,
|
|
319
|
+
error: entry.computedError
|
|
477
320
|
};
|
|
478
321
|
let retryTS = 0;
|
|
479
322
|
while (true) {
|
|
@@ -512,14 +355,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
512
355
|
|
|
513
356
|
// src/options.ts
|
|
514
357
|
var processors = {
|
|
515
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
358
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
516
359
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
517
360
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
518
361
|
};
|
|
519
|
-
var
|
|
362
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
520
363
|
var DEFAULT_PROCESSORS = [
|
|
521
|
-
|
|
364
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
522
365
|
];
|
|
366
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
523
367
|
var parseFilter = (filter) => {
|
|
524
368
|
if (typeof filter === "number") {
|
|
525
369
|
return [
|
|
@@ -528,7 +372,6 @@ var parseFilter = (filter) => {
|
|
|
528
372
|
}
|
|
529
373
|
];
|
|
530
374
|
}
|
|
531
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
532
375
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
533
376
|
return lines.map((filter2) => {
|
|
534
377
|
const [pattern, level] = filter2.split(":");
|
|
@@ -540,66 +383,91 @@ var parseFilter = (filter) => {
|
|
|
540
383
|
};
|
|
541
384
|
});
|
|
542
385
|
};
|
|
543
|
-
var
|
|
544
|
-
const
|
|
386
|
+
var createConfig = (options) => {
|
|
387
|
+
const envOptions = "process" in globalThis ? {
|
|
545
388
|
file: process.env.LOG_CONFIG,
|
|
546
389
|
filter: process.env.LOG_FILTER,
|
|
547
390
|
processor: process.env.LOG_PROCESSOR
|
|
548
391
|
} : void 0;
|
|
549
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
392
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
550
393
|
return {
|
|
551
394
|
options: mergedOptions,
|
|
552
395
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
553
396
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
554
397
|
processors: mergedOptions.processor ? [
|
|
555
398
|
processors[mergedOptions.processor]
|
|
556
|
-
] :
|
|
399
|
+
] : [
|
|
400
|
+
...DEFAULT_PROCESSORS
|
|
401
|
+
],
|
|
557
402
|
prefix: mergedOptions.prefix
|
|
558
403
|
};
|
|
559
404
|
};
|
|
560
405
|
|
|
561
406
|
// src/log.ts
|
|
407
|
+
var logCount = 0;
|
|
562
408
|
var createLog = () => {
|
|
563
409
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
564
|
-
log2
|
|
410
|
+
Object.assign(log2, {
|
|
411
|
+
_id: `log-${++logCount}`,
|
|
412
|
+
_config: createConfig()
|
|
413
|
+
});
|
|
565
414
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
566
415
|
get: () => log2._config
|
|
567
416
|
});
|
|
568
|
-
log2.addProcessor = (processor) => {
|
|
569
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
570
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
571
|
-
}
|
|
572
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
573
|
-
log2._config.processors.push(processor);
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
log2.config = (options) => {
|
|
577
|
-
log2._config = getConfig(options);
|
|
578
|
-
};
|
|
579
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
580
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
581
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
582
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
583
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
584
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
585
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
586
|
-
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");
|
|
587
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
588
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
589
|
-
log2.method = createMethodLogDecorator(log2);
|
|
590
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
591
417
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
592
|
-
|
|
418
|
+
const entry = new LogEntry({
|
|
593
419
|
level,
|
|
594
420
|
message,
|
|
595
421
|
context,
|
|
596
422
|
meta,
|
|
597
423
|
error
|
|
598
|
-
})
|
|
424
|
+
});
|
|
425
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
599
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
|
+
});
|
|
600
468
|
return log2;
|
|
601
469
|
};
|
|
602
|
-
var log = globalThis.
|
|
470
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
603
471
|
var start = Date.now();
|
|
604
472
|
var last = start;
|
|
605
473
|
var debug = (label, args) => {
|
|
@@ -616,11 +484,88 @@ var debug = (label, args) => {
|
|
|
616
484
|
};
|
|
617
485
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
618
486
|
|
|
487
|
+
// src/index.ts
|
|
488
|
+
__reExport(index_exports, processors_exports);
|
|
489
|
+
|
|
490
|
+
// src/dbg.ts
|
|
491
|
+
var dbg = (arg, meta) => {
|
|
492
|
+
if (meta?.A) {
|
|
493
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
494
|
+
} else {
|
|
495
|
+
console.log(arg);
|
|
496
|
+
}
|
|
497
|
+
return arg;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// src/log-buffer.ts
|
|
501
|
+
import { CircularBuffer } from "@dxos/util";
|
|
502
|
+
var DEFAULT_BUFFER_SIZE = 2e3;
|
|
503
|
+
var MAX_CONTEXT_LENGTH = 500;
|
|
504
|
+
var LogBuffer = class {
|
|
505
|
+
_buffer;
|
|
506
|
+
constructor(size = DEFAULT_BUFFER_SIZE) {
|
|
507
|
+
this._buffer = new CircularBuffer(size);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Log processor that can be registered with `log.runtimeConfig.processors`.
|
|
511
|
+
* Captures every level except TRACE (does not apply `shouldLog` / filter; use for full debug dumps).
|
|
512
|
+
*/
|
|
513
|
+
logProcessor = (_config, entry) => {
|
|
514
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const { filename, line, context: scopeName } = entry.computedMeta;
|
|
518
|
+
const record = {
|
|
519
|
+
t: new Date(entry.timestamp).toISOString(),
|
|
520
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
521
|
+
m: entry.message ?? ""
|
|
522
|
+
};
|
|
523
|
+
if (filename !== void 0) {
|
|
524
|
+
record.f = filename;
|
|
525
|
+
}
|
|
526
|
+
if (line !== void 0) {
|
|
527
|
+
record.n = line;
|
|
528
|
+
}
|
|
529
|
+
if (scopeName !== void 0) {
|
|
530
|
+
record.o = scopeName;
|
|
531
|
+
}
|
|
532
|
+
if (entry.computedError !== void 0) {
|
|
533
|
+
record.e = entry.computedError;
|
|
534
|
+
}
|
|
535
|
+
const computedContext = entry.computedContext;
|
|
536
|
+
if (Object.keys(computedContext).length > 0) {
|
|
537
|
+
try {
|
|
538
|
+
let json = JSON.stringify(computedContext);
|
|
539
|
+
if (json.length > MAX_CONTEXT_LENGTH) {
|
|
540
|
+
json = json.slice(0, MAX_CONTEXT_LENGTH);
|
|
541
|
+
}
|
|
542
|
+
record.c = json;
|
|
543
|
+
} catch {
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
this._buffer.push(record);
|
|
547
|
+
};
|
|
548
|
+
/** Number of entries currently in the buffer. */
|
|
549
|
+
get size() {
|
|
550
|
+
return this._buffer.elementCount;
|
|
551
|
+
}
|
|
552
|
+
/** Discard all buffered entries. */
|
|
553
|
+
clear() {
|
|
554
|
+
this._buffer.clear();
|
|
555
|
+
}
|
|
556
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
557
|
+
serialize() {
|
|
558
|
+
const lines = [];
|
|
559
|
+
for (const record of this._buffer) {
|
|
560
|
+
lines.push(JSON.stringify(record));
|
|
561
|
+
}
|
|
562
|
+
return lines.join("\n");
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
619
566
|
// src/experimental/ownership.ts
|
|
620
|
-
import { inspect as
|
|
621
|
-
var
|
|
622
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
623
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
567
|
+
import { inspect as inspect3 } from "node:util";
|
|
568
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
624
569
|
var OwnershipScope = class {
|
|
625
570
|
constr;
|
|
626
571
|
parent;
|
|
@@ -640,7 +585,7 @@ var OwnershipScope = class {
|
|
|
640
585
|
}
|
|
641
586
|
return info;
|
|
642
587
|
}
|
|
643
|
-
[
|
|
588
|
+
[inspect3.custom]() {
|
|
644
589
|
return {
|
|
645
590
|
className: this.constr.name,
|
|
646
591
|
info: this.getInfo(),
|
|
@@ -651,14 +596,15 @@ var OwnershipScope = class {
|
|
|
651
596
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
652
597
|
export {
|
|
653
598
|
BROWSER_PROCESSOR,
|
|
654
|
-
CONSOLE_PROCESSOR,
|
|
655
599
|
DEBUG_PROCESSOR,
|
|
656
|
-
DEFAULT_FORMATTER,
|
|
657
600
|
FILE_PROCESSOR,
|
|
601
|
+
LogBuffer,
|
|
602
|
+
LogEntry,
|
|
658
603
|
LogLevel,
|
|
659
604
|
LogProcessorType,
|
|
660
|
-
SHORT_FORMATTER,
|
|
661
605
|
createFileProcessor,
|
|
606
|
+
createLog,
|
|
607
|
+
dbg,
|
|
662
608
|
debug,
|
|
663
609
|
gatherLogInfoFromScope,
|
|
664
610
|
getContextFromEntry,
|
|
@@ -671,7 +617,6 @@ export {
|
|
|
671
617
|
parseFilter,
|
|
672
618
|
pick,
|
|
673
619
|
shortLevelName,
|
|
674
|
-
shouldLog
|
|
675
|
-
truncate
|
|
620
|
+
shouldLog
|
|
676
621
|
};
|
|
677
622
|
//# sourceMappingURL=index.mjs.map
|