@dxos/log 0.10.0 → 0.11.0
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/chunk-context.mjs +307 -0
- package/dist/lib/chunk-context.mjs.map +1 -0
- package/dist/lib/index.mjs +619 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/platform/browser.mjs +18 -0
- package/dist/lib/platform/browser.mjs.map +1 -0
- package/dist/lib/platform/node.mjs +18 -0
- package/dist/lib/platform/node.mjs.map +1 -0
- package/dist/lib/processors/console-processor.mjs +86 -0
- package/dist/lib/processors/console-processor.mjs.map +1 -0
- package/dist/lib/processors/console-stub.mjs +6 -0
- package/dist/lib/processors/console-stub.mjs.map +1 -0
- package/dist/lib/processors/file-processor.mjs +62 -0
- package/dist/lib/processors/file-processor.mjs.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/registry.d.ts +28 -0
- package/dist/types/src/registry.d.ts.map +1 -0
- package/dist/types/src/registry.test.d.ts +2 -0
- package/dist/types/src/registry.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -18
- package/src/context.ts +32 -3
- package/src/index.ts +1 -0
- package/src/platform/browser/index.ts +2 -2
- package/src/registry.test.ts +56 -0
- package/src/registry.ts +63 -0
- package/dist/lib/browser/chunk-ALZAGDFJ.mjs +0 -311
- package/dist/lib/browser/chunk-ALZAGDFJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +0 -23
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -667
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/platform/browser/index.mjs +0 -26
- package/dist/lib/browser/platform/browser/index.mjs.map +0 -7
- package/dist/lib/browser/platform/node/index.mjs +0 -21
- package/dist/lib/browser/platform/node/index.mjs.map +0 -7
- package/dist/lib/browser/processors/console-processor.mjs +0 -102
- package/dist/lib/browser/processors/console-processor.mjs.map +0 -7
- package/dist/lib/browser/processors/console-stub.mjs +0 -9
- package/dist/lib/browser/processors/console-stub.mjs.map +0 -7
- package/dist/lib/browser/processors/file-processor.mjs +0 -75
- package/dist/lib/browser/processors/file-processor.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +0 -24
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RKEZ3A6V.mjs +0 -313
- package/dist/lib/node-esm/chunk-RKEZ3A6V.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -668
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +0 -27
- package/dist/lib/node-esm/platform/browser/index.mjs.map +0 -7
- package/dist/lib/node-esm/platform/node/index.mjs +0 -22
- package/dist/lib/node-esm/platform/node/index.mjs.map +0 -7
- package/dist/lib/node-esm/processors/console-processor.mjs +0 -103
- package/dist/lib/node-esm/processors/console-processor.mjs.map +0 -7
- package/dist/lib/node-esm/processors/console-stub.mjs +0 -10
- package/dist/lib/node-esm/processors/console-stub.mjs.map +0 -7
- package/dist/lib/node-esm/processors/file-processor.mjs +0 -76
- package/dist/lib/node-esm/processors/file-processor.mjs.map +0 -7
|
@@ -1,668 +0,0 @@
|
|
|
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-RKEZ3A6V.mjs";
|
|
14
|
-
import {
|
|
15
|
-
__export,
|
|
16
|
-
__reExport
|
|
17
|
-
} from "./chunk-2SZHAWBN.mjs";
|
|
18
|
-
|
|
19
|
-
// src/index.ts
|
|
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";
|
|
49
|
-
|
|
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);
|
|
61
|
-
}
|
|
62
|
-
return suffix;
|
|
63
|
-
}
|
|
64
|
-
return Math.random().toString(36).slice(2, 2 + SUFFIX_LENGTH).padEnd(SUFFIX_LENGTH, "0");
|
|
65
|
-
};
|
|
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;
|
|
74
|
-
}
|
|
75
|
-
const suffix = randomSuffix();
|
|
76
|
-
session.setItem(TAB_SUFFIX_STORAGE_KEY, suffix);
|
|
77
|
-
return suffix;
|
|
78
|
-
} catch {
|
|
79
|
-
return randomSuffix();
|
|
80
|
-
}
|
|
81
|
-
};
|
|
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()}`;
|
|
97
|
-
}
|
|
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()}`;
|
|
111
|
-
};
|
|
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;
|
|
129
|
-
}
|
|
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 {
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
return JSON.stringify(record);
|
|
148
|
-
} catch {
|
|
149
|
-
return void 0;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// src/decorators.ts
|
|
154
|
-
import chalk from "chalk";
|
|
155
|
-
import { inspect } from "node:util";
|
|
156
|
-
var nextPromiseId = 0;
|
|
157
|
-
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
158
|
-
const method = descriptor.value;
|
|
159
|
-
const methodName = propertyKey;
|
|
160
|
-
descriptor.value = function(...args) {
|
|
161
|
-
const combinedMeta = {
|
|
162
|
-
F: "",
|
|
163
|
-
L: 0,
|
|
164
|
-
...meta ?? {},
|
|
165
|
-
S: this
|
|
166
|
-
};
|
|
167
|
-
const formattedArgs = args.map((arg) => inspect(arg, false, 1, true)).join(", ");
|
|
168
|
-
try {
|
|
169
|
-
const startTime = performance.now();
|
|
170
|
-
const result = method.apply(this, args);
|
|
171
|
-
if (isThenable(result)) {
|
|
172
|
-
const id = nextPromiseId++;
|
|
173
|
-
logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
|
|
174
|
-
result.then((resolvedValue) => {
|
|
175
|
-
logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
|
|
176
|
-
}, (err) => {
|
|
177
|
-
logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
|
|
178
|
-
});
|
|
179
|
-
} else {
|
|
180
|
-
logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
} catch (err) {
|
|
184
|
-
logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
|
|
185
|
-
throw err;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
Object.defineProperty(descriptor.value, "name", {
|
|
189
|
-
value: methodName + "$log"
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
var createFunctionLogDecorator = (log2) => (name, fn, opts = {}) => {
|
|
193
|
-
const decoratedFn = function(...args) {
|
|
194
|
-
const combinedMeta = {
|
|
195
|
-
F: "",
|
|
196
|
-
L: 0
|
|
197
|
-
};
|
|
198
|
-
const formattedArgs = args.map((arg) => inspect(arg, false, 1, true)).join(", ");
|
|
199
|
-
try {
|
|
200
|
-
const startTime = performance.now();
|
|
201
|
-
const result = fn.apply(this, args);
|
|
202
|
-
let transformedResult = result;
|
|
203
|
-
if (opts.transformOutput) {
|
|
204
|
-
if (isThenable(result)) {
|
|
205
|
-
transformedResult = result.then(opts.transformOutput);
|
|
206
|
-
} else {
|
|
207
|
-
transformedResult = opts.transformOutput(result);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (isThenable(transformedResult)) {
|
|
211
|
-
const id = nextPromiseId++;
|
|
212
|
-
logAsyncBegin(log2, name, formattedArgs, id, combinedMeta);
|
|
213
|
-
transformedResult.then((resolvedValue) => {
|
|
214
|
-
logAsyncResolved(log2, name, resolvedValue, id, startTime, combinedMeta);
|
|
215
|
-
}, (err) => {
|
|
216
|
-
logAsyncRejected(log2, name, err, id, startTime, combinedMeta);
|
|
217
|
-
});
|
|
218
|
-
} else {
|
|
219
|
-
logSyncCall(log2, name, formattedArgs, transformedResult, combinedMeta);
|
|
220
|
-
}
|
|
221
|
-
return result;
|
|
222
|
-
} catch (err) {
|
|
223
|
-
logSyncError(log2, name, formattedArgs, err, combinedMeta);
|
|
224
|
-
throw err;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
Object.defineProperty(decoratedFn, "name", {
|
|
228
|
-
value: name + "$log"
|
|
229
|
-
});
|
|
230
|
-
return decoratedFn;
|
|
231
|
-
};
|
|
232
|
-
var isThenable = (obj) => obj && typeof obj.then === "function";
|
|
233
|
-
var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
|
|
234
|
-
log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray("=>")} ${inspect(result, false, 1, true)}`, {}, combinedMeta);
|
|
235
|
-
};
|
|
236
|
-
var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
|
|
237
|
-
log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
|
|
238
|
-
};
|
|
239
|
-
var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
|
|
240
|
-
log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${chalk.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
|
|
241
|
-
};
|
|
242
|
-
var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
|
|
243
|
-
if (resolvedValue !== void 0) {
|
|
244
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${inspect(resolvedValue, false, 1, true)}`, {}, combinedMeta);
|
|
245
|
-
} else {
|
|
246
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
250
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
251
|
-
};
|
|
252
|
-
var COLOR_FUNCTION = [
|
|
253
|
-
220,
|
|
254
|
-
220,
|
|
255
|
-
170
|
|
256
|
-
];
|
|
257
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
258
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
259
|
-
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
260
|
-
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
261
|
-
|
|
262
|
-
// src/options.ts
|
|
263
|
-
import defaultsDeep from "lodash.defaultsdeep";
|
|
264
|
-
|
|
265
|
-
// src/platform/index.ts
|
|
266
|
-
var platform_exports = {};
|
|
267
|
-
__reExport(platform_exports, platform_star);
|
|
268
|
-
import * as platform_star from "#platform";
|
|
269
|
-
|
|
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
|
-
});
|
|
277
|
-
|
|
278
|
-
// src/processors/browser-processor.ts
|
|
279
|
-
import { safariCheck } from "@dxos/util";
|
|
280
|
-
var CONFIG = {
|
|
281
|
-
useTestProcessor: false,
|
|
282
|
-
printFileLinks: false
|
|
283
|
-
};
|
|
284
|
-
var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
285
|
-
if (!shouldLog(entry, config.filters)) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
289
|
-
const LOG_BROWSER_CSS = [];
|
|
290
|
-
const { filename, line: lineNumber, context: scopeDebugName } = entry.computedMeta;
|
|
291
|
-
let link = "";
|
|
292
|
-
if (filename !== void 0 && lineNumber !== void 0) {
|
|
293
|
-
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
294
|
-
link = `${filepath}#L${lineNumber}`;
|
|
295
|
-
}
|
|
296
|
-
let args = [];
|
|
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
|
-
}
|
|
304
|
-
}
|
|
305
|
-
if (entry.message) {
|
|
306
|
-
args.push(entry.message);
|
|
307
|
-
}
|
|
308
|
-
const context = getContextFromEntry(entry);
|
|
309
|
-
if (context) {
|
|
310
|
-
if (Object.keys(context).length === 1 && "error" in context) {
|
|
311
|
-
args.push(unwrapEffectError(context.error));
|
|
312
|
-
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
313
|
-
args.push(unwrapEffectError(context.err));
|
|
314
|
-
} else {
|
|
315
|
-
args.push(context);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
const levels2 = {
|
|
319
|
-
[LogLevel.ERROR]: console.error.bind(console),
|
|
320
|
-
[LogLevel.WARN]: console.warn.bind(console),
|
|
321
|
-
[LogLevel.DEBUG]: console.log.bind(console)
|
|
322
|
-
};
|
|
323
|
-
if (CONFIG.printFileLinks || safariCheck()) {
|
|
324
|
-
if (LOG_BROWSER_CSS?.length) {
|
|
325
|
-
args = [
|
|
326
|
-
`%c${link}
|
|
327
|
-
%c${args.join(" ")}`,
|
|
328
|
-
...LOG_BROWSER_CSS
|
|
329
|
-
];
|
|
330
|
-
} else {
|
|
331
|
-
args = [
|
|
332
|
-
link + "\n",
|
|
333
|
-
...args
|
|
334
|
-
];
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const level = levels2[entry.level] ?? console.log.bind(console);
|
|
338
|
-
if (typeof entry.meta?.C === "function") {
|
|
339
|
-
entry.meta.C(level, args);
|
|
340
|
-
} else {
|
|
341
|
-
level(...args);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
345
|
-
if (!shouldLog(entry, config.filters)) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const { filename, line: lineNumber } = entry.computedMeta;
|
|
349
|
-
const path = filename !== void 0 && lineNumber !== void 0 ? `${filename}:${lineNumber}` : "";
|
|
350
|
-
let args = [];
|
|
351
|
-
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
352
|
-
args.push(`${processPrefix}${entry.message}`);
|
|
353
|
-
const context = getContextFromEntry(entry);
|
|
354
|
-
if (context) {
|
|
355
|
-
args.push(context);
|
|
356
|
-
}
|
|
357
|
-
const levels2 = {
|
|
358
|
-
[LogLevel.ERROR]: console.error,
|
|
359
|
-
[LogLevel.WARN]: console.warn,
|
|
360
|
-
[LogLevel.DEBUG]: console.log
|
|
361
|
-
};
|
|
362
|
-
if (CONFIG.printFileLinks) {
|
|
363
|
-
args = [
|
|
364
|
-
path,
|
|
365
|
-
...args
|
|
366
|
-
];
|
|
367
|
-
}
|
|
368
|
-
const level = levels2[entry.level] ?? console.log;
|
|
369
|
-
if (typeof entry.meta?.C === "function") {
|
|
370
|
-
entry.meta.C(level, args);
|
|
371
|
-
} else {
|
|
372
|
-
level(...args);
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
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;
|
|
382
|
-
};
|
|
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));
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// src/options.ts
|
|
395
|
-
var processors = {
|
|
396
|
-
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
397
|
-
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
398
|
-
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
399
|
-
};
|
|
400
|
-
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
401
|
-
var DEFAULT_PROCESSORS = [
|
|
402
|
-
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
403
|
-
];
|
|
404
|
-
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
405
|
-
var parseFilter = (filter) => {
|
|
406
|
-
if (typeof filter === "number") {
|
|
407
|
-
return [
|
|
408
|
-
{
|
|
409
|
-
level: filter
|
|
410
|
-
}
|
|
411
|
-
];
|
|
412
|
-
}
|
|
413
|
-
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
414
|
-
return lines.map((filter2) => {
|
|
415
|
-
const [pattern, level] = filter2.split(":");
|
|
416
|
-
return level ? {
|
|
417
|
-
level: parseLogLevel(level),
|
|
418
|
-
pattern
|
|
419
|
-
} : {
|
|
420
|
-
level: parseLogLevel(pattern)
|
|
421
|
-
};
|
|
422
|
-
});
|
|
423
|
-
};
|
|
424
|
-
var createConfig = (options) => {
|
|
425
|
-
const envOptions = "process" in globalThis ? {
|
|
426
|
-
file: process.env.LOG_CONFIG,
|
|
427
|
-
filter: process.env.LOG_FILTER,
|
|
428
|
-
processor: process.env.LOG_PROCESSOR
|
|
429
|
-
} : void 0;
|
|
430
|
-
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
431
|
-
return {
|
|
432
|
-
options: mergedOptions,
|
|
433
|
-
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
434
|
-
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
435
|
-
processors: mergedOptions.processor ? [
|
|
436
|
-
processors[mergedOptions.processor]
|
|
437
|
-
] : [
|
|
438
|
-
...DEFAULT_PROCESSORS
|
|
439
|
-
],
|
|
440
|
-
prefix: mergedOptions.prefix
|
|
441
|
-
};
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// src/log.ts
|
|
445
|
-
var logCount = 0;
|
|
446
|
-
var createLog = () => {
|
|
447
|
-
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
448
|
-
Object.assign(log2, {
|
|
449
|
-
_id: `log-${++logCount}`,
|
|
450
|
-
_config: createConfig()
|
|
451
|
-
});
|
|
452
|
-
Object.defineProperty(log2, "runtimeConfig", {
|
|
453
|
-
get: () => log2._config
|
|
454
|
-
});
|
|
455
|
-
const processLog = (level, message, context = {}, meta, error) => {
|
|
456
|
-
const entry = new LogEntry({
|
|
457
|
-
level,
|
|
458
|
-
message,
|
|
459
|
-
context,
|
|
460
|
-
meta,
|
|
461
|
-
error
|
|
462
|
-
});
|
|
463
|
-
log2._config.processors.forEach((processor) => processor(log2._config, entry));
|
|
464
|
-
};
|
|
465
|
-
Object.assign(log2, {
|
|
466
|
-
/**
|
|
467
|
-
* Update config.
|
|
468
|
-
* NOTE: Preserves any processors that were already added to this logger instance
|
|
469
|
-
* unless an explicit processor option is provided.
|
|
470
|
-
*/
|
|
471
|
-
config: ({ processor, ...options } = {}) => {
|
|
472
|
-
const config = createConfig(options);
|
|
473
|
-
const processors2 = processor ? config.processors : log2._config.processors;
|
|
474
|
-
log2._config = {
|
|
475
|
-
...config,
|
|
476
|
-
processors: processors2
|
|
477
|
-
};
|
|
478
|
-
return log2;
|
|
479
|
-
},
|
|
480
|
-
/**
|
|
481
|
-
* Adds a processor to the logger.
|
|
482
|
-
*/
|
|
483
|
-
addProcessor: (processor) => {
|
|
484
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
485
|
-
log2._config.processors.push(processor);
|
|
486
|
-
}
|
|
487
|
-
return () => {
|
|
488
|
-
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
489
|
-
};
|
|
490
|
-
},
|
|
491
|
-
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
492
|
-
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
493
|
-
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
494
|
-
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
495
|
-
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
496
|
-
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
497
|
-
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
498
|
-
method: createMethodLogDecorator(log2),
|
|
499
|
-
function: createFunctionLogDecorator(log2),
|
|
500
|
-
break: () => log2.info("-".repeat(80)),
|
|
501
|
-
stack: (message, context, meta) => {
|
|
502
|
-
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
503
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
return log2;
|
|
507
|
-
};
|
|
508
|
-
var log = globalThis.DX_LOG ??= createLog();
|
|
509
|
-
var start = Date.now();
|
|
510
|
-
var last = start;
|
|
511
|
-
var debug = (label, args) => {
|
|
512
|
-
const now = Date.now();
|
|
513
|
-
const err = new Error();
|
|
514
|
-
console.group(`DEBUG[${label}]`, JSON.stringify({
|
|
515
|
-
t: Number(now - start).toLocaleString(),
|
|
516
|
-
dt: Number(now - last).toLocaleString(),
|
|
517
|
-
...args
|
|
518
|
-
}));
|
|
519
|
-
console.warn(err.stack);
|
|
520
|
-
console.groupEnd();
|
|
521
|
-
last = Date.now();
|
|
522
|
-
};
|
|
523
|
-
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
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
|
-
|
|
610
|
-
// src/experimental/ownership.ts
|
|
611
|
-
import { inspect as inspect3 } from "node:util";
|
|
612
|
-
var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
|
|
613
|
-
var OwnershipScope = class {
|
|
614
|
-
constr;
|
|
615
|
-
parent;
|
|
616
|
-
instance;
|
|
617
|
-
constructor(constr, parent) {
|
|
618
|
-
this.constr = constr;
|
|
619
|
-
this.parent = parent;
|
|
620
|
-
}
|
|
621
|
-
getInfo() {
|
|
622
|
-
if (!this.instance) {
|
|
623
|
-
return {};
|
|
624
|
-
}
|
|
625
|
-
const props = this.constr.prototype[kDebugInfoProperties] ?? [];
|
|
626
|
-
const info = {};
|
|
627
|
-
for (const prop of props) {
|
|
628
|
-
info[prop] = this.instance[prop];
|
|
629
|
-
}
|
|
630
|
-
return info;
|
|
631
|
-
}
|
|
632
|
-
[inspect3.custom]() {
|
|
633
|
-
return {
|
|
634
|
-
className: this.constr.name,
|
|
635
|
-
info: this.getInfo(),
|
|
636
|
-
parent: this.parent
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
641
|
-
export {
|
|
642
|
-
BROWSER_PROCESSOR,
|
|
643
|
-
DEBUG_PROCESSOR,
|
|
644
|
-
LOG_META_MARKER,
|
|
645
|
-
LogBuffer,
|
|
646
|
-
LogEntry,
|
|
647
|
-
LogLevel,
|
|
648
|
-
LogProcessorType,
|
|
649
|
-
createLog,
|
|
650
|
-
dbg,
|
|
651
|
-
debug,
|
|
652
|
-
gatherLogInfoFromScope,
|
|
653
|
-
getContextFromEntry,
|
|
654
|
-
getCurrentOwnershipScope,
|
|
655
|
-
getRelativeFilename,
|
|
656
|
-
inferEnvironmentName,
|
|
657
|
-
isLogMeta,
|
|
658
|
-
levels,
|
|
659
|
-
log,
|
|
660
|
-
logInfo,
|
|
661
|
-
omit,
|
|
662
|
-
parseFilter,
|
|
663
|
-
pick,
|
|
664
|
-
serializeToJsonl,
|
|
665
|
-
shortLevelName,
|
|
666
|
-
shouldLog
|
|
667
|
-
};
|
|
668
|
-
//# sourceMappingURL=index.mjs.map
|