@dxos/log 0.8.4-main.7ace549 → 0.8.4-main.937b3ca

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.
Files changed (40) hide show
  1. package/dist/lib/browser/chunk-GPOFUMLO.mjs +133 -0
  2. package/dist/lib/browser/chunk-GPOFUMLO.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
  4. package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +74 -162
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/platform/browser/index.mjs +26 -0
  9. package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
  10. package/dist/lib/browser/platform/node/index.mjs +21 -0
  11. package/dist/lib/browser/platform/node/index.mjs.map +7 -0
  12. package/dist/lib/browser/processors/console-processor.mjs +107 -0
  13. package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
  14. package/dist/lib/browser/processors/console-stub.mjs +9 -0
  15. package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
  16. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
  17. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
  18. package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs +135 -0
  19. package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs.map +7 -0
  20. package/dist/lib/node-esm/index.mjs +71 -246
  21. package/dist/lib/node-esm/index.mjs.map +4 -4
  22. package/dist/lib/node-esm/meta.json +1 -1
  23. package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
  24. package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
  25. package/dist/lib/node-esm/platform/node/index.mjs +22 -0
  26. package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
  27. package/dist/lib/node-esm/processors/console-processor.mjs +108 -0
  28. package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
  29. package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
  30. package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
  31. package/dist/types/src/options.d.ts.map +1 -1
  32. package/dist/types/src/platform/index.d.ts +1 -1
  33. package/dist/types/src/platform/index.d.ts.map +1 -1
  34. package/dist/types/src/processors/index.d.ts +3 -3
  35. package/dist/types/src/processors/index.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +29 -9
  38. package/src/options.ts +3 -1
  39. package/src/platform/index.ts +1 -1
  40. package/src/processors/index.ts +3 -3
@@ -0,0 +1,135 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/config.ts
4
+ var LogLevel = /* @__PURE__ */ (function(LogLevel2) {
5
+ LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
6
+ LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
7
+ LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
8
+ LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
9
+ LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
10
+ LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
11
+ return LogLevel2;
12
+ })({});
13
+ var levels = {
14
+ "*": 5,
15
+ trace: 5,
16
+ debug: 10,
17
+ verbose: 11,
18
+ info: 12,
19
+ warn: 13,
20
+ error: 14
21
+ };
22
+ var shortLevelName = {
23
+ [5]: "T",
24
+ [10]: "D",
25
+ [11]: "V",
26
+ [12]: "I",
27
+ [13]: "W",
28
+ [14]: "E"
29
+ };
30
+ var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
31
+ LogProcessorType2["CONSOLE"] = "console";
32
+ LogProcessorType2["BROWSER"] = "browser";
33
+ LogProcessorType2["DEBUG"] = "debug";
34
+ return LogProcessorType2;
35
+ })({});
36
+
37
+ // src/scope.ts
38
+ var logInfoProperties = Symbol("logInfoProperties");
39
+ var logInfo = (target, propertyKey, descriptor) => {
40
+ (target[logInfoProperties] ??= []).push(propertyKey);
41
+ };
42
+ var gatherLogInfoFromScope = (scope) => {
43
+ if (!scope) {
44
+ return {};
45
+ }
46
+ const res = {};
47
+ const prototype = Object.getPrototypeOf(scope);
48
+ const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
49
+ for (const prop of infoProps) {
50
+ try {
51
+ res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
52
+ } catch (err) {
53
+ res[prop] = err.message;
54
+ }
55
+ }
56
+ return res;
57
+ };
58
+
59
+ // src/context.ts
60
+ var matchFilter = (filter, level, path) => {
61
+ if (filter.pattern?.startsWith("-")) {
62
+ if (path?.includes(filter.pattern.slice(1))) {
63
+ if (level >= filter.level) {
64
+ return false;
65
+ }
66
+ }
67
+ } else {
68
+ if (filter.pattern?.length) {
69
+ if (path?.includes(filter.pattern)) {
70
+ return level >= filter.level;
71
+ }
72
+ } else {
73
+ if (level >= filter.level) {
74
+ return true;
75
+ }
76
+ }
77
+ }
78
+ };
79
+ var shouldLog = (entry, filters) => {
80
+ if (filters === void 0) {
81
+ return false;
82
+ }
83
+ const results = filters.map((filter) => matchFilter(filter, entry.level, entry.meta?.F)).filter((result) => result !== void 0);
84
+ return results.length > 0 && !results.some((results2) => results2 === false);
85
+ };
86
+ var getContextFromEntry = (entry) => {
87
+ let context;
88
+ if (entry.meta) {
89
+ const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
90
+ if (Object.keys(scopeInfo).length > 0) {
91
+ context = Object.assign(context ?? {}, scopeInfo);
92
+ }
93
+ }
94
+ const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
95
+ if (entryContext) {
96
+ if (entryContext instanceof Error) {
97
+ const c = entryContext.context;
98
+ context = Object.assign(context ?? {}, {
99
+ error: entryContext.stack,
100
+ ...c
101
+ });
102
+ } else if (typeof entryContext === "object") {
103
+ context = Object.assign(context ?? {}, entryContext);
104
+ }
105
+ }
106
+ if (entry.error) {
107
+ context = Object.assign(context ?? {}, {
108
+ error: entry.error
109
+ });
110
+ }
111
+ return context && Object.keys(context).length > 0 ? context : void 0;
112
+ };
113
+
114
+ // src/processors/common.ts
115
+ var getRelativeFilename = (filename) => {
116
+ const match = filename.match(/.+\/(packages\/.+\/.+)/);
117
+ if (match) {
118
+ const [, filePath] = match;
119
+ return filePath;
120
+ }
121
+ return filename;
122
+ };
123
+
124
+ export {
125
+ LogLevel,
126
+ levels,
127
+ shortLevelName,
128
+ LogProcessorType,
129
+ logInfo,
130
+ gatherLogInfoFromScope,
131
+ shouldLog,
132
+ getContextFromEntry,
133
+ getRelativeFilename
134
+ };
135
+ //# sourceMappingURL=chunk-QPYJZ4SO.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/config.ts", "../../../src/scope.ts", "../../../src/context.ts", "../../../src/processors/common.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n * NOTE: Keep aligned with LogLevel in @dxos/protocols.\n */\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n VERBOSE = 11,\n INFO = 12,\n WARN = 13,\n ERROR = 14,\n}\n\nexport const levels: Record<string, LogLevel> = {\n '*': LogLevel.TRACE,\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\n verbose: LogLevel.VERBOSE,\n info: LogLevel.INFO,\n warn: LogLevel.WARN,\n error: LogLevel.ERROR,\n};\n\nexport const shortLevelName = {\n [LogLevel.TRACE]: 'T',\n [LogLevel.DEBUG]: 'D',\n [LogLevel.VERBOSE]: 'V',\n [LogLevel.INFO]: 'I',\n [LogLevel.WARN]: 'W',\n [LogLevel.ERROR]: 'E',\n};\n\nexport enum LogProcessorType {\n CONSOLE = 'console',\n BROWSER = 'browser',\n DEBUG = 'debug',\n}\n\n/**\n * Individual filter condition.\n */\nexport type LogFilter = {\n level: LogLevel;\n pattern?: string;\n};\n\n/**\n * Options to set inline or load from the YML file.\n */\nexport type LogOptions = {\n file?: string;\n filter?: string | string[] | LogLevel;\n captureFilter?: string | string[] | LogLevel;\n depth?: number; // Context object depth.\n processor?: string | LogProcessorType;\n formatter?: {\n column: number;\n timestamp: boolean;\n timestampFirst: boolean;\n };\n prefix?: string;\n};\n\n/**\n * Runtime config.\n */\nexport interface LogConfig {\n options: LogOptions;\n filters?: LogFilter[];\n captureFilters?: LogFilter[];\n processors: LogProcessor[];\n prefix?: string;\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nconst logInfoProperties = Symbol('logInfoProperties');\n\n/**\n * Decorate fields, properties, or methods to automatically include their values in log messages.\n *\n * Example:\n *\n * ```typescript\n * class Example {\n * @logInfo\n * peerId: PublicKey;\n * }\n * ```\n */\nexport const logInfo = (target: any, propertyKey: string, descriptor?: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[logInfoProperties] ??= []).push(propertyKey);\n};\n\n/**\n * Introspects class instance to find decorated metadata.\n * @param scope Class instance.\n */\nexport const gatherLogInfoFromScope = (scope: any): Record<string, any> => {\n if (!scope) {\n return {};\n }\n\n const res: Record<string, any> = {};\n\n const prototype = Object.getPrototypeOf(scope);\n const infoProps = (typeof prototype === 'object' && prototype !== null ? prototype[logInfoProperties] : []) ?? [];\n for (const prop of infoProps) {\n try {\n res[prop] = typeof scope[prop] === 'function' ? scope[prop]() : scope[prop];\n } catch (err: any) {\n res[prop] = err.message;\n }\n }\n\n return res;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, type LogFilter, type LogLevel } from './config';\nimport { type CallMetadata } from './meta';\nimport { gatherLogInfoFromScope } from './scope';\n\n/**\n * Optional object passed to the logging API.\n */\nexport type LogContext = Record<string, any> | Error | any;\n\n/**\n * Record for current log line.\n */\nexport interface LogEntry {\n level: LogLevel;\n message?: string;\n context?: LogContext;\n meta?: CallMetadata;\n error?: Error;\n}\n\n/**\n * Processes (e.g., prints, forwards) log entries.\n */\nexport type LogProcessor = (config: LogConfig, entry: LogEntry) => void;\n\n/**\n * Returns:\n * true if the log entry matches the filter,\n * false if should be excluded, or\n * undefined if it the filter doesn't match the level.\n */\nconst matchFilter = (filter: LogFilter, level: LogLevel, path?: string): boolean | undefined => {\n // TODO(burdon): Support regexp.\n if (filter.pattern?.startsWith('-')) {\n // Exclude.\n if (path?.includes(filter.pattern.slice(1))) {\n if (level >= filter.level) {\n return false;\n }\n }\n } else {\n // Include.\n if (filter.pattern?.length) {\n if (path?.includes(filter.pattern)) {\n return level >= filter.level;\n }\n } else {\n if (level >= filter.level) {\n return true;\n }\n }\n }\n};\n\n/**\n * Determines if the current line should be logged (called by the processor).\n */\nexport const shouldLog = (entry: LogEntry, filters?: LogFilter[]): boolean => {\n if (filters === undefined) {\n return false;\n }\n\n const results = filters\n .map((filter) => matchFilter(filter, entry.level, entry.meta?.F))\n .filter((result): result is boolean => result !== undefined);\n\n // Skip if any are explicitely false.\n // console.log({ level: entry.level, path: entry.meta?.F }, filters, results, results.length);\n return results.length > 0 && !results.some((results) => results === false);\n};\n\nexport const getContextFromEntry = (entry: LogEntry): Record<string, any> | undefined => {\n let context;\n if (entry.meta) {\n const scopeInfo = gatherLogInfoFromScope(entry.meta.S);\n if (Object.keys(scopeInfo).length > 0) {\n context = Object.assign(context ?? {}, scopeInfo);\n }\n }\n\n const entryContext = typeof entry.context === 'function' ? entry.context() : entry.context;\n if (entryContext) {\n if (entryContext instanceof Error) {\n // Additional context from Error.\n const c = (entryContext as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entryContext.stack, ...c });\n } else if (typeof entryContext === 'object') {\n context = Object.assign(context ?? {}, entryContext);\n }\n }\n\n if (entry.error) {\n context = Object.assign(context ?? {}, { error: entry.error });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const getRelativeFilename = (filename: string) => {\n // TODO(burdon): Hack uses \"packages\" as an anchor (pre-parse NX?)\n // Including `packages/` part of the path so that excluded paths (e.g. from dist) are clickable in vscode.\n const match = filename.match(/.+\\/(packages\\/.+\\/.+)/);\n if (match) {\n const [, filePath] = match;\n return filePath;\n }\n\n return filename;\n};\n"],
5
+ "mappings": "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",
6
+ "names": ["LogLevel", "levels", "trace", "debug", "verbose", "info", "warn", "error", "shortLevelName", "LogProcessorType", "logInfoProperties", "Symbol", "logInfo", "target", "propertyKey", "descriptor", "push", "gatherLogInfoFromScope", "scope", "res", "prototype", "Object", "getPrototypeOf", "infoProps", "prop", "err", "message", "matchFilter", "filter", "level", "path", "pattern", "startsWith", "includes", "slice", "length", "shouldLog", "entry", "filters", "undefined", "results", "map", "meta", "F", "result", "some", "getContextFromEntry", "context", "scopeInfo", "gatherLogInfoFromScope", "S", "Object", "keys", "assign", "entryContext", "Error", "c", "error", "stack", "getRelativeFilename", "filename", "match", "filePath"]
7
+ }
@@ -1,120 +1,47 @@
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
+ debug: () => debug,
29
+ gatherLogInfoFromScope: () => gatherLogInfoFromScope,
30
+ getContextFromEntry: () => getContextFromEntry,
31
+ getCurrentOwnershipScope: () => getCurrentOwnershipScope,
32
+ getRelativeFilename: () => getRelativeFilename,
33
+ levels: () => levels,
34
+ log: () => log,
35
+ logInfo: () => logInfo,
36
+ omit: () => omit,
37
+ parseFilter: () => parseFilter,
38
+ pick: () => pick,
39
+ shortLevelName: () => shortLevelName,
40
+ shouldLog: () => shouldLog
41
+ });
4
42
  import omit from "lodash.omit";
5
43
  import { pick } from "@dxos/util";
6
44
 
7
- // src/config.ts
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
- "*": 5,
19
- trace: 5,
20
- debug: 10,
21
- verbose: 11,
22
- info: 12,
23
- warn: 13,
24
- error: 14
25
- };
26
- var shortLevelName = {
27
- [5]: "T",
28
- [10]: "D",
29
- [11]: "V",
30
- [12]: "I",
31
- [13]: "W",
32
- [14]: "E"
33
- };
34
- var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
35
- LogProcessorType2["CONSOLE"] = "console";
36
- LogProcessorType2["BROWSER"] = "browser";
37
- LogProcessorType2["DEBUG"] = "debug";
38
- return LogProcessorType2;
39
- })({});
40
-
41
- // src/scope.ts
42
- var logInfoProperties = Symbol("logInfoProperties");
43
- var logInfo = (target, propertyKey, descriptor) => {
44
- (target[logInfoProperties] ??= []).push(propertyKey);
45
- };
46
- var gatherLogInfoFromScope = (scope) => {
47
- if (!scope) {
48
- return {};
49
- }
50
- const res = {};
51
- const prototype = Object.getPrototypeOf(scope);
52
- const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
53
- for (const prop of infoProps) {
54
- try {
55
- res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
56
- } catch (err) {
57
- res[prop] = err.message;
58
- }
59
- }
60
- return res;
61
- };
62
-
63
- // src/context.ts
64
- var matchFilter = (filter, level, path) => {
65
- if (filter.pattern?.startsWith("-")) {
66
- if (path?.includes(filter.pattern.slice(1))) {
67
- if (level >= filter.level) {
68
- return false;
69
- }
70
- }
71
- } else {
72
- if (filter.pattern?.length) {
73
- if (path?.includes(filter.pattern)) {
74
- return level >= filter.level;
75
- }
76
- } else {
77
- if (level >= filter.level) {
78
- return true;
79
- }
80
- }
81
- }
82
- };
83
- var shouldLog = (entry, filters) => {
84
- if (filters === void 0) {
85
- return false;
86
- }
87
- const results = filters.map((filter) => matchFilter(filter, entry.level, entry.meta?.F)).filter((result) => result !== void 0);
88
- return results.length > 0 && !results.some((results2) => results2 === false);
89
- };
90
- var getContextFromEntry = (entry) => {
91
- let context;
92
- if (entry.meta) {
93
- const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
94
- if (Object.keys(scopeInfo).length > 0) {
95
- context = Object.assign(context ?? {}, scopeInfo);
96
- }
97
- }
98
- const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
99
- if (entryContext) {
100
- if (entryContext instanceof Error) {
101
- const c = entryContext.context;
102
- context = Object.assign(context ?? {}, {
103
- error: entryContext.stack,
104
- ...c
105
- });
106
- } else if (typeof entryContext === "object") {
107
- context = Object.assign(context ?? {}, entryContext);
108
- }
109
- }
110
- if (entry.error) {
111
- context = Object.assign(context ?? {}, {
112
- error: entry.error
113
- });
114
- }
115
- return context && Object.keys(context).length > 0 ? context : void 0;
116
- };
117
-
118
45
  // src/decorators.ts
119
46
  import { inspect } from "node:util";
120
47
  import chalk from "chalk";
@@ -227,131 +154,20 @@ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
227
154
  // src/options.ts
228
155
  import defaultsDeep from "lodash.defaultsdeep";
229
156
 
230
- // src/platform/node/index.ts
231
- import fs from "node:fs";
232
- import yaml from "js-yaml";
233
- var loadOptions = (filepath) => {
234
- if (filepath) {
235
- try {
236
- const text = fs.readFileSync(filepath, "utf-8");
237
- if (text) {
238
- return yaml.load(text);
239
- }
240
- } catch (err) {
241
- console.warn(`Invalid log file: ${filepath}`);
242
- }
243
- }
244
- };
245
-
246
- // src/processors/console-processor.ts
247
- import { inspect as inspect2 } from "node:util";
248
- import chalk2 from "chalk";
249
- import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
250
-
251
- // src/processors/common.ts
252
- var getRelativeFilename = (filename) => {
253
- const match = filename.match(/.+\/(packages\/.+\/.+)/);
254
- if (match) {
255
- const [, filePath] = match;
256
- return filePath;
257
- }
258
- return filename;
259
- };
260
-
261
- // src/processors/console-processor.ts
262
- var LEVEL_COLORS = {
263
- [LogLevel.TRACE]: "gray",
264
- [LogLevel.DEBUG]: "gray",
265
- [LogLevel.VERBOSE]: "gray",
266
- [LogLevel.INFO]: "white",
267
- [LogLevel.WARN]: "yellow",
268
- [LogLevel.ERROR]: "red"
269
- };
270
- var truncate = (text, length = 0, right = false) => {
271
- const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
272
- return right ? str.padStart(length, " ") : str.padEnd(length, " ");
273
- };
274
- var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
275
- const column = config.options?.formatter?.column;
276
- const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
277
- let instance;
278
- if (scope) {
279
- const prototype = Object.getPrototypeOf(scope);
280
- if (prototype !== null) {
281
- const id = getPrototypeSpecificInstanceId(scope);
282
- instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
283
- }
284
- }
285
- const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
286
- const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
287
- const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
288
- return config.options?.formatter?.timestampFirst ? [
289
- formattedTimestamp,
290
- filepath,
291
- padding,
292
- formattedLevel,
293
- instance,
294
- message,
295
- context,
296
- error
297
- ] : [
298
- // NOTE: File path must come fist for console hyperlinks.
299
- // Must not truncate for terminal output.
300
- filepath,
301
- padding,
302
- formattedTimestamp,
303
- formattedLevel,
304
- instance,
305
- message,
306
- context,
307
- error
308
- ];
309
- };
310
- var SHORT_FORMATTER = (config, { path, level, message }) => {
311
- return [
312
- chalk2.grey(truncate(path, 16, true)),
313
- chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
314
- message
315
- ];
316
- };
317
- var formatter = DEFAULT_FORMATTER;
318
- var CONSOLE_PROCESSOR = (config, entry) => {
319
- const { level, message, meta, error } = entry;
320
- if (!shouldLog(entry, config.filters)) {
321
- return;
322
- }
323
- const parts = {
324
- level,
325
- message,
326
- error,
327
- path: void 0,
328
- line: void 0,
329
- scope: void 0,
330
- context: void 0
331
- };
332
- if (meta) {
333
- parts.path = getRelativeFilename(meta.F);
334
- parts.line = meta.L;
335
- parts.scope = meta.S;
336
- }
337
- const context = getContextFromEntry(entry);
338
- if (context) {
339
- parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
340
- depth: config.options.depth,
341
- colors: true,
342
- maxArrayLength: 8,
343
- sorted: false
344
- });
345
- }
346
- const line = formatter(config, parts).filter(Boolean).join(" ");
347
- console.log(line);
348
- };
157
+ // src/platform/index.ts
158
+ var platform_exports = {};
159
+ __reExport(platform_exports, platform_star);
160
+ import * as platform_star from "#platform";
349
161
 
350
- // src/processors/debug-processor.ts
351
- import { inspect as inspect3 } from "node:util";
352
- var DEBUG_PROCESSOR = (config, entry) => {
353
- console.log(inspect3(entry, false, null, true));
354
- };
162
+ // src/processors/index.ts
163
+ var processors_exports = {};
164
+ __export(processors_exports, {
165
+ BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
166
+ DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
167
+ FILE_PROCESSOR: () => FILE_PROCESSOR,
168
+ createFileProcessor: () => createFileProcessor,
169
+ getRelativeFilename: () => getRelativeFilename
170
+ });
355
171
 
356
172
  // src/processors/browser-processor.ts
357
173
  import { getDebugName, safariCheck } from "@dxos/util";
@@ -460,6 +276,16 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
460
276
  };
461
277
  var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
462
278
 
279
+ // src/processors/index.ts
280
+ __reExport(processors_exports, console_processor_star);
281
+ import * as console_processor_star from "#console-processor";
282
+
283
+ // src/processors/debug-processor.ts
284
+ import { inspect as inspect2 } from "node:util";
285
+ var DEBUG_PROCESSOR = (config, entry) => {
286
+ console.log(inspect2(entry, false, null, true));
287
+ };
288
+
463
289
  // src/processors/file-processor.ts
464
290
  import { appendFileSync, mkdirSync, openSync } from "node:fs";
465
291
  import { dirname } from "node:path";
@@ -531,13 +357,13 @@ var FILE_PROCESSOR = createFileProcessor({
531
357
 
532
358
  // src/options.ts
533
359
  var processors = {
534
- [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
360
+ [LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
535
361
  [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
536
362
  [LogProcessorType.DEBUG]: DEBUG_PROCESSOR
537
363
  };
538
- var browser = typeof window !== "undefined" || typeof navigator !== "undefined";
364
+ var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
539
365
  var DEFAULT_PROCESSORS = [
540
- browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
366
+ browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
541
367
  ];
542
368
  var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
543
369
  var parseFilter = (filter) => {
@@ -565,7 +391,7 @@ var createConfig = (options) => {
565
391
  filter: process.env.LOG_FILTER,
566
392
  processor: process.env.LOG_PROCESSOR
567
393
  } : void 0;
568
- const mergedOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
394
+ const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
569
395
  return {
570
396
  options: mergedOptions,
571
397
  filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
@@ -659,8 +485,11 @@ var debug = (label, args) => {
659
485
  };
660
486
  var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
661
487
 
488
+ // src/index.ts
489
+ __reExport(index_exports, processors_exports);
490
+
662
491
  // src/experimental/ownership.ts
663
- import { inspect as inspect4 } from "node:util";
492
+ import { inspect as inspect3 } from "node:util";
664
493
  var kOwnershipScope = Symbol("kOwnershipScope");
665
494
  var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
666
495
  var kDebugInfoProperties = Symbol("kDebugInfoProperties");
@@ -683,7 +512,7 @@ var OwnershipScope = class {
683
512
  }
684
513
  return info;
685
514
  }
686
- [inspect4.custom]() {
515
+ [inspect3.custom]() {
687
516
  return {
688
517
  className: this.constr.name,
689
518
  info: this.getInfo(),
@@ -694,13 +523,10 @@ var OwnershipScope = class {
694
523
  var getCurrentOwnershipScope = (thisRef) => thisRef;
695
524
  export {
696
525
  BROWSER_PROCESSOR,
697
- CONSOLE_PROCESSOR,
698
526
  DEBUG_PROCESSOR,
699
- DEFAULT_FORMATTER,
700
527
  FILE_PROCESSOR,
701
528
  LogLevel,
702
529
  LogProcessorType,
703
- SHORT_FORMATTER,
704
530
  createFileProcessor,
705
531
  createLog,
706
532
  debug,
@@ -715,7 +541,6 @@ export {
715
541
  parseFilter,
716
542
  pick,
717
543
  shortLevelName,
718
- shouldLog,
719
- truncate
544
+ shouldLog
720
545
  };
721
546
  //# sourceMappingURL=index.mjs.map