@dxos/log 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (65) hide show
  1. package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
  2. package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-M2YHSBML.mjs +133 -0
  4. package/dist/lib/browser/chunk-M2YHSBML.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +165 -169
  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-62VKC2WQ.mjs +135 -0
  19. package/dist/lib/node-esm/chunk-62VKC2WQ.mjs.map +7 -0
  20. package/dist/lib/node-esm/index.mjs +162 -253
  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/dbg.d.ts +23 -0
  32. package/dist/types/src/dbg.d.ts.map +1 -0
  33. package/dist/types/src/decorators.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +3 -2
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/log-buffer.d.ts +40 -0
  37. package/dist/types/src/log-buffer.d.ts.map +1 -0
  38. package/dist/types/src/log-buffer.test.d.ts +2 -0
  39. package/dist/types/src/log-buffer.test.d.ts.map +1 -0
  40. package/dist/types/src/log.d.ts +3 -1
  41. package/dist/types/src/log.d.ts.map +1 -1
  42. package/dist/types/src/options.d.ts.map +1 -1
  43. package/dist/types/src/platform/index.d.ts +1 -1
  44. package/dist/types/src/platform/index.d.ts.map +1 -1
  45. package/dist/types/src/platform/node/index.d.ts.map +1 -1
  46. package/dist/types/src/processors/console-processor.d.ts.map +1 -1
  47. package/dist/types/src/processors/file-processor.d.ts.map +1 -1
  48. package/dist/types/src/processors/index.d.ts +3 -3
  49. package/dist/types/src/processors/index.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +30 -12
  52. package/src/dbg.ts +34 -0
  53. package/src/decorators.ts +1 -2
  54. package/src/experimental/classes.test.ts +0 -1
  55. package/src/index.ts +3 -3
  56. package/src/log-buffer.test.ts +155 -0
  57. package/src/log-buffer.ts +117 -0
  58. package/src/log.test.ts +0 -1
  59. package/src/log.ts +4 -2
  60. package/src/options.ts +3 -1
  61. package/src/platform/index.ts +1 -1
  62. package/src/platform/node/index.ts +1 -2
  63. package/src/processors/console-processor.ts +1 -3
  64. package/src/processors/file-processor.ts +0 -1
  65. 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 = /* @__PURE__ */ 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-62VKC2WQ.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": ";;;AAWO,IAAKA,WAAAA,0BAAAA,WAAAA;;;;;;;SAAAA;;AASL,IAAMC,SAAmC;EAC9C,KAAG;EACHC,OAAK;EACLC,OAAK;EACLC,SAAO;EACPC,MAAI;EACJC,MAAI;EACJC,OAAK;AACP;AAEO,IAAMC,iBAAiB;EAC5B,CAAA,CAAA,GAAkB;EAClB,CAAA,EAAA,GAAkB;EAClB,CAAA,E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;AAEA,SAAOF;AACT;",
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,123 +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-62VKC2WQ.mjs";
13
+ import {
14
+ __export,
15
+ __reExport
16
+ } from "./chunk-2SZHAWBN.mjs";
2
17
 
3
18
  // src/index.ts
4
- import omit from "lodash.omit";
5
- import { pick } from "@dxos/util";
6
-
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
- };
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
22
+ DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
23
+ FILE_PROCESSOR: () => FILE_PROCESSOR,
24
+ LogBuffer: () => LogBuffer,
25
+ LogLevel: () => LogLevel,
26
+ LogProcessorType: () => LogProcessorType,
27
+ createFileProcessor: () => createFileProcessor,
28
+ createLog: () => createLog,
29
+ dbg: () => dbg,
30
+ debug: () => debug,
31
+ gatherLogInfoFromScope: () => gatherLogInfoFromScope,
32
+ getContextFromEntry: () => getContextFromEntry,
33
+ getCurrentOwnershipScope: () => getCurrentOwnershipScope,
34
+ getRelativeFilename: () => getRelativeFilename,
35
+ levels: () => levels,
36
+ log: () => log,
37
+ logInfo: () => logInfo,
38
+ omit: () => omit,
39
+ parseFilter: () => parseFilter,
40
+ pick: () => pick,
41
+ shortLevelName: () => shortLevelName,
42
+ shouldLog: () => shouldLog
43
+ });
44
+ import { omit, pick } from "@dxos/util";
117
45
 
118
46
  // src/decorators.ts
119
- import { inspect } from "node:util";
120
47
  import chalk from "chalk";
48
+ import { inspect } from "node:util";
121
49
  var nextPromiseId = 0;
122
50
  var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
123
51
  const method = descriptor.value;
@@ -227,131 +155,20 @@ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
227
155
  // src/options.ts
228
156
  import defaultsDeep from "lodash.defaultsdeep";
229
157
 
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
- };
158
+ // src/platform/index.ts
159
+ var platform_exports = {};
160
+ __reExport(platform_exports, platform_star);
161
+ import * as platform_star from "#platform";
349
162
 
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
- };
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
+ });
355
172
 
356
173
  // src/processors/browser-processor.ts
357
174
  import { getDebugName, safariCheck } from "@dxos/util";
@@ -460,6 +277,16 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
460
277
  };
461
278
  var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
462
279
 
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
+
463
290
  // src/processors/file-processor.ts
464
291
  import { appendFileSync, mkdirSync, openSync } from "node:fs";
465
292
  import { dirname } from "node:path";
@@ -531,13 +358,13 @@ var FILE_PROCESSOR = createFileProcessor({
531
358
 
532
359
  // src/options.ts
533
360
  var processors = {
534
- [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
361
+ [LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
535
362
  [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
536
363
  [LogProcessorType.DEBUG]: DEBUG_PROCESSOR
537
364
  };
538
- var browser = typeof window !== "undefined" || typeof navigator !== "undefined";
365
+ var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
539
366
  var DEFAULT_PROCESSORS = [
540
- browser ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR
367
+ browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
541
368
  ];
542
369
  var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
543
370
  var parseFilter = (filter) => {
@@ -565,7 +392,7 @@ var createConfig = (options) => {
565
392
  filter: process.env.LOG_FILTER,
566
393
  processor: process.env.LOG_PROCESSOR
567
394
  } : void 0;
568
- const mergedOptions = defaultsDeep({}, loadOptions(envOptions?.file), envOptions, options);
395
+ const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
569
396
  return {
570
397
  options: mergedOptions,
571
398
  filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
@@ -605,7 +432,7 @@ var createLog = () => {
605
432
  * NOTE: Preserves any processors that were already added to this logger instance
606
433
  * unless an explicit processor option is provided.
607
434
  */
608
- config: ({ processor, ...options }) => {
435
+ config: ({ processor, ...options } = {}) => {
609
436
  const config = createConfig(options);
610
437
  const processors2 = processor ? config.processors : log2._config.processors;
611
438
  log2._config = {
@@ -659,11 +486,95 @@ var debug = (label, args) => {
659
486
  };
660
487
  var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
661
488
 
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/log-buffer.ts
503
+ import { CircularBuffer, getDebugName as getDebugName2 } from "@dxos/util";
504
+ var DEFAULT_BUFFER_SIZE = 2e3;
505
+ var MAX_CONTEXT_LENGTH = 500;
506
+ var LogBuffer = class {
507
+ _buffer;
508
+ constructor(size = DEFAULT_BUFFER_SIZE) {
509
+ this._buffer = new CircularBuffer(size);
510
+ }
511
+ /**
512
+ * Log processor that can be registered with `log.runtimeConfig.processors`.
513
+ * Captures every level except TRACE (does not apply `shouldLog` / filter; use for full debug dumps).
514
+ */
515
+ logProcessor = (_config, entry) => {
516
+ if (entry.level <= LogLevel.TRACE) {
517
+ return;
518
+ }
519
+ const record = {
520
+ t: (/* @__PURE__ */ new Date()).toISOString(),
521
+ l: shortLevelName[entry.level] ?? "?",
522
+ m: entry.message ?? ""
523
+ };
524
+ if (entry.meta) {
525
+ record.f = getRelativeFilename3(entry.meta.F);
526
+ record.n = entry.meta.L;
527
+ }
528
+ if (entry.error) {
529
+ record.e = entry.error.stack ?? entry.error.message;
530
+ }
531
+ if (entry.context != null) {
532
+ try {
533
+ const ctx = typeof entry.context === "function" ? entry.context() : entry.context;
534
+ if (ctx != null && !(ctx instanceof Error)) {
535
+ let json = JSON.stringify(ctx);
536
+ if (json.length > MAX_CONTEXT_LENGTH) {
537
+ json = json.slice(0, MAX_CONTEXT_LENGTH);
538
+ }
539
+ record.c = json;
540
+ }
541
+ } catch {
542
+ }
543
+ }
544
+ const scope = entry.meta?.S;
545
+ if (typeof scope === "object" && scope !== null && Object.getPrototypeOf(scope) !== Object.prototype) {
546
+ record.o = getDebugName2(scope);
547
+ }
548
+ this._buffer.push(record);
549
+ };
550
+ /** Number of entries currently in the buffer. */
551
+ get size() {
552
+ return this._buffer.elementCount;
553
+ }
554
+ /** Discard all buffered entries. */
555
+ clear() {
556
+ this._buffer.clear();
557
+ }
558
+ /** Serialize buffer contents as NDJSON (newline-delimited JSON). */
559
+ serialize() {
560
+ const lines = [];
561
+ for (const record of this._buffer) {
562
+ lines.push(JSON.stringify(record));
563
+ }
564
+ return lines.join("\n");
565
+ }
566
+ };
567
+ var getRelativeFilename3 = (filename) => {
568
+ const match = filename.match(/.+\/(packages\/.+\/.+)/);
569
+ if (match) {
570
+ return match[1];
571
+ }
572
+ return filename;
573
+ };
574
+
662
575
  // src/experimental/ownership.ts
663
- import { inspect as inspect4 } from "node:util";
664
- var kOwnershipScope = Symbol("kOwnershipScope");
665
- var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
666
- var kDebugInfoProperties = Symbol("kDebugInfoProperties");
576
+ import { inspect as inspect3 } from "node:util";
577
+ var kDebugInfoProperties = /* @__PURE__ */ Symbol("kDebugInfoProperties");
667
578
  var OwnershipScope = class {
668
579
  constr;
669
580
  parent;
@@ -683,7 +594,7 @@ var OwnershipScope = class {
683
594
  }
684
595
  return info;
685
596
  }
686
- [inspect4.custom]() {
597
+ [inspect3.custom]() {
687
598
  return {
688
599
  className: this.constr.name,
689
600
  info: this.getInfo(),
@@ -694,15 +605,14 @@ var OwnershipScope = class {
694
605
  var getCurrentOwnershipScope = (thisRef) => thisRef;
695
606
  export {
696
607
  BROWSER_PROCESSOR,
697
- CONSOLE_PROCESSOR,
698
608
  DEBUG_PROCESSOR,
699
- DEFAULT_FORMATTER,
700
609
  FILE_PROCESSOR,
610
+ LogBuffer,
701
611
  LogLevel,
702
612
  LogProcessorType,
703
- SHORT_FORMATTER,
704
613
  createFileProcessor,
705
614
  createLog,
615
+ dbg,
706
616
  debug,
707
617
  gatherLogInfoFromScope,
708
618
  getContextFromEntry,
@@ -715,7 +625,6 @@ export {
715
625
  parseFilter,
716
626
  pick,
717
627
  shortLevelName,
718
- shouldLog,
719
- truncate
628
+ shouldLog
720
629
  };
721
630
  //# sourceMappingURL=index.mjs.map