@dxos/log 0.6.11 → 0.6.12-main.5cc132e
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 +1 -4
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +1 -4
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +605 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/package.json +6 -9
- package/src/experimental/classes.test.ts +1 -1
- package/src/log.test.ts +2 -3
- package/src/processors/browser-processor.ts +4 -10
- package/src/scope.test.ts +1 -1
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/log/src/config.ts":{"bytes":3604,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3928,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6948,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":14472,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/node/index.ts":{"bytes":2103,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":492,"imports":[{"path":"packages/common/log/src/platform/node/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/common.ts":{"bytes":1666,"imports":[],"format":"esm"},"packages/common/log/src/processors/console-processor.ts":{"bytes":13162,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/processors/common.ts","kind":"import-statement","original":"./common"},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1106,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/log/src/config.ts":{"bytes":3604,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3928,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6948,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":14472,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/node/index.ts":{"bytes":2103,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":492,"imports":[{"path":"packages/common/log/src/platform/node/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/common.ts":{"bytes":1666,"imports":[],"format":"esm"},"packages/common/log/src/processors/console-processor.ts":{"bytes":13162,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/processors/common.ts","kind":"import-statement","original":"./common"},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1106,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":15138,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/file-processor.ts":{"bytes":10237,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/processors/common.ts","kind":"import-statement","original":"./common"},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/index.ts":{"bytes":939,"imports":[{"path":"packages/common/log/src/processors/console-processor.ts","kind":"import-statement","original":"./console-processor"},{"path":"packages/common/log/src/processors/debug-processor.ts","kind":"import-statement","original":"./debug-processor"},{"path":"packages/common/log/src/processors/browser-processor.ts","kind":"import-statement","original":"./browser-processor"},{"path":"packages/common/log/src/processors/file-processor.ts","kind":"import-statement","original":"./file-processor"},{"path":"packages/common/log/src/processors/common.ts","kind":"import-statement","original":"./common"}],"format":"esm"},"packages/common/log/src/options.ts":{"bytes":7654,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/platform/index.ts","kind":"import-statement","original":"./platform"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"}],"format":"esm"},"packages/common/log/src/log.ts":{"bytes":10413,"imports":[{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/decorators.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"}],"format":"esm"},"packages/common/log/src/meta.ts":{"bytes":1661,"imports":[],"format":"esm"},"packages/common/log/src/experimental/ownership.ts":{"bytes":9414,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/index.ts":{"bytes":1722,"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/log/src/log.ts","kind":"import-statement","original":"./log"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"},{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"},{"path":"packages/common/log/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/common/log/src/experimental/ownership.ts","kind":"import-statement","original":"./experimental/ownership"}],"format":"esm"}},"outputs":{"packages/common/log/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":49855},"packages/common/log/dist/lib/node/index.cjs":{"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["BROWSER_PROCESSOR","CONSOLE_PROCESSOR","DEBUG_PROCESSOR","DEFAULT_FORMATTER","FILE_PROCESSOR","LogLevel","LogProcessorType","SHORT_FORMATTER","createFileProcessor","gatherLogInfoFromScope","getContextFromEntry","getCurrentOwnershipScope","getRelativeFilename","levels","log","logInfo","omit","parseFilter","pick","shortLevelName","shouldLog","truncate"],"entryPoint":"packages/common/log/src/index.ts","inputs":{"packages/common/log/src/index.ts":{"bytesInOutput":67},"packages/common/log/src/config.ts":{"bytesInOutput":703},"packages/common/log/src/scope.ts":{"bytesInOutput":571},"packages/common/log/src/context.ts":{"bytesInOutput":1241},"packages/common/log/src/decorators.ts":{"bytesInOutput":3205},"packages/common/log/src/options.ts":{"bytesInOutput":1542},"packages/common/log/src/platform/node/index.ts":{"bytesInOutput":315},"packages/common/log/src/platform/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/console-processor.ts":{"bytesInOutput":2700},"packages/common/log/src/processors/common.ts":{"bytesInOutput":194},"packages/common/log/src/processors/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/debug-processor.ts":{"bytesInOutput":146},"packages/common/log/src/processors/browser-processor.ts":{"bytesInOutput":2724},"packages/common/log/src/processors/file-processor.ts":{"bytesInOutput":1812},"packages/common/log/src/log.ts":{"bytesInOutput":1930},"packages/common/log/src/experimental/ownership.ts":{"bytesInOutput":782}},"bytes":19108}}}
|
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
// packages/common/log/src/index.ts
|
|
2
|
+
import omit from "lodash.omit";
|
|
3
|
+
import { pick } from "@dxos/util";
|
|
4
|
+
|
|
5
|
+
// packages/common/log/src/config.ts
|
|
6
|
+
var LogLevel;
|
|
7
|
+
(function(LogLevel2) {
|
|
8
|
+
LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
|
|
9
|
+
LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
|
|
10
|
+
LogLevel2[LogLevel2["INFO"] = 11] = "INFO";
|
|
11
|
+
LogLevel2[LogLevel2["WARN"] = 12] = "WARN";
|
|
12
|
+
LogLevel2[LogLevel2["ERROR"] = 13] = "ERROR";
|
|
13
|
+
})(LogLevel || (LogLevel = {}));
|
|
14
|
+
var levels = {
|
|
15
|
+
trace: 5,
|
|
16
|
+
debug: 10,
|
|
17
|
+
info: 11,
|
|
18
|
+
warn: 12,
|
|
19
|
+
error: 13
|
|
20
|
+
};
|
|
21
|
+
var shortLevelName = {
|
|
22
|
+
[5]: "T",
|
|
23
|
+
[10]: "D",
|
|
24
|
+
[11]: "I",
|
|
25
|
+
[12]: "W",
|
|
26
|
+
[13]: "E"
|
|
27
|
+
};
|
|
28
|
+
var LogProcessorType;
|
|
29
|
+
(function(LogProcessorType2) {
|
|
30
|
+
LogProcessorType2["CONSOLE"] = "console";
|
|
31
|
+
LogProcessorType2["BROWSER"] = "browser";
|
|
32
|
+
LogProcessorType2["DEBUG"] = "debug";
|
|
33
|
+
})(LogProcessorType || (LogProcessorType = {}));
|
|
34
|
+
|
|
35
|
+
// packages/common/log/src/scope.ts
|
|
36
|
+
var logInfoProperties = Symbol("logInfoProperties");
|
|
37
|
+
var logInfo = (target, propertyKey, descriptor) => {
|
|
38
|
+
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
39
|
+
};
|
|
40
|
+
var gatherLogInfoFromScope = (scope) => {
|
|
41
|
+
if (!scope) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
const res = {};
|
|
45
|
+
const prototype = Object.getPrototypeOf(scope);
|
|
46
|
+
const infoProps = prototype[logInfoProperties] ?? [];
|
|
47
|
+
for (const prop of infoProps) {
|
|
48
|
+
try {
|
|
49
|
+
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
50
|
+
} catch (err) {
|
|
51
|
+
res[prop] = err.message;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return res;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// packages/common/log/src/context.ts
|
|
58
|
+
var matchFilter = (filter, level, path) => {
|
|
59
|
+
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
60
|
+
};
|
|
61
|
+
var shouldLog = (entry, filters) => {
|
|
62
|
+
if (filters === void 0) {
|
|
63
|
+
return true;
|
|
64
|
+
} else {
|
|
65
|
+
return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var getContextFromEntry = (entry) => {
|
|
69
|
+
let context;
|
|
70
|
+
if (entry.meta) {
|
|
71
|
+
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
72
|
+
if (Object.keys(scopeInfo).length > 0) {
|
|
73
|
+
context = Object.assign(context ?? {}, scopeInfo);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
77
|
+
if (entryContext) {
|
|
78
|
+
if (entryContext instanceof Error) {
|
|
79
|
+
const c = entryContext.context;
|
|
80
|
+
context = Object.assign(context ?? {}, {
|
|
81
|
+
error: entryContext.stack,
|
|
82
|
+
...c
|
|
83
|
+
});
|
|
84
|
+
} else if (typeof entryContext === "object") {
|
|
85
|
+
context = Object.assign(context ?? {}, entryContext);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (entry.error) {
|
|
89
|
+
const errorContext = entry.error.context;
|
|
90
|
+
context = Object.assign(context ?? {}, {
|
|
91
|
+
error: entry.error,
|
|
92
|
+
...errorContext
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// packages/common/log/src/decorators.ts
|
|
99
|
+
import chalk from "chalk";
|
|
100
|
+
import { inspect } from "node:util";
|
|
101
|
+
var nextPromiseId = 0;
|
|
102
|
+
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
103
|
+
const method = descriptor.value;
|
|
104
|
+
const methodName = propertyKey;
|
|
105
|
+
descriptor.value = function(...args) {
|
|
106
|
+
const combinedMeta = {
|
|
107
|
+
F: "",
|
|
108
|
+
L: 0,
|
|
109
|
+
...meta ?? {},
|
|
110
|
+
S: this
|
|
111
|
+
};
|
|
112
|
+
const formattedArgs = args.map((arg) => inspect(arg, false, 1, true)).join(", ");
|
|
113
|
+
try {
|
|
114
|
+
const startTime = performance.now();
|
|
115
|
+
const result = method.apply(this, args);
|
|
116
|
+
if (isThenable(result)) {
|
|
117
|
+
const id = nextPromiseId++;
|
|
118
|
+
logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
|
|
119
|
+
result.then((resolvedValue) => {
|
|
120
|
+
logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
|
|
121
|
+
}, (err) => {
|
|
122
|
+
logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
Object.defineProperty(descriptor.value, "name", {
|
|
134
|
+
value: methodName + "$log"
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
var isThenable = (obj) => obj && typeof obj.then === "function";
|
|
138
|
+
var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
|
|
139
|
+
log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray("=>")} ${inspect(result, false, 1, true)}`, {}, combinedMeta);
|
|
140
|
+
};
|
|
141
|
+
var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
|
|
142
|
+
log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
|
|
143
|
+
};
|
|
144
|
+
var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
|
|
145
|
+
log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${chalk.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
|
|
146
|
+
};
|
|
147
|
+
var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
|
|
148
|
+
if (resolvedValue !== void 0) {
|
|
149
|
+
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${inspect(resolvedValue, false, 1, true)}`, {}, combinedMeta);
|
|
150
|
+
} else {
|
|
151
|
+
log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
155
|
+
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
156
|
+
};
|
|
157
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
158
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
159
|
+
var COLOR_FUNCTION = [
|
|
160
|
+
220,
|
|
161
|
+
220,
|
|
162
|
+
170
|
|
163
|
+
];
|
|
164
|
+
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
165
|
+
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
166
|
+
|
|
167
|
+
// packages/common/log/src/options.ts
|
|
168
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
169
|
+
|
|
170
|
+
// packages/common/log/src/platform/node/index.ts
|
|
171
|
+
import yaml from "js-yaml";
|
|
172
|
+
import fs from "node:fs";
|
|
173
|
+
var loadOptions = (filepath) => {
|
|
174
|
+
if (filepath) {
|
|
175
|
+
try {
|
|
176
|
+
const text = fs.readFileSync(filepath, "utf-8");
|
|
177
|
+
if (text) {
|
|
178
|
+
return yaml.load(text);
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.warn(`Invalid log file: ${filepath}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// packages/common/log/src/processors/console-processor.ts
|
|
187
|
+
import chalk2 from "chalk";
|
|
188
|
+
import { inspect as inspect2 } from "node:util";
|
|
189
|
+
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
190
|
+
|
|
191
|
+
// packages/common/log/src/processors/common.ts
|
|
192
|
+
var getRelativeFilename = (filename) => {
|
|
193
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
194
|
+
if (match) {
|
|
195
|
+
const [, filePath] = match;
|
|
196
|
+
return filePath;
|
|
197
|
+
}
|
|
198
|
+
return filename;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// packages/common/log/src/processors/console-processor.ts
|
|
202
|
+
var LEVEL_COLORS = {
|
|
203
|
+
[LogLevel.TRACE]: "gray",
|
|
204
|
+
[LogLevel.DEBUG]: "gray",
|
|
205
|
+
[LogLevel.INFO]: "white",
|
|
206
|
+
[LogLevel.WARN]: "yellow",
|
|
207
|
+
[LogLevel.ERROR]: "red"
|
|
208
|
+
};
|
|
209
|
+
var truncate = (text, length = 0, right = false) => {
|
|
210
|
+
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
211
|
+
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
212
|
+
};
|
|
213
|
+
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
214
|
+
const column = config.options?.formatter?.column;
|
|
215
|
+
const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
|
|
216
|
+
let instance;
|
|
217
|
+
if (scope) {
|
|
218
|
+
const prototype = Object.getPrototypeOf(scope);
|
|
219
|
+
const id = getPrototypeSpecificInstanceId(scope);
|
|
220
|
+
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
221
|
+
}
|
|
222
|
+
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
223
|
+
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
224
|
+
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
225
|
+
return config.options?.formatter?.timestampFirst ? [
|
|
226
|
+
formattedTimestamp,
|
|
227
|
+
filepath,
|
|
228
|
+
padding,
|
|
229
|
+
formattedLevel,
|
|
230
|
+
instance,
|
|
231
|
+
message,
|
|
232
|
+
context,
|
|
233
|
+
error
|
|
234
|
+
] : [
|
|
235
|
+
// NOTE: File path must come fist for console hyperlinks.
|
|
236
|
+
// Must not truncate for terminal output.
|
|
237
|
+
filepath,
|
|
238
|
+
padding,
|
|
239
|
+
formattedTimestamp,
|
|
240
|
+
formattedLevel,
|
|
241
|
+
instance,
|
|
242
|
+
message,
|
|
243
|
+
context,
|
|
244
|
+
error
|
|
245
|
+
];
|
|
246
|
+
};
|
|
247
|
+
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
248
|
+
return [
|
|
249
|
+
chalk2.grey(truncate(path, 16, true)),
|
|
250
|
+
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
251
|
+
message
|
|
252
|
+
];
|
|
253
|
+
};
|
|
254
|
+
var formatter = DEFAULT_FORMATTER;
|
|
255
|
+
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
256
|
+
const { level, message, meta, error } = entry;
|
|
257
|
+
if (!shouldLog(entry, config.filters)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const parts = {
|
|
261
|
+
level,
|
|
262
|
+
message,
|
|
263
|
+
error,
|
|
264
|
+
path: void 0,
|
|
265
|
+
line: void 0,
|
|
266
|
+
scope: void 0,
|
|
267
|
+
context: void 0
|
|
268
|
+
};
|
|
269
|
+
if (meta) {
|
|
270
|
+
parts.path = getRelativeFilename(meta.F);
|
|
271
|
+
parts.line = meta.L;
|
|
272
|
+
parts.scope = meta.S;
|
|
273
|
+
}
|
|
274
|
+
const context = getContextFromEntry(entry);
|
|
275
|
+
if (context) {
|
|
276
|
+
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
277
|
+
depth: config.options.depth,
|
|
278
|
+
colors: true,
|
|
279
|
+
maxArrayLength: 8,
|
|
280
|
+
sorted: false
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
284
|
+
console.log(line);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// packages/common/log/src/processors/debug-processor.ts
|
|
288
|
+
import { inspect as inspect3 } from "node:util";
|
|
289
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
290
|
+
console.log(inspect3(entry, false, null, true));
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// packages/common/log/src/processors/browser-processor.ts
|
|
294
|
+
import { getDebugName, safariCheck } from "@dxos/util";
|
|
295
|
+
var getRelativeFilename2 = (filename) => {
|
|
296
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
297
|
+
if (match) {
|
|
298
|
+
const [, filePath] = match;
|
|
299
|
+
return filePath;
|
|
300
|
+
}
|
|
301
|
+
return filename;
|
|
302
|
+
};
|
|
303
|
+
var CONFIG = {
|
|
304
|
+
useTestProcessor: false,
|
|
305
|
+
printFileLinks: false
|
|
306
|
+
};
|
|
307
|
+
var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
308
|
+
if (!shouldLog(entry, config.filters)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const LOG_BROWSER_PREFIX = config.prefix ?? "https://vscode.dev/github.com/dxos/dxos/blob/main/";
|
|
312
|
+
const LOG_BROWSER_CSS = [];
|
|
313
|
+
let link = "";
|
|
314
|
+
if (entry.meta) {
|
|
315
|
+
const filename = getRelativeFilename2(entry.meta.F);
|
|
316
|
+
const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, "")}/${filename}`;
|
|
317
|
+
link = `${filepath}#L${entry.meta.L}`;
|
|
318
|
+
}
|
|
319
|
+
let args = [];
|
|
320
|
+
if (entry.meta?.S) {
|
|
321
|
+
const scope = entry.meta?.S;
|
|
322
|
+
const scopeName = scope.name || getDebugName(scope);
|
|
323
|
+
const processPrefix = entry.meta.S?.hostSessionId ? "[worker] " : "";
|
|
324
|
+
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
325
|
+
}
|
|
326
|
+
args.push(entry.message);
|
|
327
|
+
const context = getContextFromEntry(entry);
|
|
328
|
+
if (context) {
|
|
329
|
+
args.push(context);
|
|
330
|
+
}
|
|
331
|
+
const levels2 = {
|
|
332
|
+
[LogLevel.ERROR]: console.error.bind(console),
|
|
333
|
+
[LogLevel.WARN]: console.warn.bind(console),
|
|
334
|
+
[LogLevel.DEBUG]: console.log.bind(console)
|
|
335
|
+
};
|
|
336
|
+
if (CONFIG.printFileLinks || safariCheck()) {
|
|
337
|
+
if (LOG_BROWSER_CSS?.length) {
|
|
338
|
+
args = [
|
|
339
|
+
`%c${link}
|
|
340
|
+
%c${args.join(" ")}`,
|
|
341
|
+
...LOG_BROWSER_CSS
|
|
342
|
+
];
|
|
343
|
+
} else {
|
|
344
|
+
args = [
|
|
345
|
+
link + "\n",
|
|
346
|
+
...args
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const level = levels2[entry.level] ?? console.log.bind(console);
|
|
351
|
+
if (typeof entry.meta?.C === "function") {
|
|
352
|
+
entry.meta.C(level, args);
|
|
353
|
+
} else {
|
|
354
|
+
level(...args);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
358
|
+
if (!shouldLog(entry, config.filters)) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
let path = "";
|
|
362
|
+
if (entry.meta) {
|
|
363
|
+
path = `${getRelativeFilename2(entry.meta.F)}:${entry.meta.L}`;
|
|
364
|
+
}
|
|
365
|
+
let args = [];
|
|
366
|
+
const processPrefix = entry.meta?.S?.hostSessionId ? "[worker] " : "";
|
|
367
|
+
args.push(`${processPrefix}${entry.message}`);
|
|
368
|
+
const context = getContextFromEntry(entry);
|
|
369
|
+
if (context) {
|
|
370
|
+
args.push(context);
|
|
371
|
+
}
|
|
372
|
+
const levels2 = {
|
|
373
|
+
[LogLevel.ERROR]: console.error,
|
|
374
|
+
[LogLevel.WARN]: console.warn,
|
|
375
|
+
[LogLevel.DEBUG]: console.log
|
|
376
|
+
};
|
|
377
|
+
if (CONFIG.printFileLinks) {
|
|
378
|
+
args = [
|
|
379
|
+
path,
|
|
380
|
+
...args
|
|
381
|
+
];
|
|
382
|
+
}
|
|
383
|
+
const level = levels2[entry.level] ?? console.log;
|
|
384
|
+
if (typeof entry.meta?.C === "function") {
|
|
385
|
+
entry.meta.C(level, args);
|
|
386
|
+
} else {
|
|
387
|
+
level(...args);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
391
|
+
|
|
392
|
+
// packages/common/log/src/processors/file-processor.ts
|
|
393
|
+
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
394
|
+
import { dirname } from "node:path";
|
|
395
|
+
import { jsonlogify } from "@dxos/util";
|
|
396
|
+
var EAGAIN_MAX_DURATION = 1e3;
|
|
397
|
+
var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
|
|
398
|
+
let fd;
|
|
399
|
+
return (config, entry) => {
|
|
400
|
+
if (levels2.length > 0 && !levels2.includes(entry.level)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (!shouldLog(entry, filters)) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (typeof pathOrFd === "number") {
|
|
407
|
+
fd = pathOrFd;
|
|
408
|
+
} else {
|
|
409
|
+
try {
|
|
410
|
+
mkdirSync(dirname(pathOrFd));
|
|
411
|
+
} catch {
|
|
412
|
+
}
|
|
413
|
+
fd = openSync(pathOrFd, "a");
|
|
414
|
+
}
|
|
415
|
+
const record = {
|
|
416
|
+
...entry,
|
|
417
|
+
timestamp: Date.now(),
|
|
418
|
+
...entry.meta ? {
|
|
419
|
+
meta: {
|
|
420
|
+
file: getRelativeFilename(entry.meta.F),
|
|
421
|
+
line: entry.meta.L
|
|
422
|
+
}
|
|
423
|
+
} : {},
|
|
424
|
+
context: jsonlogify(getContextFromEntry(entry))
|
|
425
|
+
};
|
|
426
|
+
let retryTS = 0;
|
|
427
|
+
while (true) {
|
|
428
|
+
try {
|
|
429
|
+
return appendFileSync(fd, JSON.stringify(record) + "\n");
|
|
430
|
+
} catch (err) {
|
|
431
|
+
if (err.code !== "EAGAIN") {
|
|
432
|
+
throw err;
|
|
433
|
+
}
|
|
434
|
+
if (retryTS === 0) {
|
|
435
|
+
retryTS = performance.now();
|
|
436
|
+
} else {
|
|
437
|
+
if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
|
|
438
|
+
console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
|
|
439
|
+
throw err;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
var logFilePath;
|
|
447
|
+
var getLogFilePath = () => {
|
|
448
|
+
logFilePath ??= process.env.LOG_FILE ?? (process.env.HOME ? `${process.env.HOME}/.dxlog/${(/* @__PURE__ */ new Date()).toISOString()}.log` : void 0);
|
|
449
|
+
return logFilePath;
|
|
450
|
+
};
|
|
451
|
+
var FILE_PROCESSOR = createFileProcessor({
|
|
452
|
+
pathOrFd: getLogFilePath(),
|
|
453
|
+
levels: [
|
|
454
|
+
LogLevel.ERROR,
|
|
455
|
+
LogLevel.WARN,
|
|
456
|
+
LogLevel.INFO,
|
|
457
|
+
LogLevel.TRACE
|
|
458
|
+
]
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// packages/common/log/src/options.ts
|
|
462
|
+
var processors = {
|
|
463
|
+
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
464
|
+
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
465
|
+
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
466
|
+
};
|
|
467
|
+
var IS_BROWSER = typeof window !== "undefined" || typeof navigator !== "undefined";
|
|
468
|
+
var DEFAULT_PROCESSORS = [
|
|
469
|
+
IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
|
|
470
|
+
];
|
|
471
|
+
var parseFilter = (filter) => {
|
|
472
|
+
if (typeof filter === "number") {
|
|
473
|
+
return [
|
|
474
|
+
{
|
|
475
|
+
level: filter
|
|
476
|
+
}
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
480
|
+
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
481
|
+
return lines.map((filter2) => {
|
|
482
|
+
const [pattern, level] = filter2.split(":");
|
|
483
|
+
return level ? {
|
|
484
|
+
level: parseLogLevel(level),
|
|
485
|
+
pattern
|
|
486
|
+
} : {
|
|
487
|
+
level: parseLogLevel(pattern)
|
|
488
|
+
};
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
var getConfig = (options) => {
|
|
492
|
+
const nodeOptions = "process" in globalThis ? {
|
|
493
|
+
file: process.env.LOG_CONFIG,
|
|
494
|
+
filter: process.env.LOG_FILTER,
|
|
495
|
+
processor: process.env.LOG_PROCESSOR
|
|
496
|
+
} : void 0;
|
|
497
|
+
const mergedOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);
|
|
498
|
+
return {
|
|
499
|
+
options: mergedOptions,
|
|
500
|
+
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
501
|
+
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
502
|
+
processors: mergedOptions.processor ? [
|
|
503
|
+
processors[mergedOptions.processor]
|
|
504
|
+
] : DEFAULT_PROCESSORS,
|
|
505
|
+
prefix: mergedOptions.prefix
|
|
506
|
+
};
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// packages/common/log/src/log.ts
|
|
510
|
+
var createLog = () => {
|
|
511
|
+
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
512
|
+
log2._config = getConfig();
|
|
513
|
+
Object.defineProperty(log2, "runtimeConfig", {
|
|
514
|
+
get: () => log2._config
|
|
515
|
+
});
|
|
516
|
+
log2.addProcessor = (processor) => {
|
|
517
|
+
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
518
|
+
DEFAULT_PROCESSORS.push(processor);
|
|
519
|
+
}
|
|
520
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
521
|
+
log2._config.processors.push(processor);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
log2.config = (options) => {
|
|
525
|
+
log2._config = getConfig(options);
|
|
526
|
+
};
|
|
527
|
+
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
528
|
+
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
529
|
+
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
530
|
+
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
531
|
+
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
532
|
+
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);
|
|
533
|
+
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");
|
|
534
|
+
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
535
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
536
|
+
log2.method = createMethodLogDecorator(log2);
|
|
537
|
+
const processLog = (level, message, context = {}, meta, error) => {
|
|
538
|
+
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
539
|
+
level,
|
|
540
|
+
message,
|
|
541
|
+
context,
|
|
542
|
+
meta,
|
|
543
|
+
error
|
|
544
|
+
}));
|
|
545
|
+
};
|
|
546
|
+
return log2;
|
|
547
|
+
};
|
|
548
|
+
var log = globalThis.dx_log ??= createLog();
|
|
549
|
+
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
550
|
+
|
|
551
|
+
// packages/common/log/src/experimental/ownership.ts
|
|
552
|
+
import { inspect as inspect4 } from "node:util";
|
|
553
|
+
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
554
|
+
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
555
|
+
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
556
|
+
var OwnershipScope = class {
|
|
557
|
+
constructor(constr, parent) {
|
|
558
|
+
this.constr = constr;
|
|
559
|
+
this.parent = parent;
|
|
560
|
+
}
|
|
561
|
+
getInfo() {
|
|
562
|
+
if (!this.instance) {
|
|
563
|
+
return {};
|
|
564
|
+
}
|
|
565
|
+
const props = this.constr.prototype[kDebugInfoProperties] ?? [];
|
|
566
|
+
const info = {};
|
|
567
|
+
for (const prop of props) {
|
|
568
|
+
info[prop] = this.instance[prop];
|
|
569
|
+
}
|
|
570
|
+
return info;
|
|
571
|
+
}
|
|
572
|
+
[inspect4.custom]() {
|
|
573
|
+
return {
|
|
574
|
+
className: this.constr.name,
|
|
575
|
+
info: this.getInfo(),
|
|
576
|
+
parent: this.parent
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
581
|
+
export {
|
|
582
|
+
BROWSER_PROCESSOR,
|
|
583
|
+
CONSOLE_PROCESSOR,
|
|
584
|
+
DEBUG_PROCESSOR,
|
|
585
|
+
DEFAULT_FORMATTER,
|
|
586
|
+
FILE_PROCESSOR,
|
|
587
|
+
LogLevel,
|
|
588
|
+
LogProcessorType,
|
|
589
|
+
SHORT_FORMATTER,
|
|
590
|
+
createFileProcessor,
|
|
591
|
+
gatherLogInfoFromScope,
|
|
592
|
+
getContextFromEntry,
|
|
593
|
+
getCurrentOwnershipScope,
|
|
594
|
+
getRelativeFilename,
|
|
595
|
+
levels,
|
|
596
|
+
log,
|
|
597
|
+
logInfo,
|
|
598
|
+
omit,
|
|
599
|
+
parseFilter,
|
|
600
|
+
pick,
|
|
601
|
+
shortLevelName,
|
|
602
|
+
shouldLog,
|
|
603
|
+
truncate
|
|
604
|
+
};
|
|
605
|
+
//# sourceMappingURL=index.mjs.map
|