@dxos/log 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
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 +356 -223
- 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 +357 -311
- 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 +28 -27
- package/src/processors/console-processor.ts +5 -13
- package/src/processors/file-processor.ts +9 -9
- package/src/processors/index.ts +3 -3
|
@@ -1,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,7 +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));
|
|
315
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
316
|
+
args.push(unwrapEffectError(context.err));
|
|
283
317
|
} else {
|
|
284
318
|
args.push(context);
|
|
285
319
|
}
|
|
@@ -314,10 +348,8 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
314
348
|
if (!shouldLog(entry, config.filters)) {
|
|
315
349
|
return;
|
|
316
350
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;
|
|
320
|
-
}
|
|
351
|
+
const { filename, line: lineNumber } = entry.computedMeta;
|
|
352
|
+
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
321
353
|
let args = [];
|
|
322
354
|
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
323
355
|
args.push(`${processPrefix}${entry.message}`);
|
|
@@ -344,23 +376,27 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
344
376
|
}
|
|
345
377
|
};
|
|
346
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
|
+
};
|
|
347
386
|
|
|
348
|
-
// src/processors/
|
|
349
|
-
|
|
350
|
-
import
|
|
351
|
-
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";
|
|
352
390
|
|
|
353
|
-
// src/processors/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const [, filePath] = match;
|
|
358
|
-
return filePath;
|
|
359
|
-
}
|
|
360
|
-
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));
|
|
361
395
|
};
|
|
362
396
|
|
|
363
397
|
// src/processors/file-processor.ts
|
|
398
|
+
import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
|
|
399
|
+
import { dirname } from "@dxos/node-std/path";
|
|
364
400
|
var EAGAIN_MAX_DURATION = 1e3;
|
|
365
401
|
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
366
402
|
let fd;
|
|
@@ -381,15 +417,12 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
381
417
|
fd = openSync(pathOrFd, "a");
|
|
382
418
|
}
|
|
383
419
|
const record = {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
} : {},
|
|
392
|
-
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
|
|
393
426
|
};
|
|
394
427
|
let retryTS = 0;
|
|
395
428
|
while (true) {
|
|
@@ -413,7 +446,7 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
|
413
446
|
};
|
|
414
447
|
var logFilePath;
|
|
415
448
|
var getLogFilePath = () => {
|
|
416
|
-
logFilePath
|
|
449
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
417
450
|
return logFilePath;
|
|
418
451
|
};
|
|
419
452
|
var FILE_PROCESSOR = createFileProcessor({
|
|
@@ -428,14 +461,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
428
461
|
|
|
429
462
|
// src/options.ts
|
|
430
463
|
var processors = {
|
|
431
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
464
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
432
465
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
433
466
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
434
467
|
};
|
|
435
|
-
var
|
|
468
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
436
469
|
var DEFAULT_PROCESSORS = [
|
|
437
|
-
|
|
470
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
438
471
|
];
|
|
472
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
439
473
|
var parseFilter = (filter) => {
|
|
440
474
|
if (typeof filter === "number") {
|
|
441
475
|
return [
|
|
@@ -444,7 +478,6 @@ var parseFilter = (filter) => {
|
|
|
444
478
|
}
|
|
445
479
|
];
|
|
446
480
|
}
|
|
447
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
448
481
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
449
482
|
return lines.map((filter2) => {
|
|
450
483
|
const [pattern, level] = filter2.split(":");
|
|
@@ -456,67 +489,91 @@ var parseFilter = (filter) => {
|
|
|
456
489
|
};
|
|
457
490
|
});
|
|
458
491
|
};
|
|
459
|
-
var
|
|
460
|
-
const
|
|
492
|
+
var createConfig = (options) => {
|
|
493
|
+
const envOptions = "process" in globalThis ? {
|
|
461
494
|
file: process.env.LOG_CONFIG,
|
|
462
495
|
filter: process.env.LOG_FILTER,
|
|
463
496
|
processor: process.env.LOG_PROCESSOR
|
|
464
497
|
} : void 0;
|
|
465
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
498
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
466
499
|
return {
|
|
467
500
|
options: mergedOptions,
|
|
468
501
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
469
502
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
470
503
|
processors: mergedOptions.processor ? [
|
|
471
504
|
processors[mergedOptions.processor]
|
|
472
|
-
] :
|
|
505
|
+
] : [
|
|
506
|
+
...DEFAULT_PROCESSORS
|
|
507
|
+
],
|
|
473
508
|
prefix: mergedOptions.prefix
|
|
474
509
|
};
|
|
475
510
|
};
|
|
476
511
|
|
|
477
512
|
// src/log.ts
|
|
478
|
-
var
|
|
513
|
+
var logCount = 0;
|
|
479
514
|
var createLog = () => {
|
|
480
515
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
481
|
-
log2
|
|
516
|
+
Object.assign(log2, {
|
|
517
|
+
_id: `log-${++logCount}`,
|
|
518
|
+
_config: createConfig()
|
|
519
|
+
});
|
|
482
520
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
483
521
|
get: () => log2._config
|
|
484
522
|
});
|
|
485
|
-
log2.addProcessor = (processor) => {
|
|
486
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
487
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
488
|
-
}
|
|
489
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
490
|
-
log2._config.processors.push(processor);
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
log2.config = (options) => {
|
|
494
|
-
log2._config = getConfig(options);
|
|
495
|
-
};
|
|
496
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
497
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
498
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
499
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
500
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
501
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
502
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
503
|
-
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");
|
|
504
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
505
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
506
|
-
log2.method = createMethodLogDecorator(log2);
|
|
507
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
508
523
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
509
|
-
|
|
524
|
+
const entry = new LogEntry({
|
|
510
525
|
level,
|
|
511
526
|
message,
|
|
512
527
|
context,
|
|
513
528
|
meta,
|
|
514
529
|
error
|
|
515
|
-
})
|
|
530
|
+
});
|
|
531
|
+
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
516
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
|
+
});
|
|
517
574
|
return log2;
|
|
518
575
|
};
|
|
519
|
-
var log =
|
|
576
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
520
577
|
var start = Date.now();
|
|
521
578
|
var last = start;
|
|
522
579
|
var debug = (label, args) => {
|
|
@@ -533,26 +590,102 @@ var debug = (label, args) => {
|
|
|
533
590
|
};
|
|
534
591
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
535
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
|
+
|
|
536
678
|
// src/experimental/ownership.ts
|
|
537
679
|
import { inspect as inspect3 } from "@dxos/node-std/util";
|
|
538
|
-
|
|
539
|
-
if (key in obj) {
|
|
540
|
-
Object.defineProperty(obj, key, {
|
|
541
|
-
value,
|
|
542
|
-
enumerable: true,
|
|
543
|
-
configurable: true,
|
|
544
|
-
writable: true
|
|
545
|
-
});
|
|
546
|
-
} else {
|
|
547
|
-
obj[key] = value;
|
|
548
|
-
}
|
|
549
|
-
return obj;
|
|
550
|
-
}
|
|
551
|
-
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
552
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
553
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
554
|
-
var _inspect_custom = inspect3.custom;
|
|
680
|
+
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
555
681
|
var OwnershipScope = class {
|
|
682
|
+
constr;
|
|
683
|
+
parent;
|
|
684
|
+
instance;
|
|
685
|
+
constructor(constr, parent) {
|
|
686
|
+
this.constr = constr;
|
|
687
|
+
this.parent = parent;
|
|
688
|
+
}
|
|
556
689
|
getInfo() {
|
|
557
690
|
if (!this.instance) {
|
|
558
691
|
return {};
|
|
@@ -564,41 +697,41 @@ var OwnershipScope = class {
|
|
|
564
697
|
}
|
|
565
698
|
return info;
|
|
566
699
|
}
|
|
567
|
-
[
|
|
700
|
+
[inspect3.custom]() {
|
|
568
701
|
return {
|
|
569
702
|
className: this.constr.name,
|
|
570
703
|
info: this.getInfo(),
|
|
571
704
|
parent: this.parent
|
|
572
705
|
};
|
|
573
706
|
}
|
|
574
|
-
constructor(constr, parent) {
|
|
575
|
-
_define_property(this, "constr", void 0);
|
|
576
|
-
_define_property(this, "parent", void 0);
|
|
577
|
-
_define_property(this, "instance", void 0);
|
|
578
|
-
this.constr = constr;
|
|
579
|
-
this.parent = parent;
|
|
580
|
-
}
|
|
581
707
|
};
|
|
582
708
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
583
709
|
export {
|
|
584
710
|
BROWSER_PROCESSOR,
|
|
585
|
-
CONSOLE_PROCESSOR,
|
|
586
711
|
DEBUG_PROCESSOR,
|
|
587
712
|
FILE_PROCESSOR,
|
|
713
|
+
LOG_META_MARKER,
|
|
714
|
+
LogBuffer,
|
|
715
|
+
LogEntry,
|
|
588
716
|
LogLevel,
|
|
589
717
|
LogProcessorType,
|
|
590
718
|
createFileProcessor,
|
|
719
|
+
createLog,
|
|
720
|
+
dbg,
|
|
591
721
|
debug,
|
|
592
722
|
gatherLogInfoFromScope,
|
|
593
723
|
getContextFromEntry,
|
|
594
724
|
getCurrentOwnershipScope,
|
|
595
|
-
|
|
725
|
+
getRelativeFilename,
|
|
726
|
+
inferEnvironmentName,
|
|
727
|
+
isLogMeta,
|
|
596
728
|
levels,
|
|
597
729
|
log,
|
|
598
730
|
logInfo,
|
|
599
731
|
omit,
|
|
600
732
|
parseFilter,
|
|
601
733
|
pick,
|
|
734
|
+
serializeToJsonl,
|
|
602
735
|
shortLevelName,
|
|
603
736
|
shouldLog
|
|
604
737
|
};
|