@dxos/log 0.8.3 → 0.8.4-main.f9ba587
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/index.mjs +16 -16
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +16 -16
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/lib/node/index.cjs +0 -695
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/log",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.f9ba587",
|
|
4
4
|
"description": "Logger",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
36
|
"lodash.defaultsdeep": "^4.6.1",
|
|
37
37
|
"lodash.omit": "^4.5.0",
|
|
38
|
-
"@dxos/node-std": "0.8.
|
|
39
|
-
"@dxos/util": "0.8.
|
|
38
|
+
"@dxos/node-std": "0.8.4-main.f9ba587",
|
|
39
|
+
"@dxos/util": "0.8.4-main.f9ba587"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/js-yaml": "^4.0.5",
|
package/dist/lib/node/index.cjs
DELETED
|
@@ -1,695 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var node_exports = {};
|
|
30
|
-
__export(node_exports, {
|
|
31
|
-
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
32
|
-
CONSOLE_PROCESSOR: () => CONSOLE_PROCESSOR,
|
|
33
|
-
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
34
|
-
DEFAULT_FORMATTER: () => DEFAULT_FORMATTER,
|
|
35
|
-
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
36
|
-
LogLevel: () => LogLevel,
|
|
37
|
-
LogProcessorType: () => LogProcessorType,
|
|
38
|
-
SHORT_FORMATTER: () => SHORT_FORMATTER,
|
|
39
|
-
createFileProcessor: () => createFileProcessor,
|
|
40
|
-
debug: () => debug,
|
|
41
|
-
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
42
|
-
getContextFromEntry: () => getContextFromEntry,
|
|
43
|
-
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
44
|
-
getRelativeFilename: () => getRelativeFilename,
|
|
45
|
-
levels: () => levels,
|
|
46
|
-
log: () => log,
|
|
47
|
-
logInfo: () => logInfo,
|
|
48
|
-
omit: () => import_lodash.default,
|
|
49
|
-
parseFilter: () => parseFilter,
|
|
50
|
-
pick: () => import_util.pick,
|
|
51
|
-
shortLevelName: () => shortLevelName,
|
|
52
|
-
shouldLog: () => shouldLog,
|
|
53
|
-
truncate: () => truncate
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(node_exports);
|
|
56
|
-
var import_lodash = __toESM(require("lodash.omit"));
|
|
57
|
-
var import_util = require("@dxos/util");
|
|
58
|
-
var import_chalk = __toESM(require("chalk"));
|
|
59
|
-
var import_node_util = require("node:util");
|
|
60
|
-
var import_lodash2 = __toESM(require("lodash.defaultsdeep"));
|
|
61
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
62
|
-
var import_node_fs = __toESM(require("node:fs"));
|
|
63
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
64
|
-
var import_node_util2 = require("node:util");
|
|
65
|
-
var import_util2 = require("@dxos/util");
|
|
66
|
-
var import_node_util3 = require("node:util");
|
|
67
|
-
var import_util3 = require("@dxos/util");
|
|
68
|
-
var import_node_fs2 = require("node:fs");
|
|
69
|
-
var import_node_path = require("node:path");
|
|
70
|
-
var import_util4 = require("@dxos/util");
|
|
71
|
-
var import_node_util4 = require("node:util");
|
|
72
|
-
var LogLevel = /* @__PURE__ */ function(LogLevel2) {
|
|
73
|
-
LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
|
|
74
|
-
LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
|
|
75
|
-
LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
|
|
76
|
-
LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
|
|
77
|
-
LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
|
|
78
|
-
LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
|
|
79
|
-
return LogLevel2;
|
|
80
|
-
}({});
|
|
81
|
-
var levels = {
|
|
82
|
-
trace: 5,
|
|
83
|
-
debug: 10,
|
|
84
|
-
verbose: 11,
|
|
85
|
-
info: 12,
|
|
86
|
-
warn: 13,
|
|
87
|
-
error: 14
|
|
88
|
-
};
|
|
89
|
-
var shortLevelName = {
|
|
90
|
-
[5]: "T",
|
|
91
|
-
[10]: "D",
|
|
92
|
-
[11]: "V",
|
|
93
|
-
[12]: "I",
|
|
94
|
-
[13]: "W",
|
|
95
|
-
[14]: "E"
|
|
96
|
-
};
|
|
97
|
-
var LogProcessorType = /* @__PURE__ */ function(LogProcessorType2) {
|
|
98
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
99
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
100
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
101
|
-
return LogProcessorType2;
|
|
102
|
-
}({});
|
|
103
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
104
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
105
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
106
|
-
};
|
|
107
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
108
|
-
if (!scope) {
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
const res = {};
|
|
112
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
113
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
114
|
-
for (const prop of infoProps) {
|
|
115
|
-
try {
|
|
116
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
117
|
-
} catch (err) {
|
|
118
|
-
res[prop] = err.message;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return res;
|
|
122
|
-
};
|
|
123
|
-
var matchFilter = (filter, level, path) => {
|
|
124
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
125
|
-
};
|
|
126
|
-
var shouldLog = (entry, filters) => {
|
|
127
|
-
if (filters === void 0) {
|
|
128
|
-
return true;
|
|
129
|
-
} else {
|
|
130
|
-
return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var getContextFromEntry = (entry) => {
|
|
134
|
-
let context;
|
|
135
|
-
if (entry.meta) {
|
|
136
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
137
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
138
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
142
|
-
if (entryContext) {
|
|
143
|
-
if (entryContext instanceof Error) {
|
|
144
|
-
const c = entryContext.context;
|
|
145
|
-
context = Object.assign(context ?? {}, {
|
|
146
|
-
error: entryContext.stack,
|
|
147
|
-
...c
|
|
148
|
-
});
|
|
149
|
-
} else if (typeof entryContext === "object") {
|
|
150
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (entry.error) {
|
|
154
|
-
const errorContext = entry.error.context;
|
|
155
|
-
context = Object.assign(context ?? {}, {
|
|
156
|
-
error: entry.error,
|
|
157
|
-
...errorContext
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
161
|
-
};
|
|
162
|
-
var nextPromiseId = 0;
|
|
163
|
-
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
164
|
-
const method = descriptor.value;
|
|
165
|
-
const methodName = propertyKey;
|
|
166
|
-
descriptor.value = function(...args) {
|
|
167
|
-
const combinedMeta = {
|
|
168
|
-
F: "",
|
|
169
|
-
L: 0,
|
|
170
|
-
...meta ?? {},
|
|
171
|
-
S: this
|
|
172
|
-
};
|
|
173
|
-
const formattedArgs = args.map((arg) => (0, import_node_util.inspect)(arg, false, 1, true)).join(", ");
|
|
174
|
-
try {
|
|
175
|
-
const startTime = performance.now();
|
|
176
|
-
const result = method.apply(this, args);
|
|
177
|
-
if (isThenable(result)) {
|
|
178
|
-
const id = nextPromiseId++;
|
|
179
|
-
logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
|
|
180
|
-
result.then((resolvedValue) => {
|
|
181
|
-
logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
|
|
182
|
-
}, (err) => {
|
|
183
|
-
logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
} catch (err) {
|
|
190
|
-
logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
|
|
191
|
-
throw err;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
Object.defineProperty(descriptor.value, "name", {
|
|
195
|
-
value: methodName + "$log"
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
var createFunctionLogDecorator = (log2) => (name, fn, opts = {}) => {
|
|
199
|
-
const decoratedFn = function(...args) {
|
|
200
|
-
const combinedMeta = {
|
|
201
|
-
F: "",
|
|
202
|
-
L: 0
|
|
203
|
-
};
|
|
204
|
-
const formattedArgs = args.map((arg) => (0, import_node_util.inspect)(arg, false, 1, true)).join(", ");
|
|
205
|
-
try {
|
|
206
|
-
const startTime = performance.now();
|
|
207
|
-
const result = fn.apply(this, args);
|
|
208
|
-
let transformedResult = result;
|
|
209
|
-
if (opts.transformOutput) {
|
|
210
|
-
if (isThenable(result)) {
|
|
211
|
-
transformedResult = result.then(opts.transformOutput);
|
|
212
|
-
} else {
|
|
213
|
-
transformedResult = opts.transformOutput(result);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (isThenable(transformedResult)) {
|
|
217
|
-
const id = nextPromiseId++;
|
|
218
|
-
logAsyncBegin(log2, name, formattedArgs, id, combinedMeta);
|
|
219
|
-
transformedResult.then((resolvedValue) => {
|
|
220
|
-
logAsyncResolved(log2, name, resolvedValue, id, startTime, combinedMeta);
|
|
221
|
-
}, (err) => {
|
|
222
|
-
logAsyncRejected(log2, name, err, id, startTime, combinedMeta);
|
|
223
|
-
});
|
|
224
|
-
} else {
|
|
225
|
-
logSyncCall(log2, name, formattedArgs, transformedResult, combinedMeta);
|
|
226
|
-
}
|
|
227
|
-
return result;
|
|
228
|
-
} catch (err) {
|
|
229
|
-
logSyncError(log2, name, formattedArgs, err, combinedMeta);
|
|
230
|
-
throw err;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
Object.defineProperty(decoratedFn, "name", {
|
|
234
|
-
value: name + "$log"
|
|
235
|
-
});
|
|
236
|
-
return decoratedFn;
|
|
237
|
-
};
|
|
238
|
-
var isThenable = (obj) => obj && typeof obj.then === "function";
|
|
239
|
-
var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
|
|
240
|
-
log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${import_chalk.default.gray("=>")} ${(0, import_node_util.inspect)(result, false, 1, true)}`, {}, combinedMeta);
|
|
241
|
-
};
|
|
242
|
-
var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
|
|
243
|
-
log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
|
|
244
|
-
};
|
|
245
|
-
var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
|
|
246
|
-
log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${import_chalk.default.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
|
|
247
|
-
};
|
|
248
|
-
var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
|
|
249
|
-
if (resolvedValue !== void 0) {
|
|
250
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${import_chalk.default.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${import_chalk.default.gray("=>")} ${(0, import_node_util.inspect)(resolvedValue, false, 1, true)}`, {}, combinedMeta);
|
|
251
|
-
} else {
|
|
252
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${import_chalk.default.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
256
|
-
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${import_chalk.default.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${import_chalk.default.gray("=>")} ${err}`, {}, combinedMeta);
|
|
257
|
-
};
|
|
258
|
-
var greenCheck = typeof import_chalk.default.green === "function" ? import_chalk.default.green("\u2714") : "\u2714";
|
|
259
|
-
var formatTimeElapsed = (startTime) => import_chalk.default.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
260
|
-
var COLOR_FUNCTION = [
|
|
261
|
-
220,
|
|
262
|
-
220,
|
|
263
|
-
170
|
|
264
|
-
];
|
|
265
|
-
var formatFunction = (name) => import_chalk.default.bold(import_chalk.default.rgb(...COLOR_FUNCTION)(name));
|
|
266
|
-
var formatPromise = (id) => import_chalk.default.blue(`Promise#${id}`);
|
|
267
|
-
var loadOptions = (filepath) => {
|
|
268
|
-
if (filepath) {
|
|
269
|
-
try {
|
|
270
|
-
const text = import_node_fs.default.readFileSync(filepath, "utf-8");
|
|
271
|
-
if (text) {
|
|
272
|
-
return import_js_yaml.default.load(text);
|
|
273
|
-
}
|
|
274
|
-
} catch (err) {
|
|
275
|
-
console.warn(`Invalid log file: ${filepath}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var getRelativeFilename = (filename) => {
|
|
280
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
281
|
-
if (match) {
|
|
282
|
-
const [, filePath] = match;
|
|
283
|
-
return filePath;
|
|
284
|
-
}
|
|
285
|
-
return filename;
|
|
286
|
-
};
|
|
287
|
-
var LEVEL_COLORS = {
|
|
288
|
-
[LogLevel.TRACE]: "gray",
|
|
289
|
-
[LogLevel.DEBUG]: "gray",
|
|
290
|
-
[LogLevel.VERBOSE]: "gray",
|
|
291
|
-
[LogLevel.INFO]: "white",
|
|
292
|
-
[LogLevel.WARN]: "yellow",
|
|
293
|
-
[LogLevel.ERROR]: "red"
|
|
294
|
-
};
|
|
295
|
-
var truncate = (text, length = 0, right = false) => {
|
|
296
|
-
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
297
|
-
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
298
|
-
};
|
|
299
|
-
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
300
|
-
const column = config.options?.formatter?.column;
|
|
301
|
-
const filepath = path !== void 0 && line !== void 0 ? import_chalk2.default.grey(`${path}:${line}`) : void 0;
|
|
302
|
-
let instance;
|
|
303
|
-
if (scope) {
|
|
304
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
305
|
-
const id = (0, import_util2.getPrototypeSpecificInstanceId)(scope);
|
|
306
|
-
instance = import_chalk2.default.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
307
|
-
}
|
|
308
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
309
|
-
const formattedLevel = import_chalk2.default[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
310
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
311
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
312
|
-
formattedTimestamp,
|
|
313
|
-
filepath,
|
|
314
|
-
padding,
|
|
315
|
-
formattedLevel,
|
|
316
|
-
instance,
|
|
317
|
-
message,
|
|
318
|
-
context,
|
|
319
|
-
error
|
|
320
|
-
] : [
|
|
321
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
322
|
-
// Must not truncate for terminal output.
|
|
323
|
-
filepath,
|
|
324
|
-
padding,
|
|
325
|
-
formattedTimestamp,
|
|
326
|
-
formattedLevel,
|
|
327
|
-
instance,
|
|
328
|
-
message,
|
|
329
|
-
context,
|
|
330
|
-
error
|
|
331
|
-
];
|
|
332
|
-
};
|
|
333
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
334
|
-
return [
|
|
335
|
-
import_chalk2.default.grey(truncate(path, 16, true)),
|
|
336
|
-
import_chalk2.default[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
337
|
-
message
|
|
338
|
-
];
|
|
339
|
-
};
|
|
340
|
-
var formatter = DEFAULT_FORMATTER;
|
|
341
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
342
|
-
const { level, message, meta, error } = entry;
|
|
343
|
-
if (!shouldLog(entry, config.filters)) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
const parts = {
|
|
347
|
-
level,
|
|
348
|
-
message,
|
|
349
|
-
error,
|
|
350
|
-
path: void 0,
|
|
351
|
-
line: void 0,
|
|
352
|
-
scope: void 0,
|
|
353
|
-
context: void 0
|
|
354
|
-
};
|
|
355
|
-
if (meta) {
|
|
356
|
-
parts.path = getRelativeFilename(meta.F);
|
|
357
|
-
parts.line = meta.L;
|
|
358
|
-
parts.scope = meta.S;
|
|
359
|
-
}
|
|
360
|
-
const context = getContextFromEntry(entry);
|
|
361
|
-
if (context) {
|
|
362
|
-
parts.context = (0, import_node_util2.inspect)((0, import_util2.pickBy)(context, (value) => value !== void 0), {
|
|
363
|
-
depth: config.options.depth,
|
|
364
|
-
colors: true,
|
|
365
|
-
maxArrayLength: 8,
|
|
366
|
-
sorted: false
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
370
|
-
console.log(line);
|
|
371
|
-
};
|
|
372
|
-
var DEBUG_PROCESSOR = (config, entry) => {
|
|
373
|
-
console.log((0, import_node_util3.inspect)(entry, false, null, true));
|
|
374
|
-
};
|
|
375
|
-
var getRelativeFilename2 = (filename) => {
|
|
376
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
377
|
-
if (match) {
|
|
378
|
-
const [, filePath] = match;
|
|
379
|
-
return filePath;
|
|
380
|
-
}
|
|
381
|
-
return filename;
|
|
382
|
-
};
|
|
383
|
-
var CONFIG = {
|
|
384
|
-
useTestProcessor: false,
|
|
385
|
-
printFileLinks: false
|
|
386
|
-
};
|
|
387
|
-
var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
388
|
-
if (!shouldLog(entry, config.filters)) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
392
|
-
const LOG_BROWSER_CSS = [];
|
|
393
|
-
let link = "";
|
|
394
|
-
if (entry.meta) {
|
|
395
|
-
const filename = getRelativeFilename2(entry.meta.F);
|
|
396
|
-
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
397
|
-
link = `${filepath}#L${entry.meta.L}`;
|
|
398
|
-
}
|
|
399
|
-
let args = [];
|
|
400
|
-
if (entry.meta?.S) {
|
|
401
|
-
const scope = entry.meta?.S;
|
|
402
|
-
const scopeName = scope.name || (0, import_util3.getDebugName)(scope);
|
|
403
|
-
const processPrefix = entry.meta.S?.hostSessionId ? "[worker] " : "";
|
|
404
|
-
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
405
|
-
}
|
|
406
|
-
args.push(entry.message);
|
|
407
|
-
const context = getContextFromEntry(entry);
|
|
408
|
-
if (context) {
|
|
409
|
-
if (Object.keys(context).length === 1 && "error" in context) {
|
|
410
|
-
args.push(context.error);
|
|
411
|
-
} else {
|
|
412
|
-
args.push(context);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
const levels2 = {
|
|
416
|
-
[LogLevel.ERROR]: console.error.bind(console),
|
|
417
|
-
[LogLevel.WARN]: console.warn.bind(console),
|
|
418
|
-
[LogLevel.DEBUG]: console.log.bind(console)
|
|
419
|
-
};
|
|
420
|
-
if (CONFIG.printFileLinks || (0, import_util3.safariCheck)()) {
|
|
421
|
-
if (LOG_BROWSER_CSS?.length) {
|
|
422
|
-
args = [
|
|
423
|
-
`%c${link}
|
|
424
|
-
%c${args.join(" ")}`,
|
|
425
|
-
...LOG_BROWSER_CSS
|
|
426
|
-
];
|
|
427
|
-
} else {
|
|
428
|
-
args = [
|
|
429
|
-
link + "\n",
|
|
430
|
-
...args
|
|
431
|
-
];
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
const level = levels2[entry.level] ?? console.log.bind(console);
|
|
435
|
-
if (typeof entry.meta?.C === "function") {
|
|
436
|
-
entry.meta.C(level, args);
|
|
437
|
-
} else {
|
|
438
|
-
level(...args);
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
442
|
-
if (!shouldLog(entry, config.filters)) {
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
let path = "";
|
|
446
|
-
if (entry.meta) {
|
|
447
|
-
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
448
|
-
}
|
|
449
|
-
let args = [];
|
|
450
|
-
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
451
|
-
args.push(`${processPrefix}${entry.message}`);
|
|
452
|
-
const context = getContextFromEntry(entry);
|
|
453
|
-
if (context) {
|
|
454
|
-
args.push(context);
|
|
455
|
-
}
|
|
456
|
-
const levels2 = {
|
|
457
|
-
[LogLevel.ERROR]: console.error,
|
|
458
|
-
[LogLevel.WARN]: console.warn,
|
|
459
|
-
[LogLevel.DEBUG]: console.log
|
|
460
|
-
};
|
|
461
|
-
if (CONFIG.printFileLinks) {
|
|
462
|
-
args = [
|
|
463
|
-
path,
|
|
464
|
-
...args
|
|
465
|
-
];
|
|
466
|
-
}
|
|
467
|
-
const level = levels2[entry.level] ?? console.log;
|
|
468
|
-
if (typeof entry.meta?.C === "function") {
|
|
469
|
-
entry.meta.C(level, args);
|
|
470
|
-
} else {
|
|
471
|
-
level(...args);
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
475
|
-
var EAGAIN_MAX_DURATION = 1e3;
|
|
476
|
-
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
477
|
-
let fd;
|
|
478
|
-
return (config, entry) => {
|
|
479
|
-
if (levels2.length > 0 && !levels2.includes(entry.level)) {
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
if (!shouldLog(entry, filters)) {
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if (typeof pathOrFd === "number") {
|
|
486
|
-
fd = pathOrFd;
|
|
487
|
-
} else {
|
|
488
|
-
try {
|
|
489
|
-
(0, import_node_fs2.mkdirSync)((0, import_node_path.dirname)(pathOrFd));
|
|
490
|
-
} catch {
|
|
491
|
-
}
|
|
492
|
-
fd = (0, import_node_fs2.openSync)(pathOrFd, "a");
|
|
493
|
-
}
|
|
494
|
-
const record = {
|
|
495
|
-
...entry,
|
|
496
|
-
timestamp: Date.now(),
|
|
497
|
-
...entry.meta ? {
|
|
498
|
-
meta: {
|
|
499
|
-
file: getRelativeFilename(entry.meta.F),
|
|
500
|
-
line: entry.meta.L
|
|
501
|
-
}
|
|
502
|
-
} : {},
|
|
503
|
-
context: (0, import_util4.jsonlogify)(getContextFromEntry(entry))
|
|
504
|
-
};
|
|
505
|
-
let retryTS = 0;
|
|
506
|
-
while (true) {
|
|
507
|
-
try {
|
|
508
|
-
return (0, import_node_fs2.appendFileSync)(fd, JSON.stringify(record) + "\n");
|
|
509
|
-
} catch (err) {
|
|
510
|
-
if (err.code !== "EAGAIN") {
|
|
511
|
-
throw err;
|
|
512
|
-
}
|
|
513
|
-
if (retryTS === 0) {
|
|
514
|
-
retryTS = performance.now();
|
|
515
|
-
} else {
|
|
516
|
-
if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
|
|
517
|
-
console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
|
|
518
|
-
throw err;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
var logFilePath;
|
|
526
|
-
var getLogFilePath = () => {
|
|
527
|
-
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
528
|
-
return logFilePath;
|
|
529
|
-
};
|
|
530
|
-
var FILE_PROCESSOR = createFileProcessor({
|
|
531
|
-
pathOrFd: getLogFilePath(),
|
|
532
|
-
levels: [
|
|
533
|
-
LogLevel.ERROR,
|
|
534
|
-
LogLevel.WARN,
|
|
535
|
-
LogLevel.INFO,
|
|
536
|
-
LogLevel.TRACE
|
|
537
|
-
]
|
|
538
|
-
});
|
|
539
|
-
var processors = {
|
|
540
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
541
|
-
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
542
|
-
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
543
|
-
};
|
|
544
|
-
var IS_BROWSER = typeof window !== "undefined" || typeof navigator !== "undefined";
|
|
545
|
-
var DEFAULT_PROCESSORS = [
|
|
546
|
-
IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
|
|
547
|
-
];
|
|
548
|
-
var parseFilter = (filter) => {
|
|
549
|
-
if (typeof filter === "number") {
|
|
550
|
-
return [
|
|
551
|
-
{
|
|
552
|
-
level: filter
|
|
553
|
-
}
|
|
554
|
-
];
|
|
555
|
-
}
|
|
556
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
557
|
-
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
558
|
-
return lines.map((filter2) => {
|
|
559
|
-
const [pattern, level] = filter2.split(":");
|
|
560
|
-
return level ? {
|
|
561
|
-
level: parseLogLevel(level),
|
|
562
|
-
pattern
|
|
563
|
-
} : {
|
|
564
|
-
level: parseLogLevel(pattern)
|
|
565
|
-
};
|
|
566
|
-
});
|
|
567
|
-
};
|
|
568
|
-
var getConfig = (options) => {
|
|
569
|
-
const nodeOptions = "process" in globalThis ? {
|
|
570
|
-
file: process.env.LOG_CONFIG,
|
|
571
|
-
filter: process.env.LOG_FILTER,
|
|
572
|
-
processor: process.env.LOG_PROCESSOR
|
|
573
|
-
} : void 0;
|
|
574
|
-
const mergedOptions = (0, import_lodash2.default)({}, loadOptions(nodeOptions?.file), nodeOptions, options);
|
|
575
|
-
return {
|
|
576
|
-
options: mergedOptions,
|
|
577
|
-
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
578
|
-
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
579
|
-
processors: mergedOptions.processor ? [
|
|
580
|
-
processors[mergedOptions.processor]
|
|
581
|
-
] : DEFAULT_PROCESSORS,
|
|
582
|
-
prefix: mergedOptions.prefix
|
|
583
|
-
};
|
|
584
|
-
};
|
|
585
|
-
var createLog = () => {
|
|
586
|
-
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
587
|
-
log2._config = getConfig();
|
|
588
|
-
Object.defineProperty(log2, "runtimeConfig", {
|
|
589
|
-
get: () => log2._config
|
|
590
|
-
});
|
|
591
|
-
log2.addProcessor = (processor) => {
|
|
592
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
593
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
594
|
-
}
|
|
595
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
596
|
-
log2._config.processors.push(processor);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
log2.config = (options) => {
|
|
600
|
-
log2._config = getConfig(options);
|
|
601
|
-
};
|
|
602
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
603
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
604
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
605
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
606
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
607
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
608
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error?.message ?? String(error), context, meta, error);
|
|
609
|
-
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");
|
|
610
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
611
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
612
|
-
log2.method = createMethodLogDecorator(log2);
|
|
613
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
614
|
-
const processLog = (level, message, context = {}, meta, error) => {
|
|
615
|
-
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
616
|
-
level,
|
|
617
|
-
message,
|
|
618
|
-
context,
|
|
619
|
-
meta,
|
|
620
|
-
error
|
|
621
|
-
}));
|
|
622
|
-
};
|
|
623
|
-
return log2;
|
|
624
|
-
};
|
|
625
|
-
var log = globalThis.dx_log ??= createLog();
|
|
626
|
-
var start = Date.now();
|
|
627
|
-
var last = start;
|
|
628
|
-
var debug = (label, args) => {
|
|
629
|
-
const now = Date.now();
|
|
630
|
-
const err = new Error();
|
|
631
|
-
console.group(`DEBUG[${label}]`, JSON.stringify({
|
|
632
|
-
t: Number(now - start).toLocaleString(),
|
|
633
|
-
dt: Number(now - last).toLocaleString(),
|
|
634
|
-
...args
|
|
635
|
-
}));
|
|
636
|
-
console.warn(err.stack);
|
|
637
|
-
console.groupEnd();
|
|
638
|
-
last = Date.now();
|
|
639
|
-
};
|
|
640
|
-
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
641
|
-
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
642
|
-
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
643
|
-
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
644
|
-
var OwnershipScope = class {
|
|
645
|
-
constructor(constr, parent) {
|
|
646
|
-
this.constr = constr;
|
|
647
|
-
this.parent = parent;
|
|
648
|
-
}
|
|
649
|
-
getInfo() {
|
|
650
|
-
if (!this.instance) {
|
|
651
|
-
return {};
|
|
652
|
-
}
|
|
653
|
-
const props = this.constr.prototype[kDebugInfoProperties] ?? [];
|
|
654
|
-
const info = {};
|
|
655
|
-
for (const prop of props) {
|
|
656
|
-
info[prop] = this.instance[prop];
|
|
657
|
-
}
|
|
658
|
-
return info;
|
|
659
|
-
}
|
|
660
|
-
[import_node_util4.inspect.custom]() {
|
|
661
|
-
return {
|
|
662
|
-
className: this.constr.name,
|
|
663
|
-
info: this.getInfo(),
|
|
664
|
-
parent: this.parent
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
669
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
670
|
-
0 && (module.exports = {
|
|
671
|
-
BROWSER_PROCESSOR,
|
|
672
|
-
CONSOLE_PROCESSOR,
|
|
673
|
-
DEBUG_PROCESSOR,
|
|
674
|
-
DEFAULT_FORMATTER,
|
|
675
|
-
FILE_PROCESSOR,
|
|
676
|
-
LogLevel,
|
|
677
|
-
LogProcessorType,
|
|
678
|
-
SHORT_FORMATTER,
|
|
679
|
-
createFileProcessor,
|
|
680
|
-
debug,
|
|
681
|
-
gatherLogInfoFromScope,
|
|
682
|
-
getContextFromEntry,
|
|
683
|
-
getCurrentOwnershipScope,
|
|
684
|
-
getRelativeFilename,
|
|
685
|
-
levels,
|
|
686
|
-
log,
|
|
687
|
-
logInfo,
|
|
688
|
-
omit,
|
|
689
|
-
parseFilter,
|
|
690
|
-
pick,
|
|
691
|
-
shortLevelName,
|
|
692
|
-
shouldLog,
|
|
693
|
-
truncate
|
|
694
|
-
});
|
|
695
|
-
//# sourceMappingURL=index.cjs.map
|