@dxos/log 0.8.4-main.fffef41 → 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 +187 -199
- 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 +189 -288
- 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/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.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 +3 -1
- package/dist/types/src/log.d.ts.map +1 -1
- 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/context.ts +242 -2
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +1 -2
- 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 +0 -1
- package/src/log.ts +7 -12
- package/src/options.ts +3 -1
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +1 -2
- package/src/processors/browser-processor.ts +27 -28
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +7 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,123 +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
|
-
[13]: "W",
|
|
32
|
-
[14]: "E"
|
|
33
|
-
};
|
|
34
|
-
var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
|
|
35
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
36
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
37
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
38
|
-
return LogProcessorType2;
|
|
39
|
-
})({});
|
|
40
|
-
|
|
41
|
-
// src/scope.ts
|
|
42
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
43
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
44
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
45
|
-
};
|
|
46
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
47
|
-
if (!scope) {
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
const res = {};
|
|
51
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
52
|
-
const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
|
|
53
|
-
for (const prop of infoProps) {
|
|
54
|
-
try {
|
|
55
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
56
|
-
} catch (err) {
|
|
57
|
-
res[prop] = err.message;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return res;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/context.ts
|
|
64
|
-
var matchFilter = (filter, level, path) => {
|
|
65
|
-
if (filter.pattern?.startsWith("-")) {
|
|
66
|
-
if (path?.includes(filter.pattern.slice(1))) {
|
|
67
|
-
if (level >= filter.level) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
if (filter.pattern?.length) {
|
|
73
|
-
if (path?.includes(filter.pattern)) {
|
|
74
|
-
return level >= filter.level;
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
if (level >= filter.level) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var shouldLog = (entry, filters) => {
|
|
84
|
-
if (filters === void 0) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const results = filters.map((filter) => matchFilter(filter, entry.level, entry.meta?.F)).filter((result) => result !== void 0);
|
|
88
|
-
return results.length > 0 && !results.some((results2) => results2 === false);
|
|
89
|
-
};
|
|
90
|
-
var getContextFromEntry = (entry) => {
|
|
91
|
-
let context;
|
|
92
|
-
if (entry.meta) {
|
|
93
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
94
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
95
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
99
|
-
if (entryContext) {
|
|
100
|
-
if (entryContext instanceof Error) {
|
|
101
|
-
const c = entryContext.context;
|
|
102
|
-
context = Object.assign(context ?? {}, {
|
|
103
|
-
error: entryContext.stack,
|
|
104
|
-
...c
|
|
105
|
-
});
|
|
106
|
-
} else if (typeof entryContext === "object") {
|
|
107
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (entry.error) {
|
|
111
|
-
context = Object.assign(context ?? {}, {
|
|
112
|
-
error: entry.error
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
116
|
-
};
|
|
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";
|
|
117
47
|
|
|
118
48
|
// src/decorators.ts
|
|
119
|
-
import { inspect } from "node:util";
|
|
120
49
|
import chalk from "chalk";
|
|
50
|
+
import { inspect } from "node:util";
|
|
121
51
|
var nextPromiseId = 0;
|
|
122
52
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
123
53
|
const method = descriptor.value;
|
|
@@ -227,142 +157,23 @@ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
|
227
157
|
// src/options.ts
|
|
228
158
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
229
159
|
|
|
230
|
-
// src/platform/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (filepath) {
|
|
235
|
-
try {
|
|
236
|
-
const text = fs.readFileSync(filepath, "utf-8");
|
|
237
|
-
if (text) {
|
|
238
|
-
return yaml.load(text);
|
|
239
|
-
}
|
|
240
|
-
} catch (err) {
|
|
241
|
-
console.warn(`Invalid log file: ${filepath}`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
// src/processors/console-processor.ts
|
|
247
|
-
import { inspect as inspect2 } from "node:util";
|
|
248
|
-
import chalk2 from "chalk";
|
|
249
|
-
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
250
|
-
|
|
251
|
-
// src/processors/common.ts
|
|
252
|
-
var getRelativeFilename = (filename) => {
|
|
253
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
254
|
-
if (match) {
|
|
255
|
-
const [, filePath] = match;
|
|
256
|
-
return filePath;
|
|
257
|
-
}
|
|
258
|
-
return filename;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// src/processors/console-processor.ts
|
|
262
|
-
var LEVEL_COLORS = {
|
|
263
|
-
[LogLevel.TRACE]: "gray",
|
|
264
|
-
[LogLevel.DEBUG]: "gray",
|
|
265
|
-
[LogLevel.VERBOSE]: "gray",
|
|
266
|
-
[LogLevel.INFO]: "white",
|
|
267
|
-
[LogLevel.WARN]: "yellow",
|
|
268
|
-
[LogLevel.ERROR]: "red"
|
|
269
|
-
};
|
|
270
|
-
var truncate = (text, length = 0, right = false) => {
|
|
271
|
-
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
272
|
-
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
273
|
-
};
|
|
274
|
-
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
275
|
-
const column = config.options?.formatter?.column;
|
|
276
|
-
const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
|
|
277
|
-
let instance;
|
|
278
|
-
if (scope) {
|
|
279
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
280
|
-
if (prototype !== null) {
|
|
281
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
282
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
286
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
287
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
288
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
289
|
-
formattedTimestamp,
|
|
290
|
-
filepath,
|
|
291
|
-
padding,
|
|
292
|
-
formattedLevel,
|
|
293
|
-
instance,
|
|
294
|
-
message,
|
|
295
|
-
context,
|
|
296
|
-
error
|
|
297
|
-
] : [
|
|
298
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
299
|
-
// Must not truncate for terminal output.
|
|
300
|
-
filepath,
|
|
301
|
-
padding,
|
|
302
|
-
formattedTimestamp,
|
|
303
|
-
formattedLevel,
|
|
304
|
-
instance,
|
|
305
|
-
message,
|
|
306
|
-
context,
|
|
307
|
-
error
|
|
308
|
-
];
|
|
309
|
-
};
|
|
310
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
311
|
-
return [
|
|
312
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
313
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
314
|
-
message
|
|
315
|
-
];
|
|
316
|
-
};
|
|
317
|
-
var formatter = DEFAULT_FORMATTER;
|
|
318
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
319
|
-
const { level, message, meta, error } = entry;
|
|
320
|
-
if (!shouldLog(entry, config.filters)) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const parts = {
|
|
324
|
-
level,
|
|
325
|
-
message,
|
|
326
|
-
error,
|
|
327
|
-
path: void 0,
|
|
328
|
-
line: void 0,
|
|
329
|
-
scope: void 0,
|
|
330
|
-
context: void 0
|
|
331
|
-
};
|
|
332
|
-
if (meta) {
|
|
333
|
-
parts.path = getRelativeFilename(meta.F);
|
|
334
|
-
parts.line = meta.L;
|
|
335
|
-
parts.scope = meta.S;
|
|
336
|
-
}
|
|
337
|
-
const context = getContextFromEntry(entry);
|
|
338
|
-
if (context) {
|
|
339
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
340
|
-
depth: config.options.depth,
|
|
341
|
-
colors: true,
|
|
342
|
-
maxArrayLength: 8,
|
|
343
|
-
sorted: false
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
347
|
-
console.log(line);
|
|
348
|
-
};
|
|
160
|
+
// src/platform/index.ts
|
|
161
|
+
var platform_exports = {};
|
|
162
|
+
__reExport(platform_exports, platform_star);
|
|
163
|
+
import * as platform_star from "#platform";
|
|
349
164
|
|
|
350
|
-
// src/processors/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
+
});
|
|
355
174
|
|
|
356
175
|
// src/processors/browser-processor.ts
|
|
357
|
-
import {
|
|
358
|
-
var getRelativeFilename2 = (filename) => {
|
|
359
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
360
|
-
if (match) {
|
|
361
|
-
const [, filePath] = match;
|
|
362
|
-
return filePath;
|
|
363
|
-
}
|
|
364
|
-
return filename;
|
|
365
|
-
};
|
|
176
|
+
import { safariCheck } from "@dxos/util";
|
|
366
177
|
var CONFIG = {
|
|
367
178
|
useTestProcessor: false,
|
|
368
179
|
printFileLinks: false
|
|
@@ -373,18 +184,20 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
373
184
|
}
|
|
374
185
|
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
375
186
|
const LOG_BROWSER_CSS = [];
|
|
187
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
376
188
|
let link = "";
|
|
377
|
-
if (
|
|
378
|
-
const filename = getRelativeFilename2(entry.meta.F);
|
|
189
|
+
if (filename !== void 0 && lineNumber !== void 0) {
|
|
379
190
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
380
|
-
link = `${filepath}#L${
|
|
191
|
+
link = `${filepath}#L${lineNumber}`;
|
|
381
192
|
}
|
|
382
193
|
let args = [];
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const scopeName = scope.name ||
|
|
386
|
-
|
|
387
|
-
|
|
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
|
+
}
|
|
388
201
|
}
|
|
389
202
|
if (entry.message) {
|
|
390
203
|
args.push(entry.message);
|
|
@@ -392,9 +205,9 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
392
205
|
const context = getContextFromEntry(entry);
|
|
393
206
|
if (context) {
|
|
394
207
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
395
|
-
args.push(context.error);
|
|
208
|
+
args.push(unwrapEffectError(context.error));
|
|
396
209
|
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
397
|
-
args.push(context.err);
|
|
210
|
+
args.push(unwrapEffectError(context.err));
|
|
398
211
|
} else {
|
|
399
212
|
args.push(context);
|
|
400
213
|
}
|
|
@@ -429,10 +242,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
429
242
|
if (!shouldLog(entry, config.filters)) {
|
|
430
243
|
return;
|
|
431
244
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
435
|
-
}
|
|
245
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
246
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
436
247
|
let args = [];
|
|
437
248
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
438
249
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -459,11 +270,27 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
459
270
|
}
|
|
460
271
|
};
|
|
461
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
|
+
};
|
|
462
290
|
|
|
463
291
|
// src/processors/file-processor.ts
|
|
464
292
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
465
293
|
import { dirname } from "node:path";
|
|
466
|
-
import { jsonlogify } from "@dxos/util";
|
|
467
294
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
468
295
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
469
296
|
let fd;
|
|
@@ -484,15 +311,12 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
484
311
|
fd = openSync(pathOrFd, "a");
|
|
485
312
|
}
|
|
486
313
|
const record = {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
} : {},
|
|
495
|
-
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
|
|
496
320
|
};
|
|
497
321
|
let retryTS = 0;
|
|
498
322
|
while (true) {
|
|
@@ -531,13 +355,13 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
531
355
|
|
|
532
356
|
// src/options.ts
|
|
533
357
|
var processors = {
|
|
534
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
358
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
535
359
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
536
360
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
537
361
|
};
|
|
538
|
-
var browser = typeof window !== "undefined" || typeof navigator !== "undefined";
|
|
362
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
539
363
|
var DEFAULT_PROCESSORS = [
|
|
540
|
-
browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
|
|
364
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
541
365
|
];
|
|
542
366
|
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
543
367
|
var parseFilter = (filter) => {
|
|
@@ -565,7 +389,7 @@ var createConfig = (options) => {
|
|
|
565
389
|
filter: process.env.LOG_FILTER,
|
|
566
390
|
processor: process.env.LOG_PROCESSOR
|
|
567
391
|
} : void 0;
|
|
568
|
-
const mergedOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
|
|
392
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
569
393
|
return {
|
|
570
394
|
options: mergedOptions,
|
|
571
395
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
@@ -591,13 +415,14 @@ var createLog = () => {
|
|
|
591
415
|
get: () => log2._config
|
|
592
416
|
});
|
|
593
417
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
594
|
-
|
|
418
|
+
const entry = new LogEntry({
|
|
595
419
|
level,
|
|
596
420
|
message,
|
|
597
421
|
context,
|
|
598
422
|
meta,
|
|
599
423
|
error
|
|
600
|
-
})
|
|
424
|
+
});
|
|
425
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
601
426
|
};
|
|
602
427
|
Object.assign(log2, {
|
|
603
428
|
/**
|
|
@@ -605,7 +430,7 @@ var createLog = () => {
|
|
|
605
430
|
* NOTE: Preserves any processors that were already added to this logger instance
|
|
606
431
|
* unless an explicit processor option is provided.
|
|
607
432
|
*/
|
|
608
|
-
config: ({ processor, ...options }) => {
|
|
433
|
+
config: ({ processor, ...options } = {}) => {
|
|
609
434
|
const config = createConfig(options);
|
|
610
435
|
const processors2 = processor ? config.processors : log2._config.processors;
|
|
611
436
|
log2._config = {
|
|
@@ -659,11 +484,88 @@ var debug = (label, args) => {
|
|
|
659
484
|
};
|
|
660
485
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
661
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
|
+
|
|
662
566
|
// src/experimental/ownership.ts
|
|
663
|
-
import { inspect as
|
|
664
|
-
var
|
|
665
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
666
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
567
|
+
import { inspect as inspect3 } from "node:util";
|
|
568
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
667
569
|
var OwnershipScope = class {
|
|
668
570
|
constr;
|
|
669
571
|
parent;
|
|
@@ -683,7 +585,7 @@ var OwnershipScope = class {
|
|
|
683
585
|
}
|
|
684
586
|
return info;
|
|
685
587
|
}
|
|
686
|
-
[
|
|
588
|
+
[inspect3.custom]() {
|
|
687
589
|
return {
|
|
688
590
|
className: this.constr.name,
|
|
689
591
|
info: this.getInfo(),
|
|
@@ -694,15 +596,15 @@ var OwnershipScope = class {
|
|
|
694
596
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
695
597
|
export {
|
|
696
598
|
BROWSER_PROCESSOR,
|
|
697
|
-
CONSOLE_PROCESSOR,
|
|
698
599
|
DEBUG_PROCESSOR,
|
|
699
|
-
DEFAULT_FORMATTER,
|
|
700
600
|
FILE_PROCESSOR,
|
|
601
|
+
LogBuffer,
|
|
602
|
+
LogEntry,
|
|
701
603
|
LogLevel,
|
|
702
604
|
LogProcessorType,
|
|
703
|
-
SHORT_FORMATTER,
|
|
704
605
|
createFileProcessor,
|
|
705
606
|
createLog,
|
|
607
|
+
dbg,
|
|
706
608
|
debug,
|
|
707
609
|
gatherLogInfoFromScope,
|
|
708
610
|
getContextFromEntry,
|
|
@@ -715,7 +617,6 @@ export {
|
|
|
715
617
|
parseFilter,
|
|
716
618
|
pick,
|
|
717
619
|
shortLevelName,
|
|
718
|
-
shouldLog
|
|
719
|
-
truncate
|
|
620
|
+
shouldLog
|
|
720
621
|
};
|
|
721
622
|
//# sourceMappingURL=index.mjs.map
|