@dxos/log 0.8.3 → 0.8.4-main.1068cf700f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-GPOFUMLO.mjs +133 -0
- package/dist/lib/browser/chunk-GPOFUMLO.mjs.map +7 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +159 -188
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/platform/browser/index.mjs +26 -0
- package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
- package/dist/lib/browser/platform/node/index.mjs +21 -0
- package/dist/lib/browser/platform/node/index.mjs.map +7 -0
- package/dist/lib/browser/processors/console-processor.mjs +107 -0
- package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
- package/dist/lib/browser/processors/console-stub.mjs +9 -0
- package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs +135 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +156 -270
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
- package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
- package/dist/lib/node-esm/platform/node/index.mjs +22 -0
- package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-processor.mjs +108 -0
- package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
- package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
- package/dist/types/src/config.d.ts +2 -3
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/context.d.ts +1 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/dbg.d.ts +23 -0
- package/dist/types/src/dbg.d.ts.map +1 -0
- package/dist/types/src/decorators.d.ts +1 -1
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/log.d.ts +12 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/platform/node/index.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -11
- package/src/config.ts +3 -2
- package/src/context.ts +38 -8
- package/src/dbg.ts +35 -0
- package/src/decorators.ts +5 -4
- package/src/experimental/classes.test.ts +2 -1
- package/src/index.ts +2 -1
- package/src/log.test.ts +59 -23
- package/src/log.ts +102 -59
- package/src/options.ts +27 -11
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +2 -1
- package/src/processors/browser-processor.ts +6 -2
- package/src/processors/console-processor.ts +11 -7
- package/src/processors/file-processor.ts +4 -1
- package/src/processors/index.ts +3 -3
- package/src/scope.ts +1 -1
- 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
|
@@ -1,108 +1,51 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
LogLevel,
|
|
4
|
+
LogProcessorType,
|
|
5
|
+
gatherLogInfoFromScope,
|
|
6
|
+
getContextFromEntry,
|
|
7
|
+
getRelativeFilename,
|
|
8
|
+
levels,
|
|
9
|
+
logInfo,
|
|
10
|
+
shortLevelName,
|
|
11
|
+
shouldLog
|
|
12
|
+
} from "./chunk-QPYJZ4SO.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__export,
|
|
15
|
+
__reExport
|
|
16
|
+
} from "./chunk-2SZHAWBN.mjs";
|
|
2
17
|
|
|
3
|
-
//
|
|
18
|
+
// src/index.ts
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
22
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
23
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
24
|
+
LogLevel: () => LogLevel,
|
|
25
|
+
LogProcessorType: () => LogProcessorType,
|
|
26
|
+
createFileProcessor: () => createFileProcessor,
|
|
27
|
+
createLog: () => createLog,
|
|
28
|
+
dbg: () => dbg,
|
|
29
|
+
debug: () => debug,
|
|
30
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
31
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
32
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
33
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
34
|
+
levels: () => levels,
|
|
35
|
+
log: () => log,
|
|
36
|
+
logInfo: () => logInfo,
|
|
37
|
+
omit: () => omit,
|
|
38
|
+
parseFilter: () => parseFilter,
|
|
39
|
+
pick: () => pick,
|
|
40
|
+
shortLevelName: () => shortLevelName,
|
|
41
|
+
shouldLog: () => shouldLog
|
|
42
|
+
});
|
|
4
43
|
import omit from "lodash.omit";
|
|
5
44
|
import { pick } from "@dxos/util";
|
|
6
45
|
|
|
7
|
-
//
|
|
8
|
-
var LogLevel = /* @__PURE__ */ function(LogLevel2) {
|
|
9
|
-
LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
|
|
10
|
-
LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
|
|
11
|
-
LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
|
|
12
|
-
LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
|
|
13
|
-
LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
|
|
14
|
-
LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
|
|
15
|
-
return LogLevel2;
|
|
16
|
-
}({});
|
|
17
|
-
var levels = {
|
|
18
|
-
trace: 5,
|
|
19
|
-
debug: 10,
|
|
20
|
-
verbose: 11,
|
|
21
|
-
info: 12,
|
|
22
|
-
warn: 13,
|
|
23
|
-
error: 14
|
|
24
|
-
};
|
|
25
|
-
var shortLevelName = {
|
|
26
|
-
[5]: "T",
|
|
27
|
-
[10]: "D",
|
|
28
|
-
[11]: "V",
|
|
29
|
-
[12]: "I",
|
|
30
|
-
[13]: "W",
|
|
31
|
-
[14]: "E"
|
|
32
|
-
};
|
|
33
|
-
var LogProcessorType = /* @__PURE__ */ function(LogProcessorType2) {
|
|
34
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
35
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
36
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
37
|
-
return LogProcessorType2;
|
|
38
|
-
}({});
|
|
39
|
-
|
|
40
|
-
// packages/common/log/src/scope.ts
|
|
41
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
42
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
43
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
44
|
-
};
|
|
45
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
46
|
-
if (!scope) {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
const res = {};
|
|
50
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
51
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
52
|
-
for (const prop of infoProps) {
|
|
53
|
-
try {
|
|
54
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
55
|
-
} catch (err) {
|
|
56
|
-
res[prop] = err.message;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return res;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// packages/common/log/src/context.ts
|
|
63
|
-
var matchFilter = (filter, level, path) => {
|
|
64
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
65
|
-
};
|
|
66
|
-
var shouldLog = (entry, filters) => {
|
|
67
|
-
if (filters === void 0) {
|
|
68
|
-
return true;
|
|
69
|
-
} else {
|
|
70
|
-
return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var getContextFromEntry = (entry) => {
|
|
74
|
-
let context;
|
|
75
|
-
if (entry.meta) {
|
|
76
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
77
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
78
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
82
|
-
if (entryContext) {
|
|
83
|
-
if (entryContext instanceof Error) {
|
|
84
|
-
const c = entryContext.context;
|
|
85
|
-
context = Object.assign(context ?? {}, {
|
|
86
|
-
error: entryContext.stack,
|
|
87
|
-
...c
|
|
88
|
-
});
|
|
89
|
-
} else if (typeof entryContext === "object") {
|
|
90
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (entry.error) {
|
|
94
|
-
const errorContext = entry.error.context;
|
|
95
|
-
context = Object.assign(context ?? {}, {
|
|
96
|
-
error: entry.error,
|
|
97
|
-
...errorContext
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// packages/common/log/src/decorators.ts
|
|
104
|
-
import chalk from "chalk";
|
|
46
|
+
// src/decorators.ts
|
|
105
47
|
import { inspect } from "node:util";
|
|
48
|
+
import chalk from "chalk";
|
|
106
49
|
var nextPromiseId = 0;
|
|
107
50
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
108
51
|
const method = descriptor.value;
|
|
@@ -199,144 +142,35 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
199
142
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
200
143
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
201
144
|
};
|
|
202
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
203
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
204
145
|
var COLOR_FUNCTION = [
|
|
205
146
|
220,
|
|
206
147
|
220,
|
|
207
148
|
170
|
|
208
149
|
];
|
|
150
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
151
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
209
152
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
210
153
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
211
154
|
|
|
212
|
-
//
|
|
155
|
+
// src/options.ts
|
|
213
156
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
214
157
|
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (filepath) {
|
|
220
|
-
try {
|
|
221
|
-
const text = fs.readFileSync(filepath, "utf-8");
|
|
222
|
-
if (text) {
|
|
223
|
-
return yaml.load(text);
|
|
224
|
-
}
|
|
225
|
-
} catch (err) {
|
|
226
|
-
console.warn(`Invalid log file: ${filepath}`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
// packages/common/log/src/processors/console-processor.ts
|
|
232
|
-
import chalk2 from "chalk";
|
|
233
|
-
import { inspect as inspect2 } from "node:util";
|
|
234
|
-
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
158
|
+
// src/platform/index.ts
|
|
159
|
+
var platform_exports = {};
|
|
160
|
+
__reExport(platform_exports, platform_star);
|
|
161
|
+
import * as platform_star from "#platform";
|
|
235
162
|
|
|
236
|
-
//
|
|
237
|
-
var
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
// packages/common/log/src/processors/console-processor.ts
|
|
247
|
-
var LEVEL_COLORS = {
|
|
248
|
-
[LogLevel.TRACE]: "gray",
|
|
249
|
-
[LogLevel.DEBUG]: "gray",
|
|
250
|
-
[LogLevel.VERBOSE]: "gray",
|
|
251
|
-
[LogLevel.INFO]: "white",
|
|
252
|
-
[LogLevel.WARN]: "yellow",
|
|
253
|
-
[LogLevel.ERROR]: "red"
|
|
254
|
-
};
|
|
255
|
-
var truncate = (text, length = 0, right = false) => {
|
|
256
|
-
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
257
|
-
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
258
|
-
};
|
|
259
|
-
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
260
|
-
const column = config.options?.formatter?.column;
|
|
261
|
-
const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
|
|
262
|
-
let instance;
|
|
263
|
-
if (scope) {
|
|
264
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
265
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
266
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
267
|
-
}
|
|
268
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
269
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
270
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
271
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
272
|
-
formattedTimestamp,
|
|
273
|
-
filepath,
|
|
274
|
-
padding,
|
|
275
|
-
formattedLevel,
|
|
276
|
-
instance,
|
|
277
|
-
message,
|
|
278
|
-
context,
|
|
279
|
-
error
|
|
280
|
-
] : [
|
|
281
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
282
|
-
// Must not truncate for terminal output.
|
|
283
|
-
filepath,
|
|
284
|
-
padding,
|
|
285
|
-
formattedTimestamp,
|
|
286
|
-
formattedLevel,
|
|
287
|
-
instance,
|
|
288
|
-
message,
|
|
289
|
-
context,
|
|
290
|
-
error
|
|
291
|
-
];
|
|
292
|
-
};
|
|
293
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
294
|
-
return [
|
|
295
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
296
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
297
|
-
message
|
|
298
|
-
];
|
|
299
|
-
};
|
|
300
|
-
var formatter = DEFAULT_FORMATTER;
|
|
301
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
302
|
-
const { level, message, meta, error } = entry;
|
|
303
|
-
if (!shouldLog(entry, config.filters)) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const parts = {
|
|
307
|
-
level,
|
|
308
|
-
message,
|
|
309
|
-
error,
|
|
310
|
-
path: void 0,
|
|
311
|
-
line: void 0,
|
|
312
|
-
scope: void 0,
|
|
313
|
-
context: void 0
|
|
314
|
-
};
|
|
315
|
-
if (meta) {
|
|
316
|
-
parts.path = getRelativeFilename(meta.F);
|
|
317
|
-
parts.line = meta.L;
|
|
318
|
-
parts.scope = meta.S;
|
|
319
|
-
}
|
|
320
|
-
const context = getContextFromEntry(entry);
|
|
321
|
-
if (context) {
|
|
322
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
323
|
-
depth: config.options.depth,
|
|
324
|
-
colors: true,
|
|
325
|
-
maxArrayLength: 8,
|
|
326
|
-
sorted: false
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
330
|
-
console.log(line);
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
// packages/common/log/src/processors/debug-processor.ts
|
|
334
|
-
import { inspect as inspect3 } from "node:util";
|
|
335
|
-
var DEBUG_PROCESSOR = (config, entry) => {
|
|
336
|
-
console.log(inspect3(entry, false, null, true));
|
|
337
|
-
};
|
|
163
|
+
// src/processors/index.ts
|
|
164
|
+
var processors_exports = {};
|
|
165
|
+
__export(processors_exports, {
|
|
166
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
167
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
168
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
169
|
+
createFileProcessor: () => createFileProcessor,
|
|
170
|
+
getRelativeFilename: () => getRelativeFilename
|
|
171
|
+
});
|
|
338
172
|
|
|
339
|
-
//
|
|
173
|
+
// src/processors/browser-processor.ts
|
|
340
174
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
341
175
|
var getRelativeFilename2 = (filename) => {
|
|
342
176
|
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
@@ -369,11 +203,15 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
369
203
|
const processPrefix = entry.meta.S?.hostSessionId ? "[worker] " : "";
|
|
370
204
|
args.push(`%c${processPrefix}${scopeName}`, "color:#C026D3;font-weight:bold");
|
|
371
205
|
}
|
|
372
|
-
|
|
206
|
+
if (entry.message) {
|
|
207
|
+
args.push(entry.message);
|
|
208
|
+
}
|
|
373
209
|
const context = getContextFromEntry(entry);
|
|
374
210
|
if (context) {
|
|
375
211
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
376
212
|
args.push(context.error);
|
|
213
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
214
|
+
args.push(context.err);
|
|
377
215
|
} else {
|
|
378
216
|
args.push(context);
|
|
379
217
|
}
|
|
@@ -439,7 +277,17 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
439
277
|
};
|
|
440
278
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
441
279
|
|
|
442
|
-
//
|
|
280
|
+
// src/processors/index.ts
|
|
281
|
+
__reExport(processors_exports, console_processor_star);
|
|
282
|
+
import * as console_processor_star from "#console-processor";
|
|
283
|
+
|
|
284
|
+
// src/processors/debug-processor.ts
|
|
285
|
+
import { inspect as inspect2 } from "node:util";
|
|
286
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
287
|
+
console.log(inspect2(entry, false, null, true));
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/processors/file-processor.ts
|
|
443
291
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
444
292
|
import { dirname } from "node:path";
|
|
445
293
|
import { jsonlogify } from "@dxos/util";
|
|
@@ -508,16 +356,17 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
508
356
|
]
|
|
509
357
|
});
|
|
510
358
|
|
|
511
|
-
//
|
|
359
|
+
// src/options.ts
|
|
512
360
|
var processors = {
|
|
513
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
361
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
514
362
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
515
363
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
516
364
|
};
|
|
517
|
-
var
|
|
365
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
518
366
|
var DEFAULT_PROCESSORS = [
|
|
519
|
-
|
|
367
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
520
368
|
];
|
|
369
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
521
370
|
var parseFilter = (filter) => {
|
|
522
371
|
if (typeof filter === "number") {
|
|
523
372
|
return [
|
|
@@ -526,7 +375,6 @@ var parseFilter = (filter) => {
|
|
|
526
375
|
}
|
|
527
376
|
];
|
|
528
377
|
}
|
|
529
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
530
378
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
531
379
|
return lines.map((filter2) => {
|
|
532
380
|
const [pattern, level] = filter2.split(":");
|
|
@@ -538,54 +386,37 @@ var parseFilter = (filter) => {
|
|
|
538
386
|
};
|
|
539
387
|
});
|
|
540
388
|
};
|
|
541
|
-
var
|
|
542
|
-
const
|
|
389
|
+
var createConfig = (options) => {
|
|
390
|
+
const envOptions = "process" in globalThis ? {
|
|
543
391
|
file: process.env.LOG_CONFIG,
|
|
544
392
|
filter: process.env.LOG_FILTER,
|
|
545
393
|
processor: process.env.LOG_PROCESSOR
|
|
546
394
|
} : void 0;
|
|
547
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
395
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
548
396
|
return {
|
|
549
397
|
options: mergedOptions,
|
|
550
398
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
551
399
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
552
400
|
processors: mergedOptions.processor ? [
|
|
553
401
|
processors[mergedOptions.processor]
|
|
554
|
-
] :
|
|
402
|
+
] : [
|
|
403
|
+
...DEFAULT_PROCESSORS
|
|
404
|
+
],
|
|
555
405
|
prefix: mergedOptions.prefix
|
|
556
406
|
};
|
|
557
407
|
};
|
|
558
408
|
|
|
559
|
-
//
|
|
409
|
+
// src/log.ts
|
|
410
|
+
var logCount = 0;
|
|
560
411
|
var createLog = () => {
|
|
561
412
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
562
|
-
log2
|
|
413
|
+
Object.assign(log2, {
|
|
414
|
+
_id: `log-${++logCount}`,
|
|
415
|
+
_config: createConfig()
|
|
416
|
+
});
|
|
563
417
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
564
418
|
get: () => log2._config
|
|
565
419
|
});
|
|
566
|
-
log2.addProcessor = (processor) => {
|
|
567
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
568
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
569
|
-
}
|
|
570
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
571
|
-
log2._config.processors.push(processor);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
log2.config = (options) => {
|
|
575
|
-
log2._config = getConfig(options);
|
|
576
|
-
};
|
|
577
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
578
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
579
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
580
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
581
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
582
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
583
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error?.message ?? String(error), context, meta, error);
|
|
584
|
-
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");
|
|
585
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
586
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
587
|
-
log2.method = createMethodLogDecorator(log2);
|
|
588
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
589
420
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
590
421
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
591
422
|
level,
|
|
@@ -595,9 +426,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
595
426
|
error
|
|
596
427
|
}));
|
|
597
428
|
};
|
|
429
|
+
Object.assign(log2, {
|
|
430
|
+
/**
|
|
431
|
+
* Update config.
|
|
432
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
433
|
+
* unless an explicit processor option is provided.
|
|
434
|
+
*/
|
|
435
|
+
config: ({ processor, ...options }) => {
|
|
436
|
+
const config = createConfig(options);
|
|
437
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
438
|
+
log2._config = {
|
|
439
|
+
...config,
|
|
440
|
+
processors: processors2
|
|
441
|
+
};
|
|
442
|
+
return log2;
|
|
443
|
+
},
|
|
444
|
+
/**
|
|
445
|
+
* Adds a processor to the logger.
|
|
446
|
+
*/
|
|
447
|
+
addProcessor: (processor) => {
|
|
448
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
449
|
+
log2._config.processors.push(processor);
|
|
450
|
+
}
|
|
451
|
+
return () => {
|
|
452
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
453
|
+
};
|
|
454
|
+
},
|
|
455
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
456
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
457
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
458
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
459
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
460
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
461
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
462
|
+
method: createMethodLogDecorator(log2),
|
|
463
|
+
function: createFunctionLogDecorator(log2),
|
|
464
|
+
break: () => log2.info("-".repeat(80)),
|
|
465
|
+
stack: (message, context, meta) => {
|
|
466
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
467
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
598
470
|
return log2;
|
|
599
471
|
};
|
|
600
|
-
var log = globalThis.
|
|
472
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
601
473
|
var start = Date.now();
|
|
602
474
|
var last = start;
|
|
603
475
|
var debug = (label, args) => {
|
|
@@ -614,12 +486,28 @@ var debug = (label, args) => {
|
|
|
614
486
|
};
|
|
615
487
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
616
488
|
|
|
617
|
-
//
|
|
618
|
-
|
|
489
|
+
// src/index.ts
|
|
490
|
+
__reExport(index_exports, processors_exports);
|
|
491
|
+
|
|
492
|
+
// src/dbg.ts
|
|
493
|
+
var dbg = (arg, meta) => {
|
|
494
|
+
if (meta?.A) {
|
|
495
|
+
console.log(`${meta.A[0]} =`, arg);
|
|
496
|
+
} else {
|
|
497
|
+
console.log(arg);
|
|
498
|
+
}
|
|
499
|
+
return arg;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/experimental/ownership.ts
|
|
503
|
+
import { inspect as inspect3 } from "node:util";
|
|
619
504
|
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
620
505
|
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
621
506
|
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
622
507
|
var OwnershipScope = class {
|
|
508
|
+
constr;
|
|
509
|
+
parent;
|
|
510
|
+
instance;
|
|
623
511
|
constructor(constr, parent) {
|
|
624
512
|
this.constr = constr;
|
|
625
513
|
this.parent = parent;
|
|
@@ -635,7 +523,7 @@ var OwnershipScope = class {
|
|
|
635
523
|
}
|
|
636
524
|
return info;
|
|
637
525
|
}
|
|
638
|
-
[
|
|
526
|
+
[inspect3.custom]() {
|
|
639
527
|
return {
|
|
640
528
|
className: this.constr.name,
|
|
641
529
|
info: this.getInfo(),
|
|
@@ -646,14 +534,13 @@ var OwnershipScope = class {
|
|
|
646
534
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
647
535
|
export {
|
|
648
536
|
BROWSER_PROCESSOR,
|
|
649
|
-
CONSOLE_PROCESSOR,
|
|
650
537
|
DEBUG_PROCESSOR,
|
|
651
|
-
DEFAULT_FORMATTER,
|
|
652
538
|
FILE_PROCESSOR,
|
|
653
539
|
LogLevel,
|
|
654
540
|
LogProcessorType,
|
|
655
|
-
SHORT_FORMATTER,
|
|
656
541
|
createFileProcessor,
|
|
542
|
+
createLog,
|
|
543
|
+
dbg,
|
|
657
544
|
debug,
|
|
658
545
|
gatherLogInfoFromScope,
|
|
659
546
|
getContextFromEntry,
|
|
@@ -666,7 +553,6 @@ export {
|
|
|
666
553
|
parseFilter,
|
|
667
554
|
pick,
|
|
668
555
|
shortLevelName,
|
|
669
|
-
shouldLog
|
|
670
|
-
truncate
|
|
556
|
+
shouldLog
|
|
671
557
|
};
|
|
672
558
|
//# sourceMappingURL=index.mjs.map
|