@dxos/log 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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-V7FYKT4H.mjs +311 -0
- package/dist/lib/browser/chunk-V7FYKT4H.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +355 -224
- 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-5TBDXMQF.mjs +313 -0
- package/dist/lib/node-esm/chunk-5TBDXMQF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +356 -312
- 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.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/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 +55 -18
- 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 +1 -6
- 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 +3 -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 +30 -15
- package/src/config.ts +1 -0
- package/src/context.ts +278 -7
- package/src/dbg.ts +34 -0
- package/src/decorators.ts +4 -5
- 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 +48 -19
- package/src/log.ts +146 -58
- package/src/meta.ts +29 -1
- 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 +27 -28
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +9 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,105 +1,159 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
LogEntry,
|
|
3
|
+
LogLevel,
|
|
4
|
+
LogProcessorType,
|
|
5
|
+
gatherLogInfoFromScope,
|
|
6
|
+
getContextFromEntry,
|
|
7
|
+
getRelativeFilename,
|
|
8
|
+
levels,
|
|
9
|
+
logInfo,
|
|
10
|
+
shortLevelName,
|
|
11
|
+
shouldLog
|
|
12
|
+
} from "./chunk-V7FYKT4H.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__export,
|
|
15
|
+
__reExport
|
|
16
|
+
} from "./chunk-IEP6GGEX.mjs";
|
|
4
17
|
|
|
5
|
-
// src/
|
|
6
|
-
var
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
// src/index.ts
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
22
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
23
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
24
|
+
LOG_META_MARKER: () => LOG_META_MARKER,
|
|
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
|
+
inferEnvironmentName: () => inferEnvironmentName,
|
|
38
|
+
isLogMeta: () => isLogMeta,
|
|
39
|
+
levels: () => levels,
|
|
40
|
+
log: () => log,
|
|
41
|
+
logInfo: () => logInfo,
|
|
42
|
+
omit: () => omit,
|
|
43
|
+
parseFilter: () => parseFilter,
|
|
44
|
+
pick: () => pick,
|
|
45
|
+
serializeToJsonl: () => serializeToJsonl,
|
|
46
|
+
shortLevelName: () => shortLevelName,
|
|
47
|
+
shouldLog: () => shouldLog
|
|
48
|
+
});
|
|
49
|
+
import { omit, pick } from "@dxos/util";
|
|
37
50
|
|
|
38
|
-
// src/
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
// src/environment.ts
|
|
52
|
+
var TAB_SUFFIX_STORAGE_KEY = "@dxos/log:env-suffix";
|
|
53
|
+
var SUFFIX_LENGTH = 6;
|
|
54
|
+
var randomSuffix = () => {
|
|
55
|
+
const cryptoRef = globalThis.crypto;
|
|
56
|
+
if (cryptoRef?.getRandomValues) {
|
|
57
|
+
const bytes = new Uint8Array(SUFFIX_LENGTH);
|
|
58
|
+
cryptoRef.getRandomValues(bytes);
|
|
59
|
+
let suffix = "";
|
|
60
|
+
for (const byte of bytes) {
|
|
61
|
+
suffix += (byte % 36).toString(36);
|
|
62
|
+
}
|
|
63
|
+
return suffix;
|
|
64
|
+
}
|
|
65
|
+
return Math.random().toString(36).slice(2, 2 + SUFFIX_LENGTH).padEnd(SUFFIX_LENGTH, "0");
|
|
43
66
|
};
|
|
44
|
-
var
|
|
45
|
-
if (!
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
54
|
-
} catch (err) {
|
|
55
|
-
res[prop] = err.message;
|
|
67
|
+
var getOrCreateTabSuffix = (session) => {
|
|
68
|
+
if (!session) {
|
|
69
|
+
return randomSuffix();
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const existing = session.getItem(TAB_SUFFIX_STORAGE_KEY);
|
|
73
|
+
if (existing && existing.length > 0) {
|
|
74
|
+
return existing;
|
|
56
75
|
}
|
|
76
|
+
const suffix = randomSuffix();
|
|
77
|
+
session.setItem(TAB_SUFFIX_STORAGE_KEY, suffix);
|
|
78
|
+
return suffix;
|
|
79
|
+
} catch {
|
|
80
|
+
return randomSuffix();
|
|
57
81
|
}
|
|
58
|
-
return res;
|
|
59
82
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
83
|
+
var isInstanceOf = (scope, ctorName) => {
|
|
84
|
+
const ctor = scope?.[ctorName];
|
|
85
|
+
return typeof ctor === "function" && scope instanceof ctor;
|
|
64
86
|
};
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
87
|
+
var CF_WORKER_USER_AGENT = "Cloudflare-Workers";
|
|
88
|
+
var inferEnvironmentName = (options = {}) => {
|
|
89
|
+
const scope = options.scope ?? globalThis;
|
|
90
|
+
if (scope.navigator?.userAgent === CF_WORKER_USER_AGENT) {
|
|
91
|
+
return `cf-worker::${randomSuffix()}`;
|
|
92
|
+
}
|
|
93
|
+
if (isInstanceOf(scope, "SharedWorkerGlobalScope")) {
|
|
94
|
+
return `shared-worker:${scope.name ?? ""}:${randomSuffix()}`;
|
|
95
|
+
}
|
|
96
|
+
if (isInstanceOf(scope, "ServiceWorkerGlobalScope")) {
|
|
97
|
+
return `service-worker::${randomSuffix()}`;
|
|
98
|
+
}
|
|
99
|
+
if (isInstanceOf(scope, "DedicatedWorkerGlobalScope")) {
|
|
100
|
+
return `dedicated-worker:${scope.name ?? ""}:${randomSuffix()}`;
|
|
70
101
|
}
|
|
102
|
+
if (scope.window !== void 0 && scope.window === scope) {
|
|
103
|
+
const origin = scope.location?.origin ?? "";
|
|
104
|
+
return `tab:${origin}:${getOrCreateTabSuffix(scope.sessionStorage)}`;
|
|
105
|
+
}
|
|
106
|
+
const proc = scope.process;
|
|
107
|
+
if (proc && typeof proc === "object" && proc.versions?.node) {
|
|
108
|
+
const pid = typeof proc.pid === "number" ? String(proc.pid) : "";
|
|
109
|
+
return `node:${pid}:${randomSuffix()}`;
|
|
110
|
+
}
|
|
111
|
+
return `unknown::${randomSuffix()}`;
|
|
71
112
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
113
|
+
|
|
114
|
+
// src/jsonl.ts
|
|
115
|
+
var serializeToJsonl = (entry, opts = {}) => {
|
|
116
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
const { filename, line, context: scopeName } = entry.computedMeta;
|
|
120
|
+
const record = {
|
|
121
|
+
t: new Date(entry.timestamp).toISOString(),
|
|
122
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
123
|
+
m: entry.message ?? ""
|
|
124
|
+
};
|
|
125
|
+
if (filename !== void 0) {
|
|
126
|
+
record.f = filename;
|
|
127
|
+
}
|
|
128
|
+
if (line !== void 0) {
|
|
129
|
+
record.n = line;
|
|
79
130
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
131
|
+
if (scopeName !== void 0) {
|
|
132
|
+
record.o = scopeName;
|
|
133
|
+
}
|
|
134
|
+
if (entry.computedError !== void 0) {
|
|
135
|
+
record.e = entry.computedError;
|
|
136
|
+
}
|
|
137
|
+
if (opts.env !== void 0) {
|
|
138
|
+
record.i = opts.env;
|
|
139
|
+
}
|
|
140
|
+
const computedContext = entry.computedContext;
|
|
141
|
+
if (Object.keys(computedContext).length > 0) {
|
|
142
|
+
try {
|
|
143
|
+
record.c = JSON.stringify(computedContext);
|
|
144
|
+
} catch {
|
|
90
145
|
}
|
|
91
146
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
147
|
+
try {
|
|
148
|
+
return JSON.stringify(record);
|
|
149
|
+
} catch {
|
|
150
|
+
return void 0;
|
|
96
151
|
}
|
|
97
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
98
152
|
};
|
|
99
153
|
|
|
100
154
|
// src/decorators.ts
|
|
101
|
-
import { inspect } from "@dxos/node-std/util";
|
|
102
155
|
import chalk from "chalk";
|
|
156
|
+
import { inspect } from "@dxos/node-std/util";
|
|
103
157
|
var nextPromiseId = 0;
|
|
104
158
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
105
159
|
const method = descriptor.value;
|
|
@@ -196,60 +250,36 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
196
250
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
197
251
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
198
252
|
};
|
|
199
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
200
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
201
253
|
var COLOR_FUNCTION = [
|
|
202
254
|
220,
|
|
203
255
|
220,
|
|
204
256
|
170
|
|
205
257
|
];
|
|
258
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
259
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
206
260
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
207
261
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
208
262
|
|
|
209
263
|
// src/options.ts
|
|
210
264
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
211
265
|
|
|
212
|
-
// src/platform/
|
|
213
|
-
var
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (typeof localStorage === "undefined") {
|
|
217
|
-
if (globalThis.localStorage_dxlog) {
|
|
218
|
-
dxlog = globalThis.localStorage_dxlog;
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
dxlog = localStorage.getItem("dxlog") ?? void 0;
|
|
222
|
-
}
|
|
223
|
-
if (!dxlog) {
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
return JSON.parse(dxlog);
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.info("can't parse dxlog config", err);
|
|
229
|
-
return void 0;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/processors/console-stub.ts
|
|
234
|
-
var CONSOLE_PROCESSOR = () => {
|
|
235
|
-
};
|
|
266
|
+
// src/platform/index.ts
|
|
267
|
+
var platform_exports = {};
|
|
268
|
+
__reExport(platform_exports, platform_star);
|
|
269
|
+
import * as platform_star from "#platform";
|
|
236
270
|
|
|
237
|
-
// src/processors/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
271
|
+
// src/processors/index.ts
|
|
272
|
+
var processors_exports = {};
|
|
273
|
+
__export(processors_exports, {
|
|
274
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
275
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
276
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
277
|
+
createFileProcessor: () => createFileProcessor,
|
|
278
|
+
getRelativeFilename: () => getRelativeFilename
|
|
279
|
+
});
|
|
242
280
|
|
|
243
281
|
// src/processors/browser-processor.ts
|
|
244
|
-
import {
|
|
245
|
-
var getRelativeFilename = (filename) => {
|
|
246
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
247
|
-
if (match) {
|
|
248
|
-
const [, filePath] = match;
|
|
249
|
-
return filePath;
|
|
250
|
-
}
|
|
251
|
-
return filename;
|
|
252
|
-
};
|
|
282
|
+
import { safariCheck } from "@dxos/util";
|
|
253
283
|
var CONFIG = {
|
|
254
284
|
useTestProcessor: false,
|
|
255
285
|
printFileLinks: false
|
|
@@ -260,18 +290,20 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
260
290
|
}
|
|
261
291
|
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
262
292
|
const LOG_BROWSER_CSS = [];
|
|
293
|
+
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
263
294
|
let link = "";
|
|
264
|
-
if (
|
|
265
|
-
const filename = getRelativeFilename(entry.meta.F);
|
|
295
|
+
if (filename !== void 0 && lineNumber !== void 0) {
|
|
266
296
|
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
267
|
-
link = `${filepath}#L${
|
|
297
|
+
link = `${filepath}#L${lineNumber}`;
|
|
268
298
|
}
|
|
269
299
|
let args = [];
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const scopeName = scope.name ||
|
|
273
|
-
|
|
274
|
-
|
|
300
|
+
const scope = entry.meta?.S;
|
|
301
|
+
if (scope) {
|
|
302
|
+
const scopeName = scope.name || scopeDebugName;
|
|
303
|
+
if (scopeName) {
|
|
304
|
+
const processPrefix = scope.hostSessionId ? "[worker] " : "";
|
|
305
|
+
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
306
|
+
}
|
|
275
307
|
}
|
|
276
308
|
if (entry.message) {
|
|
277
309
|
args.push(entry.message);
|
|
@@ -279,9 +311,9 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
279
311
|
const context = getContextFromEntry(entry);
|
|
280
312
|
if (context) {
|
|
281
313
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
282
|
-
args.push(context.error);
|
|
314
|
+
args.push(unwrapEffectError(context.error));
|
|
283
315
|
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
284
|
-
args.push(context.err);
|
|
316
|
+
args.push(unwrapEffectError(context.err));
|
|
285
317
|
} else {
|
|
286
318
|
args.push(context);
|
|
287
319
|
}
|
|
@@ -316,10 +348,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
316
348
|
if (!shouldLog(entry, config.filters)) {
|
|
317
349
|
return;
|
|
318
350
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;
|
|
322
|
-
}
|
|
351
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
352
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
323
353
|
let args = [];
|
|
324
354
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
325
355
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -346,23 +376,27 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
346
376
|
}
|
|
347
377
|
};
|
|
348
378
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
379
|
+
var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation");
|
|
380
|
+
var unwrapEffectError = (error) => {
|
|
381
|
+
if (typeof error === "object" && error !== null && originalSymbol in error) {
|
|
382
|
+
return error[originalSymbol];
|
|
383
|
+
}
|
|
384
|
+
return error;
|
|
385
|
+
};
|
|
349
386
|
|
|
350
|
-
// src/processors/
|
|
351
|
-
|
|
352
|
-
import
|
|
353
|
-
import { jsonlogify } from "@dxos/util";
|
|
387
|
+
// src/processors/index.ts
|
|
388
|
+
__reExport(processors_exports, console_processor_star);
|
|
389
|
+
import * as console_processor_star from "#console-processor";
|
|
354
390
|
|
|
355
|
-
// src/processors/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const [, filePath] = match;
|
|
360
|
-
return filePath;
|
|
361
|
-
}
|
|
362
|
-
return filename;
|
|
391
|
+
// src/processors/debug-processor.ts
|
|
392
|
+
import { inspect as inspect2 } from "@dxos/node-std/util";
|
|
393
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
394
|
+
console.log(inspect2(entry, false, null, true));
|
|
363
395
|
};
|
|
364
396
|
|
|
365
397
|
// src/processors/file-processor.ts
|
|
398
|
+
import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
|
|
399
|
+
import { dirname } from "@dxos/node-std/path";
|
|
366
400
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
367
401
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
368
402
|
let fd;
|
|
@@ -383,15 +417,12 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
383
417
|
fd = openSync(pathOrFd, "a");
|
|
384
418
|
}
|
|
385
419
|
const record = {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
} : {},
|
|
394
|
-
context: jsonlogify(getContextFromEntry(entry))
|
|
420
|
+
level: entry.level,
|
|
421
|
+
message: entry.message,
|
|
422
|
+
timestamp: entry.timestamp,
|
|
423
|
+
meta: entry.computedMeta,
|
|
424
|
+
context: entry.computedContext,
|
|
425
|
+
error: entry.computedError
|
|
395
426
|
};
|
|
396
427
|
let retryTS = 0;
|
|
397
428
|
while (true) {
|
|
@@ -415,7 +446,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
415
446
|
};
|
|
416
447
|
var logFilePath;
|
|
417
448
|
var getLogFilePath = () => {
|
|
418
|
-
logFilePath
|
|
449
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
419
450
|
return logFilePath;
|
|
420
451
|
};
|
|
421
452
|
var FILE_PROCESSOR = createFileProcessor({
|
|
@@ -430,14 +461,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
430
461
|
|
|
431
462
|
// src/options.ts
|
|
432
463
|
var processors = {
|
|
433
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
464
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
434
465
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
435
466
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
436
467
|
};
|
|
437
|
-
var
|
|
468
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
438
469
|
var DEFAULT_PROCESSORS = [
|
|
439
|
-
|
|
470
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
440
471
|
];
|
|
472
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
441
473
|
var parseFilter = (filter) => {
|
|
442
474
|
if (typeof filter === "number") {
|
|
443
475
|
return [
|
|
@@ -446,7 +478,6 @@ var parseFilter = (filter) => {
|
|
|
446
478
|
}
|
|
447
479
|
];
|
|
448
480
|
}
|
|
449
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
450
481
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
451
482
|
return lines.map((filter2) => {
|
|
452
483
|
const [pattern, level] = filter2.split(":");
|
|
@@ -458,67 +489,91 @@ var parseFilter = (filter) => {
|
|
|
458
489
|
};
|
|
459
490
|
});
|
|
460
491
|
};
|
|
461
|
-
var
|
|
462
|
-
const
|
|
492
|
+
var createConfig = (options) => {
|
|
493
|
+
const envOptions = "process" in globalThis ? {
|
|
463
494
|
file: process.env.LOG_CONFIG,
|
|
464
495
|
filter: process.env.LOG_FILTER,
|
|
465
496
|
processor: process.env.LOG_PROCESSOR
|
|
466
497
|
} : void 0;
|
|
467
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
498
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
468
499
|
return {
|
|
469
500
|
options: mergedOptions,
|
|
470
501
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
471
502
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
472
503
|
processors: mergedOptions.processor ? [
|
|
473
504
|
processors[mergedOptions.processor]
|
|
474
|
-
] :
|
|
505
|
+
] : [
|
|
506
|
+
...DEFAULT_PROCESSORS
|
|
507
|
+
],
|
|
475
508
|
prefix: mergedOptions.prefix
|
|
476
509
|
};
|
|
477
510
|
};
|
|
478
511
|
|
|
479
512
|
// src/log.ts
|
|
480
|
-
var
|
|
513
|
+
var logCount = 0;
|
|
481
514
|
var createLog = () => {
|
|
482
515
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
483
|
-
log2
|
|
516
|
+
Object.assign(log2, {
|
|
517
|
+
_id: `log-${++logCount}`,
|
|
518
|
+
_config: createConfig()
|
|
519
|
+
});
|
|
484
520
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
485
521
|
get: () => log2._config
|
|
486
522
|
});
|
|
487
|
-
log2.addProcessor = (processor) => {
|
|
488
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
489
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
490
|
-
}
|
|
491
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
492
|
-
log2._config.processors.push(processor);
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
log2.config = (options) => {
|
|
496
|
-
log2._config = getConfig(options);
|
|
497
|
-
};
|
|
498
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
499
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
500
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
501
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
502
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
503
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
504
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
505
|
-
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");
|
|
506
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
507
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
508
|
-
log2.method = createMethodLogDecorator(log2);
|
|
509
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
510
523
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
511
|
-
|
|
524
|
+
const entry = new LogEntry({
|
|
512
525
|
level,
|
|
513
526
|
message,
|
|
514
527
|
context,
|
|
515
528
|
meta,
|
|
516
529
|
error
|
|
517
|
-
})
|
|
530
|
+
});
|
|
531
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
518
532
|
};
|
|
533
|
+
Object.assign(log2, {
|
|
534
|
+
/**
|
|
535
|
+
* Update config.
|
|
536
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
537
|
+
* unless an explicit processor option is provided.
|
|
538
|
+
*/
|
|
539
|
+
config: ({ processor, ...options } = {}) => {
|
|
540
|
+
const config = createConfig(options);
|
|
541
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
542
|
+
log2._config = {
|
|
543
|
+
...config,
|
|
544
|
+
processors: processors2
|
|
545
|
+
};
|
|
546
|
+
return log2;
|
|
547
|
+
},
|
|
548
|
+
/**
|
|
549
|
+
* Adds a processor to the logger.
|
|
550
|
+
*/
|
|
551
|
+
addProcessor: (processor) => {
|
|
552
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
553
|
+
log2._config.processors.push(processor);
|
|
554
|
+
}
|
|
555
|
+
return () => {
|
|
556
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
557
|
+
};
|
|
558
|
+
},
|
|
559
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
560
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
561
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
562
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
563
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
564
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
565
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
566
|
+
method: createMethodLogDecorator(log2),
|
|
567
|
+
function: createFunctionLogDecorator(log2),
|
|
568
|
+
break: () => log2.info("-".repeat(80)),
|
|
569
|
+
stack: (message, context, meta) => {
|
|
570
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
571
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
572
|
+
}
|
|
573
|
+
});
|
|
519
574
|
return log2;
|
|
520
575
|
};
|
|
521
|
-
var log =
|
|
576
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
522
577
|
var start = Date.now();
|
|
523
578
|
var last = start;
|
|
524
579
|
var debug = (label, args) => {
|
|
@@ -535,26 +590,102 @@ var debug = (label, args) => {
|
|
|
535
590
|
};
|
|
536
591
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
537
592
|
|
|
593
|
+
// src/index.ts
|
|
594
|
+
__reExport(index_exports, processors_exports);
|
|
595
|
+
|
|
596
|
+
// src/meta.ts
|
|
597
|
+
var LOG_META_MARKER = "~LogMeta";
|
|
598
|
+
var isLogMeta = (value) => {
|
|
599
|
+
return value != null && typeof value === "object" && value[LOG_META_MARKER] === LOG_META_MARKER;
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/dbg.ts
|
|
603
|
+
var dbg = (arg, meta) => {
|
|
604
|
+
if (meta?.A) {
|
|
605
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
606
|
+
} else {
|
|
607
|
+
console.log(arg);
|
|
608
|
+
}
|
|
609
|
+
return arg;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/log-buffer.ts
|
|
613
|
+
import { CircularBuffer } from "@dxos/util";
|
|
614
|
+
var DEFAULT_BUFFER_SIZE = 2e3;
|
|
615
|
+
var MAX_CONTEXT_LENGTH = 500;
|
|
616
|
+
var LogBuffer = class {
|
|
617
|
+
_buffer;
|
|
618
|
+
constructor(size = DEFAULT_BUFFER_SIZE) {
|
|
619
|
+
this._buffer = new CircularBuffer(size);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Log processor that can be registered with `log.runtimeConfig.processors`.
|
|
623
|
+
* Captures every level except TRACE (does not apply `shouldLog` / filter; use for full debug dumps).
|
|
624
|
+
*/
|
|
625
|
+
logProcessor = (_config, entry) => {
|
|
626
|
+
if (entry.level <= LogLevel.TRACE) {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const { filename, line, context: scopeName } = entry.computedMeta;
|
|
630
|
+
const record = {
|
|
631
|
+
t: new Date(entry.timestamp).toISOString(),
|
|
632
|
+
l: shortLevelName[entry.level] ?? "?",
|
|
633
|
+
m: entry.message ?? ""
|
|
634
|
+
};
|
|
635
|
+
if (filename !== void 0) {
|
|
636
|
+
record.f = filename;
|
|
637
|
+
}
|
|
638
|
+
if (line !== void 0) {
|
|
639
|
+
record.n = line;
|
|
640
|
+
}
|
|
641
|
+
if (scopeName !== void 0) {
|
|
642
|
+
record.o = scopeName;
|
|
643
|
+
}
|
|
644
|
+
if (entry.computedError !== void 0) {
|
|
645
|
+
record.e = entry.computedError;
|
|
646
|
+
}
|
|
647
|
+
const computedContext = entry.computedContext;
|
|
648
|
+
if (Object.keys(computedContext).length > 0) {
|
|
649
|
+
try {
|
|
650
|
+
let json = JSON.stringify(computedContext);
|
|
651
|
+
if (json.length > MAX_CONTEXT_LENGTH) {
|
|
652
|
+
json = json.slice(0, MAX_CONTEXT_LENGTH);
|
|
653
|
+
}
|
|
654
|
+
record.c = json;
|
|
655
|
+
} catch {
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
this._buffer.push(record);
|
|
659
|
+
};
|
|
660
|
+
/** Number of entries currently in the buffer. */
|
|
661
|
+
get size() {
|
|
662
|
+
return this._buffer.elementCount;
|
|
663
|
+
}
|
|
664
|
+
/** Discard all buffered entries. */
|
|
665
|
+
clear() {
|
|
666
|
+
this._buffer.clear();
|
|
667
|
+
}
|
|
668
|
+
/** Serialize buffer contents as NDJSON (newline-delimited JSON). */
|
|
669
|
+
serialize() {
|
|
670
|
+
const lines = [];
|
|
671
|
+
for (const record of this._buffer) {
|
|
672
|
+
lines.push(JSON.stringify(record));
|
|
673
|
+
}
|
|
674
|
+
return lines.join("\n");
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
538
678
|
// src/experimental/ownership.ts
|
|
539
679
|
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
540
|
-
|
|
541
|
-
if (key in obj) {
|
|
542
|
-
Object.defineProperty(obj, key, {
|
|
543
|
-
value,
|
|
544
|
-
enumerable: true,
|
|
545
|
-
configurable: true,
|
|
546
|
-
writable: true
|
|
547
|
-
});
|
|
548
|
-
} else {
|
|
549
|
-
obj[key] = value;
|
|
550
|
-
}
|
|
551
|
-
return obj;
|
|
552
|
-
}
|
|
553
|
-
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
554
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
555
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
556
|
-
var _inspect_custom = inspect3.custom;
|
|
680
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
557
681
|
var OwnershipScope = class {
|
|
682
|
+
constr;
|
|
683
|
+
parent;
|
|
684
|
+
instance;
|
|
685
|
+
constructor(constr, parent) {
|
|
686
|
+
this.constr = constr;
|
|
687
|
+
this.parent = parent;
|
|
688
|
+
}
|
|
558
689
|
getInfo() {
|
|
559
690
|
if (!this.instance) {
|
|
560
691
|
return {};
|
|
@@ -566,41 +697,41 @@ var OwnershipScope = class {
|
|
|
566
697
|
}
|
|
567
698
|
return info;
|
|
568
699
|
}
|
|
569
|
-
[
|
|
700
|
+
[inspect3.custom]() {
|
|
570
701
|
return {
|
|
571
702
|
className: this.constr.name,
|
|
572
703
|
info: this.getInfo(),
|
|
573
704
|
parent: this.parent
|
|
574
705
|
};
|
|
575
706
|
}
|
|
576
|
-
constructor(constr, parent) {
|
|
577
|
-
_define_property(this, "constr", void 0);
|
|
578
|
-
_define_property(this, "parent", void 0);
|
|
579
|
-
_define_property(this, "instance", void 0);
|
|
580
|
-
this.constr = constr;
|
|
581
|
-
this.parent = parent;
|
|
582
|
-
}
|
|
583
707
|
};
|
|
584
708
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
585
709
|
export {
|
|
586
710
|
BROWSER_PROCESSOR,
|
|
587
|
-
CONSOLE_PROCESSOR,
|
|
588
711
|
DEBUG_PROCESSOR,
|
|
589
712
|
FILE_PROCESSOR,
|
|
713
|
+
LOG_META_MARKER,
|
|
714
|
+
LogBuffer,
|
|
715
|
+
LogEntry,
|
|
590
716
|
LogLevel,
|
|
591
717
|
LogProcessorType,
|
|
592
718
|
createFileProcessor,
|
|
719
|
+
createLog,
|
|
720
|
+
dbg,
|
|
593
721
|
debug,
|
|
594
722
|
gatherLogInfoFromScope,
|
|
595
723
|
getContextFromEntry,
|
|
596
724
|
getCurrentOwnershipScope,
|
|
597
|
-
|
|
725
|
+
getRelativeFilename,
|
|
726
|
+
inferEnvironmentName,
|
|
727
|
+
isLogMeta,
|
|
598
728
|
levels,
|
|
599
729
|
log,
|
|
600
730
|
logInfo,
|
|
601
731
|
omit,
|
|
602
732
|
parseFilter,
|
|
603
733
|
pick,
|
|
734
|
+
serializeToJsonl,
|
|
604
735
|
shortLevelName,
|
|
605
736
|
shouldLog
|
|
606
737
|
};
|