@dxos/log 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/chunk-V7FYKT4H.mjs +311 -0
- package/dist/lib/browser/chunk-V7FYKT4H.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +278 -244
- 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/browser/processors/file-processor.mjs +75 -0
- package/dist/lib/browser/processors/file-processor.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-5TBDXMQF.mjs +313 -0
- package/dist/lib/node-esm/chunk-5TBDXMQF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +280 -333
- 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/lib/node-esm/processors/file-processor.mjs +76 -0
- package/dist/lib/node-esm/processors/file-processor.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/environment.d.ts +24 -0
- package/dist/types/src/environment.d.ts.map +1 -0
- package/dist/types/src/environment.test.d.ts +2 -0
- package/dist/types/src/environment.test.d.ts.map +1 -0
- package/dist/types/src/experimental/ownership.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +7 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/jsonl.d.ts +53 -0
- package/dist/types/src/jsonl.d.ts.map +1 -0
- package/dist/types/src/jsonl.test.d.ts +2 -0
- package/dist/types/src/jsonl.test.d.ts.map +1 -0
- package/dist/types/src/log-buffer.d.ts +20 -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 +44 -1
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +20 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/browser/index.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/common.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 +2 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/src/scope.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -17
- package/src/context.ts +242 -2
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +1 -2
- package/src/environment.test.ts +222 -0
- package/src/environment.ts +129 -0
- package/src/experimental/classes.test.ts +0 -1
- package/src/index.ts +7 -4
- package/src/jsonl.test.ts +121 -0
- package/src/jsonl.ts +104 -0
- package/src/log-buffer.test.ts +158 -0
- package/src/log-buffer.ts +89 -0
- package/src/log.test.ts +0 -1
- package/src/log.ts +56 -12
- package/src/meta.ts +29 -1
- 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 +2 -3
|
@@ -1,123 +1,158 @@
|
|
|
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-5TBDXMQF.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
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
|
|
35
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
36
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
37
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
38
|
-
return LogProcessorType2;
|
|
39
|
-
})({});
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
23
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
24
|
+
LOG_META_MARKER: () => LOG_META_MARKER,
|
|
25
|
+
LogBuffer: () => LogBuffer,
|
|
26
|
+
LogEntry: () => LogEntry,
|
|
27
|
+
LogLevel: () => LogLevel,
|
|
28
|
+
LogProcessorType: () => LogProcessorType,
|
|
29
|
+
createLog: () => createLog,
|
|
30
|
+
dbg: () => dbg,
|
|
31
|
+
debug: () => debug,
|
|
32
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
33
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
34
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
35
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
36
|
+
inferEnvironmentName: () => inferEnvironmentName,
|
|
37
|
+
isLogMeta: () => isLogMeta,
|
|
38
|
+
levels: () => levels,
|
|
39
|
+
log: () => log,
|
|
40
|
+
logInfo: () => logInfo,
|
|
41
|
+
omit: () => omit,
|
|
42
|
+
parseFilter: () => parseFilter,
|
|
43
|
+
pick: () => pick,
|
|
44
|
+
serializeToJsonl: () => serializeToJsonl,
|
|
45
|
+
shortLevelName: () => shortLevelName,
|
|
46
|
+
shouldLog: () => shouldLog
|
|
47
|
+
});
|
|
48
|
+
import { omit, pick } from "@dxos/util";
|
|
40
49
|
|
|
41
|
-
// src/
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
50
|
+
// src/environment.ts
|
|
51
|
+
var TAB_SUFFIX_STORAGE_KEY = "@dxos/log:env-suffix";
|
|
52
|
+
var SUFFIX_LENGTH = 6;
|
|
53
|
+
var randomSuffix = () => {
|
|
54
|
+
const cryptoRef = globalThis.crypto;
|
|
55
|
+
if (cryptoRef?.getRandomValues) {
|
|
56
|
+
const bytes = new Uint8Array(SUFFIX_LENGTH);
|
|
57
|
+
cryptoRef.getRandomValues(bytes);
|
|
58
|
+
let suffix = "";
|
|
59
|
+
for (const byte of bytes) {
|
|
60
|
+
suffix += (byte % 36).toString(36);
|
|
58
61
|
}
|
|
62
|
+
return suffix;
|
|
59
63
|
}
|
|
60
|
-
return
|
|
64
|
+
return Math.random().toString(36).slice(2, 2 + SUFFIX_LENGTH).padEnd(SUFFIX_LENGTH, "0");
|
|
61
65
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
}
|
|
66
|
+
var getOrCreateTabSuffix = (session) => {
|
|
67
|
+
if (!session) {
|
|
68
|
+
return randomSuffix();
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const existing = session.getItem(TAB_SUFFIX_STORAGE_KEY);
|
|
72
|
+
if (existing && existing.length > 0) {
|
|
73
|
+
return existing;
|
|
80
74
|
}
|
|
75
|
+
const suffix = randomSuffix();
|
|
76
|
+
session.setItem(TAB_SUFFIX_STORAGE_KEY, suffix);
|
|
77
|
+
return suffix;
|
|
78
|
+
} catch {
|
|
79
|
+
return randomSuffix();
|
|
81
80
|
}
|
|
82
81
|
};
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
var isInstanceOf = (scope, ctorName) => {
|
|
83
|
+
const ctor = scope?.[ctorName];
|
|
84
|
+
return typeof ctor === "function" && scope instanceof ctor;
|
|
85
|
+
};
|
|
86
|
+
var CF_WORKER_USER_AGENT = "Cloudflare-Workers";
|
|
87
|
+
var inferEnvironmentName = (options = {}) => {
|
|
88
|
+
const scope = options.scope ?? globalThis;
|
|
89
|
+
if (scope.navigator?.userAgent === CF_WORKER_USER_AGENT) {
|
|
90
|
+
return `cf-worker::${randomSuffix()}`;
|
|
91
|
+
}
|
|
92
|
+
if (isInstanceOf(scope, "SharedWorkerGlobalScope")) {
|
|
93
|
+
return `shared-worker:${scope.name ?? ""}:${randomSuffix()}`;
|
|
94
|
+
}
|
|
95
|
+
if (isInstanceOf(scope, "ServiceWorkerGlobalScope")) {
|
|
96
|
+
return `service-worker::${randomSuffix()}`;
|
|
86
97
|
}
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
if (isInstanceOf(scope, "DedicatedWorkerGlobalScope")) {
|
|
99
|
+
return `dedicated-worker:${scope.name ?? ""}:${randomSuffix()}`;
|
|
100
|
+
}
|
|
101
|
+
if (scope.window !== void 0 && scope.window === scope) {
|
|
102
|
+
const origin = scope.location?.origin ?? "";
|
|
103
|
+
return `tab:${origin}:${getOrCreateTabSuffix(scope.sessionStorage)}`;
|
|
104
|
+
}
|
|
105
|
+
const proc = scope.process;
|
|
106
|
+
if (proc && typeof proc === "object" && proc.versions?.node) {
|
|
107
|
+
const pid = typeof proc.pid === "number" ? String(proc.pid) : "";
|
|
108
|
+
return `node:${pid}:${randomSuffix()}`;
|
|
109
|
+
}
|
|
110
|
+
return `unknown::${randomSuffix()}`;
|
|
89
111
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
|
|
113
|
+
// src/jsonl.ts
|
|
114
|
+
var serializeToJsonl = (entry, opts = {}) => {
|
|
115
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
const { filename, line, context: scopeName } = entry.computedMeta;
|
|
119
|
+
const record = {
|
|
120
|
+
t: new Date(entry.timestamp).toISOString(),
|
|
121
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
122
|
+
m: entry.message ?? ""
|
|
123
|
+
};
|
|
124
|
+
if (filename !== void 0) {
|
|
125
|
+
record.f = filename;
|
|
126
|
+
}
|
|
127
|
+
if (line !== void 0) {
|
|
128
|
+
record.n = line;
|
|
97
129
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
130
|
+
if (scopeName !== void 0) {
|
|
131
|
+
record.o = scopeName;
|
|
132
|
+
}
|
|
133
|
+
if (entry.computedError !== void 0) {
|
|
134
|
+
record.e = entry.computedError;
|
|
135
|
+
}
|
|
136
|
+
if (opts.env !== void 0) {
|
|
137
|
+
record.i = opts.env;
|
|
138
|
+
}
|
|
139
|
+
const computedContext = entry.computedContext;
|
|
140
|
+
if (Object.keys(computedContext).length > 0) {
|
|
141
|
+
try {
|
|
142
|
+
record.c = JSON.stringify(computedContext);
|
|
143
|
+
} catch {
|
|
108
144
|
}
|
|
109
145
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
146
|
+
try {
|
|
147
|
+
return JSON.stringify(record);
|
|
148
|
+
} catch {
|
|
149
|
+
return void 0;
|
|
114
150
|
}
|
|
115
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
116
151
|
};
|
|
117
152
|
|
|
118
153
|
// src/decorators.ts
|
|
119
|
-
import { inspect } from "node:util";
|
|
120
154
|
import chalk from "chalk";
|
|
155
|
+
import { inspect } from "node:util";
|
|
121
156
|
var nextPromiseId = 0;
|
|
122
157
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
123
158
|
const method = descriptor.value;
|
|
@@ -227,142 +262,21 @@ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
|
227
262
|
// src/options.ts
|
|
228
263
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
229
264
|
|
|
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
|
-
};
|
|
265
|
+
// src/platform/index.ts
|
|
266
|
+
var platform_exports = {};
|
|
267
|
+
__reExport(platform_exports, platform_star);
|
|
268
|
+
import * as platform_star from "#platform";
|
|
349
269
|
|
|
350
|
-
// src/processors/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
270
|
+
// src/processors/index.ts
|
|
271
|
+
var processors_exports = {};
|
|
272
|
+
__export(processors_exports, {
|
|
273
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
274
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
275
|
+
getRelativeFilename: () => getRelativeFilename
|
|
276
|
+
});
|
|
355
277
|
|
|
356
278
|
// 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
|
-
};
|
|
279
|
+
import { safariCheck } from "@dxos/util";
|
|
366
280
|
var CONFIG = {
|
|
367
281
|
useTestProcessor: false,
|
|
368
282
|
printFileLinks: false
|
|
@@ -373,18 +287,20 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
373
287
|
}
|
|
374
288
|
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
375
289
|
const LOG_BROWSER_CSS = [];
|
|
290
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
376
291
|
let link = "";
|
|
377
|
-
if (
|
|
378
|
-
const filename = getRelativeFilename2(entry.meta.F);
|
|
292
|
+
if (filename !== void 0 && lineNumber !== void 0) {
|
|
379
293
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
380
|
-
link = `${filepath}#L${
|
|
294
|
+
link = `${filepath}#L${lineNumber}`;
|
|
381
295
|
}
|
|
382
296
|
let args = [];
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const scopeName = scope.name ||
|
|
386
|
-
|
|
387
|
-
|
|
297
|
+
const scope = entry.meta?.S;
|
|
298
|
+
if (scope) {
|
|
299
|
+
const scopeName = scope.name || scopeDebugName;
|
|
300
|
+
if (scopeName) {
|
|
301
|
+
const processPrefix = scope.hostSessionId ? "[worker] " : "";
|
|
302
|
+
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
303
|
+
}
|
|
388
304
|
}
|
|
389
305
|
if (entry.message) {
|
|
390
306
|
args.push(entry.message);
|
|
@@ -392,9 +308,9 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
392
308
|
const context = getContextFromEntry(entry);
|
|
393
309
|
if (context) {
|
|
394
310
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
395
|
-
args.push(context.error);
|
|
311
|
+
args.push(unwrapEffectError(context.error));
|
|
396
312
|
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
397
|
-
args.push(context.err);
|
|
313
|
+
args.push(unwrapEffectError(context.err));
|
|
398
314
|
} else {
|
|
399
315
|
args.push(context);
|
|
400
316
|
}
|
|
@@ -429,10 +345,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
429
345
|
if (!shouldLog(entry, config.filters)) {
|
|
430
346
|
return;
|
|
431
347
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
435
|
-
}
|
|
348
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
349
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
436
350
|
let args = [];
|
|
437
351
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
438
352
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -459,85 +373,33 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
459
373
|
}
|
|
460
374
|
};
|
|
461
375
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
469
|
-
let fd;
|
|
470
|
-
return (config, entry) => {
|
|
471
|
-
if (levels2.length > 0 && !levels2.includes(entry.level)) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
if (!shouldLog(entry, filters)) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
if (typeof pathOrFd === "number") {
|
|
478
|
-
fd = pathOrFd;
|
|
479
|
-
} else {
|
|
480
|
-
try {
|
|
481
|
-
mkdirSync(dirname(pathOrFd));
|
|
482
|
-
} catch {
|
|
483
|
-
}
|
|
484
|
-
fd = openSync(pathOrFd, "a");
|
|
485
|
-
}
|
|
486
|
-
const record = {
|
|
487
|
-
...entry,
|
|
488
|
-
timestamp: Date.now(),
|
|
489
|
-
...entry.meta ? {
|
|
490
|
-
meta: {
|
|
491
|
-
file: getRelativeFilename(entry.meta.F),
|
|
492
|
-
line: entry.meta.L
|
|
493
|
-
}
|
|
494
|
-
} : {},
|
|
495
|
-
context: jsonlogify(getContextFromEntry(entry))
|
|
496
|
-
};
|
|
497
|
-
let retryTS = 0;
|
|
498
|
-
while (true) {
|
|
499
|
-
try {
|
|
500
|
-
return appendFileSync(fd, JSON.stringify(record) + "\n");
|
|
501
|
-
} catch (err) {
|
|
502
|
-
if (err.code !== "EAGAIN") {
|
|
503
|
-
throw err;
|
|
504
|
-
}
|
|
505
|
-
if (retryTS === 0) {
|
|
506
|
-
retryTS = performance.now();
|
|
507
|
-
} else {
|
|
508
|
-
if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
|
|
509
|
-
console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
|
|
510
|
-
throw err;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
};
|
|
376
|
+
var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
|
|
377
|
+
var unwrapEffectError = (error) => {
|
|
378
|
+
if (typeof error === "object" && error !== null && originalSymbol in error) {
|
|
379
|
+
return error[originalSymbol];
|
|
380
|
+
}
|
|
381
|
+
return error;
|
|
516
382
|
};
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
383
|
+
|
|
384
|
+
// src/processors/index.ts
|
|
385
|
+
__reExport(processors_exports, console_processor_star);
|
|
386
|
+
import * as console_processor_star from "#console-processor";
|
|
387
|
+
|
|
388
|
+
// src/processors/debug-processor.ts
|
|
389
|
+
import { inspect as inspect2 } from "node:util";
|
|
390
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
391
|
+
console.log(inspect2(entry, false, null, true));
|
|
521
392
|
};
|
|
522
|
-
var FILE_PROCESSOR = createFileProcessor({
|
|
523
|
-
pathOrFd: getLogFilePath(),
|
|
524
|
-
levels: [
|
|
525
|
-
LogLevel.ERROR,
|
|
526
|
-
LogLevel.WARN,
|
|
527
|
-
LogLevel.INFO,
|
|
528
|
-
LogLevel.TRACE
|
|
529
|
-
]
|
|
530
|
-
});
|
|
531
393
|
|
|
532
394
|
// src/options.ts
|
|
533
395
|
var processors = {
|
|
534
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
396
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
535
397
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
536
398
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
537
399
|
};
|
|
538
|
-
var browser = typeof window !== "undefined" || typeof navigator !== "undefined";
|
|
400
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
539
401
|
var DEFAULT_PROCESSORS = [
|
|
540
|
-
browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
|
|
402
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
541
403
|
];
|
|
542
404
|
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
543
405
|
var parseFilter = (filter) => {
|
|
@@ -565,7 +427,7 @@ var createConfig = (options) => {
|
|
|
565
427
|
filter: process.env.LOG_FILTER,
|
|
566
428
|
processor: process.env.LOG_PROCESSOR
|
|
567
429
|
} : void 0;
|
|
568
|
-
const mergedOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
|
|
430
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
569
431
|
return {
|
|
570
432
|
options: mergedOptions,
|
|
571
433
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
@@ -591,13 +453,14 @@ var createLog = () => {
|
|
|
591
453
|
get: () => log2._config
|
|
592
454
|
});
|
|
593
455
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
594
|
-
|
|
456
|
+
const entry = new LogEntry({
|
|
595
457
|
level,
|
|
596
458
|
message,
|
|
597
459
|
context,
|
|
598
460
|
meta,
|
|
599
461
|
error
|
|
600
|
-
})
|
|
462
|
+
});
|
|
463
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
601
464
|
};
|
|
602
465
|
Object.assign(log2, {
|
|
603
466
|
/**
|
|
@@ -605,7 +468,7 @@ var createLog = () => {
|
|
|
605
468
|
* NOTE: Preserves any processors that were already added to this logger instance
|
|
606
469
|
* unless an explicit processor option is provided.
|
|
607
470
|
*/
|
|
608
|
-
config: ({ processor, ...options }) => {
|
|
471
|
+
config: ({ processor, ...options } = {}) => {
|
|
609
472
|
const config = createConfig(options);
|
|
610
473
|
const processors2 = processor ? config.processors : log2._config.processors;
|
|
611
474
|
log2._config = {
|
|
@@ -659,11 +522,94 @@ var debug = (label, args) => {
|
|
|
659
522
|
};
|
|
660
523
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
661
524
|
|
|
525
|
+
// src/index.ts
|
|
526
|
+
__reExport(index_exports, processors_exports);
|
|
527
|
+
|
|
528
|
+
// src/meta.ts
|
|
529
|
+
var LOG_META_MARKER = "~LogMeta";
|
|
530
|
+
var isLogMeta = (value) => {
|
|
531
|
+
return value != null && typeof value === "object" && value[LOG_META_MARKER] === LOG_META_MARKER;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/dbg.ts
|
|
535
|
+
var dbg = (arg, meta) => {
|
|
536
|
+
if (meta?.A) {
|
|
537
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
538
|
+
} else {
|
|
539
|
+
console.log(arg);
|
|
540
|
+
}
|
|
541
|
+
return arg;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/log-buffer.ts
|
|
545
|
+
import { CircularBuffer } from "@dxos/util";
|
|
546
|
+
var DEFAULT_BUFFER_SIZE = 2e3;
|
|
547
|
+
var MAX_CONTEXT_LENGTH = 500;
|
|
548
|
+
var LogBuffer = class {
|
|
549
|
+
_buffer;
|
|
550
|
+
constructor(size = DEFAULT_BUFFER_SIZE) {
|
|
551
|
+
this._buffer = new CircularBuffer(size);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Log processor that can be registered with `log.runtimeConfig.processors`.
|
|
555
|
+
* Captures every level except TRACE (does not apply `shouldLog` / filter; use for full debug dumps).
|
|
556
|
+
*/
|
|
557
|
+
logProcessor = (_config, entry) => {
|
|
558
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const { filename, line, context: scopeName } = entry.computedMeta;
|
|
562
|
+
const record = {
|
|
563
|
+
t: new Date(entry.timestamp).toISOString(),
|
|
564
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
565
|
+
m: entry.message ?? ""
|
|
566
|
+
};
|
|
567
|
+
if (filename !== void 0) {
|
|
568
|
+
record.f = filename;
|
|
569
|
+
}
|
|
570
|
+
if (line !== void 0) {
|
|
571
|
+
record.n = line;
|
|
572
|
+
}
|
|
573
|
+
if (scopeName !== void 0) {
|
|
574
|
+
record.o = scopeName;
|
|
575
|
+
}
|
|
576
|
+
if (entry.computedError !== void 0) {
|
|
577
|
+
record.e = entry.computedError;
|
|
578
|
+
}
|
|
579
|
+
const computedContext = entry.computedContext;
|
|
580
|
+
if (Object.keys(computedContext).length > 0) {
|
|
581
|
+
try {
|
|
582
|
+
let json = JSON.stringify(computedContext);
|
|
583
|
+
if (json.length > MAX_CONTEXT_LENGTH) {
|
|
584
|
+
json = json.slice(0, MAX_CONTEXT_LENGTH);
|
|
585
|
+
}
|
|
586
|
+
record.c = json;
|
|
587
|
+
} catch {
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
this._buffer.push(record);
|
|
591
|
+
};
|
|
592
|
+
/** Number of entries currently in the buffer. */
|
|
593
|
+
get size() {
|
|
594
|
+
return this._buffer.elementCount;
|
|
595
|
+
}
|
|
596
|
+
/** Discard all buffered entries. */
|
|
597
|
+
clear() {
|
|
598
|
+
this._buffer.clear();
|
|
599
|
+
}
|
|
600
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
601
|
+
serialize() {
|
|
602
|
+
const lines = [];
|
|
603
|
+
for (const record of this._buffer) {
|
|
604
|
+
lines.push(JSON.stringify(record));
|
|
605
|
+
}
|
|
606
|
+
return lines.join("\n");
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
662
610
|
// src/experimental/ownership.ts
|
|
663
|
-
import { inspect as
|
|
664
|
-
var
|
|
665
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
666
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
611
|
+
import { inspect as inspect3 } from "node:util";
|
|
612
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
667
613
|
var OwnershipScope = class {
|
|
668
614
|
constr;
|
|
669
615
|
parent;
|
|
@@ -683,7 +629,7 @@ var OwnershipScope = class {
|
|
|
683
629
|
}
|
|
684
630
|
return info;
|
|
685
631
|
}
|
|
686
|
-
[
|
|
632
|
+
[inspect3.custom]() {
|
|
687
633
|
return {
|
|
688
634
|
className: this.constr.name,
|
|
689
635
|
info: this.getInfo(),
|
|
@@ -694,28 +640,29 @@ var OwnershipScope = class {
|
|
|
694
640
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
695
641
|
export {
|
|
696
642
|
BROWSER_PROCESSOR,
|
|
697
|
-
CONSOLE_PROCESSOR,
|
|
698
643
|
DEBUG_PROCESSOR,
|
|
699
|
-
|
|
700
|
-
|
|
644
|
+
LOG_META_MARKER,
|
|
645
|
+
LogBuffer,
|
|
646
|
+
LogEntry,
|
|
701
647
|
LogLevel,
|
|
702
648
|
LogProcessorType,
|
|
703
|
-
SHORT_FORMATTER,
|
|
704
|
-
createFileProcessor,
|
|
705
649
|
createLog,
|
|
650
|
+
dbg,
|
|
706
651
|
debug,
|
|
707
652
|
gatherLogInfoFromScope,
|
|
708
653
|
getContextFromEntry,
|
|
709
654
|
getCurrentOwnershipScope,
|
|
710
655
|
getRelativeFilename,
|
|
656
|
+
inferEnvironmentName,
|
|
657
|
+
isLogMeta,
|
|
711
658
|
levels,
|
|
712
659
|
log,
|
|
713
660
|
logInfo,
|
|
714
661
|
omit,
|
|
715
662
|
parseFilter,
|
|
716
663
|
pick,
|
|
664
|
+
serializeToJsonl,
|
|
717
665
|
shortLevelName,
|
|
718
|
-
shouldLog
|
|
719
|
-
truncate
|
|
666
|
+
shouldLog
|
|
720
667
|
};
|
|
721
668
|
//# sourceMappingURL=index.mjs.map
|