@dxos/log 0.8.4-main.fbb7a13 → 0.8.4-main.fcc0d83b33

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 (73) hide show
  1. package/dist/lib/browser/chunk-V7FYKT4H.mjs +311 -0
  2. package/dist/lib/browser/chunk-V7FYKT4H.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +236 -43
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/platform/node/index.mjs +1 -1
  7. package/dist/lib/browser/platform/node/index.mjs.map +3 -3
  8. package/dist/lib/browser/processors/console-processor.mjs +6 -11
  9. package/dist/lib/browser/processors/console-processor.mjs.map +3 -3
  10. package/dist/lib/node-esm/chunk-5TBDXMQF.mjs +313 -0
  11. package/dist/lib/node-esm/chunk-5TBDXMQF.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +236 -43
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/platform/node/index.mjs +1 -1
  16. package/dist/lib/node-esm/platform/node/index.mjs.map +3 -3
  17. package/dist/lib/node-esm/processors/console-processor.mjs +6 -11
  18. package/dist/lib/node-esm/processors/console-processor.mjs.map +3 -3
  19. package/dist/types/src/context.d.ts +78 -2
  20. package/dist/types/src/context.d.ts.map +1 -1
  21. package/dist/types/src/dbg.d.ts +23 -0
  22. package/dist/types/src/dbg.d.ts.map +1 -0
  23. package/dist/types/src/decorators.d.ts.map +1 -1
  24. package/dist/types/src/environment.d.ts +24 -0
  25. package/dist/types/src/environment.d.ts.map +1 -0
  26. package/dist/types/src/environment.test.d.ts +2 -0
  27. package/dist/types/src/environment.test.d.ts.map +1 -0
  28. package/dist/types/src/experimental/ownership.d.ts.map +1 -1
  29. package/dist/types/src/index.d.ts +7 -3
  30. package/dist/types/src/index.d.ts.map +1 -1
  31. package/dist/types/src/jsonl.d.ts +53 -0
  32. package/dist/types/src/jsonl.d.ts.map +1 -0
  33. package/dist/types/src/jsonl.test.d.ts +2 -0
  34. package/dist/types/src/jsonl.test.d.ts.map +1 -0
  35. package/dist/types/src/log-buffer.d.ts +20 -0
  36. package/dist/types/src/log-buffer.d.ts.map +1 -0
  37. package/dist/types/src/log-buffer.test.d.ts +2 -0
  38. package/dist/types/src/log-buffer.test.d.ts.map +1 -0
  39. package/dist/types/src/log.d.ts +44 -1
  40. package/dist/types/src/log.d.ts.map +1 -1
  41. package/dist/types/src/meta.d.ts +20 -1
  42. package/dist/types/src/meta.d.ts.map +1 -1
  43. package/dist/types/src/platform/browser/index.d.ts.map +1 -1
  44. package/dist/types/src/platform/node/index.d.ts.map +1 -1
  45. package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
  46. package/dist/types/src/processors/common.d.ts.map +1 -1
  47. package/dist/types/src/processors/console-processor.d.ts.map +1 -1
  48. package/dist/types/src/processors/file-processor.d.ts.map +1 -1
  49. package/dist/types/src/scope.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +4 -9
  52. package/src/context.ts +242 -2
  53. package/src/dbg.ts +34 -0
  54. package/src/decorators.ts +1 -2
  55. package/src/environment.test.ts +222 -0
  56. package/src/environment.ts +129 -0
  57. package/src/experimental/classes.test.ts +0 -1
  58. package/src/index.ts +7 -4
  59. package/src/jsonl.test.ts +121 -0
  60. package/src/jsonl.ts +104 -0
  61. package/src/log-buffer.test.ts +158 -0
  62. package/src/log-buffer.ts +89 -0
  63. package/src/log.test.ts +0 -1
  64. package/src/log.ts +56 -12
  65. package/src/meta.ts +29 -1
  66. package/src/platform/node/index.ts +1 -2
  67. package/src/processors/browser-processor.ts +27 -28
  68. package/src/processors/console-processor.ts +5 -13
  69. package/src/processors/file-processor.ts +7 -9
  70. package/dist/lib/browser/chunk-GPOFUMLO.mjs +0 -133
  71. package/dist/lib/browser/chunk-GPOFUMLO.mjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs +0 -135
  73. package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs.map +0 -7
@@ -0,0 +1,311 @@
1
+ // src/config.ts
2
+ var LogLevel = /* @__PURE__ */ (function(LogLevel2) {
3
+ LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
4
+ LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
5
+ LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
6
+ LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
7
+ LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
8
+ LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
9
+ return LogLevel2;
10
+ })({});
11
+ var levels = {
12
+ "*": 5,
13
+ trace: 5,
14
+ debug: 10,
15
+ verbose: 11,
16
+ info: 12,
17
+ warn: 13,
18
+ error: 14
19
+ };
20
+ var shortLevelName = {
21
+ [5]: "T",
22
+ [10]: "D",
23
+ [11]: "V",
24
+ [12]: "I",
25
+ [13]: "W",
26
+ [14]: "E"
27
+ };
28
+ var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
29
+ LogProcessorType2["CONSOLE"] = "console";
30
+ LogProcessorType2["BROWSER"] = "browser";
31
+ LogProcessorType2["DEBUG"] = "debug";
32
+ return LogProcessorType2;
33
+ })({});
34
+
35
+ // src/processors/common.ts
36
+ var getRelativeFilename = (filename) => {
37
+ const match = filename.match(/.+\/(packages\/.+\/.+)/);
38
+ if (match) {
39
+ const [, filePath] = match;
40
+ return filePath;
41
+ }
42
+ return filename;
43
+ };
44
+
45
+ // src/scope.ts
46
+ var logInfoProperties = /* @__PURE__ */ Symbol("logInfoProperties");
47
+ var logInfo = (target, propertyKey, descriptor) => {
48
+ (target[logInfoProperties] ??= []).push(propertyKey);
49
+ };
50
+ var gatherLogInfoFromScope = (scope) => {
51
+ if (!scope) {
52
+ return {};
53
+ }
54
+ const res = {};
55
+ const prototype = Object.getPrototypeOf(scope);
56
+ const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
57
+ for (const prop of infoProps) {
58
+ try {
59
+ res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
60
+ } catch (err) {
61
+ res[prop] = err.message;
62
+ }
63
+ }
64
+ return res;
65
+ };
66
+
67
+ // src/context.ts
68
+ import { getDebugName } from "@dxos/util";
69
+ var LogEntry = class {
70
+ /** Severity of this entry. */
71
+ level;
72
+ /** Human-readable log message, if any. */
73
+ message;
74
+ /**
75
+ * Raw context value passed at the call site. May be a record, an Error, a function
76
+ * returning either, or any other value. Processors that need the flattened /
77
+ * JSON-safe view should prefer {@link computedContext}.
78
+ */
79
+ context;
80
+ /** Raw call-site metadata injected by the log transform plugin. */
81
+ meta;
82
+ /** Error passed to `log.catch()` / `log.error(err)`, if any. */
83
+ error;
84
+ /** Unix timestamp in milliseconds of when the entry was created. */
85
+ timestamp;
86
+ #computedContext;
87
+ #computedContextComputed = false;
88
+ #computedError;
89
+ #computedErrorComputed = false;
90
+ #computedMeta;
91
+ #resolvedContext;
92
+ #resolvedContextComputed = false;
93
+ constructor(init) {
94
+ this.level = init.level;
95
+ this.message = init.message;
96
+ this.context = init.context;
97
+ this.meta = init.meta;
98
+ this.error = init.error;
99
+ this.timestamp = init.timestamp ?? Date.now();
100
+ }
101
+ /**
102
+ * Resolve a function-valued {@link context} once and cache, so getters that
103
+ * independently consult the raw context don't trigger duplicate evaluation.
104
+ */
105
+ #resolveContext() {
106
+ if (!this.#resolvedContextComputed) {
107
+ this.#resolvedContext = typeof this.context === "function" ? this.context() : this.context;
108
+ this.#resolvedContextComputed = true;
109
+ }
110
+ return this.#resolvedContext;
111
+ }
112
+ /**
113
+ * Flattened, JSON-safe context intended for serialized stores.
114
+ *
115
+ * - Single-level key-value map.
116
+ * - Primitives (`boolean`, `number`, `string`, `null`, `undefined`) pass through.
117
+ * - Non-primitive values are stringified one level deep via `JSON.stringify` (no recursion).
118
+ * - The reserved `error` / `err` keys are stripped — use {@link computedError} instead.
119
+ * - Properties from `@logInfo`-decorated members of the scope (`meta.S`) are inlined.
120
+ *
121
+ * Lazily computed and memoized on first access.
122
+ */
123
+ get computedContext() {
124
+ if (!this.#computedContextComputed) {
125
+ this.#computedContext = computeContext(this, this.#resolveContext());
126
+ this.#computedContextComputed = true;
127
+ }
128
+ return this.#computedContext ?? {};
129
+ }
130
+ /**
131
+ * Stringified error for this entry, sourced (in priority order) from:
132
+ * 1. {@link error} (e.g. `log.catch(err)`),
133
+ * 2. {@link context} when the context itself is an {@link Error},
134
+ * 3. `context.error` or `context.err`.
135
+ *
136
+ * Formatted as `.stack` when available, falling back to `.message` or `String(err)`.
137
+ *
138
+ * Lazily computed and memoized on first access.
139
+ */
140
+ get computedError() {
141
+ if (!this.#computedErrorComputed) {
142
+ this.#computedError = computeError(this, this.#resolveContext());
143
+ this.#computedErrorComputed = true;
144
+ }
145
+ return this.#computedError;
146
+ }
147
+ /**
148
+ * Normalized call-site metadata suitable for display / serialization.
149
+ *
150
+ * Lazily computed and memoized on first access.
151
+ */
152
+ get computedMeta() {
153
+ if (this.#computedMeta === void 0) {
154
+ this.#computedMeta = computeMeta(this);
155
+ }
156
+ return this.#computedMeta;
157
+ }
158
+ };
159
+ var matchFilter = (filter, level, path) => {
160
+ if (filter.pattern?.startsWith("-")) {
161
+ if (path?.includes(filter.pattern.slice(1))) {
162
+ if (level >= filter.level) {
163
+ return false;
164
+ }
165
+ }
166
+ } else {
167
+ if (filter.pattern?.length) {
168
+ if (path?.includes(filter.pattern)) {
169
+ return level >= filter.level;
170
+ }
171
+ } else {
172
+ if (level >= filter.level) {
173
+ return true;
174
+ }
175
+ }
176
+ }
177
+ };
178
+ var shouldLog = (entry, filters) => {
179
+ if (filters === void 0) {
180
+ return false;
181
+ }
182
+ const results = filters.map((filter) => matchFilter(filter, entry.level, entry.meta?.F)).filter((result) => result !== void 0);
183
+ return results.length > 0 && !results.some((results2) => results2 === false);
184
+ };
185
+ var getContextFromEntry = (entry) => {
186
+ let context;
187
+ if (entry.meta) {
188
+ const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
189
+ if (Object.keys(scopeInfo).length > 0) {
190
+ context = Object.assign(context ?? {}, scopeInfo);
191
+ }
192
+ }
193
+ const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
194
+ if (entryContext) {
195
+ if (entryContext instanceof Error) {
196
+ const c = entryContext.context;
197
+ context = Object.assign(context ?? {}, {
198
+ error: entryContext.stack,
199
+ ...c
200
+ });
201
+ } else if (typeof entryContext === "object") {
202
+ context = Object.assign(context ?? {}, entryContext);
203
+ }
204
+ }
205
+ if (entry.error) {
206
+ context = Object.assign(context ?? {}, {
207
+ error: entry.error
208
+ });
209
+ }
210
+ return context && Object.keys(context).length > 0 ? context : void 0;
211
+ };
212
+ var RESERVED_ERROR_KEYS = /* @__PURE__ */ new Set([
213
+ "error",
214
+ "err"
215
+ ]);
216
+ var stringifyOneLevel = (value) => {
217
+ if (value === null || value === void 0) {
218
+ return value;
219
+ }
220
+ const type = typeof value;
221
+ if (type === "boolean" || type === "number" || type === "string") {
222
+ return value;
223
+ }
224
+ if (type === "bigint") {
225
+ return value.toString();
226
+ }
227
+ try {
228
+ return JSON.stringify(value);
229
+ } catch {
230
+ return String(value);
231
+ }
232
+ };
233
+ var computeContext = (entry, rawContext) => {
234
+ const result = {};
235
+ const mergeInto = (source) => {
236
+ if (!source || typeof source !== "object") {
237
+ return;
238
+ }
239
+ for (const [key, value] of Object.entries(source)) {
240
+ if (RESERVED_ERROR_KEYS.has(key)) {
241
+ continue;
242
+ }
243
+ result[key] = stringifyOneLevel(value);
244
+ }
245
+ };
246
+ if (entry.meta?.S !== void 0 && entry.meta.S !== null) {
247
+ mergeInto(gatherLogInfoFromScope(entry.meta.S));
248
+ }
249
+ if (rawContext instanceof Error) {
250
+ mergeInto(rawContext.context);
251
+ } else {
252
+ mergeInto(rawContext);
253
+ }
254
+ if (entry.error) {
255
+ mergeInto(entry.error.context);
256
+ }
257
+ return result;
258
+ };
259
+ var stringifyError = (err) => {
260
+ if (err === null || err === void 0) {
261
+ return void 0;
262
+ }
263
+ if (err instanceof Error) {
264
+ return err.stack ?? err.message;
265
+ }
266
+ return String(err);
267
+ };
268
+ var computeError = (entry, rawContext) => {
269
+ if (entry.error !== void 0) {
270
+ return stringifyError(entry.error);
271
+ }
272
+ if (rawContext instanceof Error) {
273
+ return stringifyError(rawContext);
274
+ }
275
+ if (rawContext && typeof rawContext === "object") {
276
+ const ctxErr = rawContext.error ?? rawContext.err;
277
+ if (ctxErr !== void 0 && ctxErr !== null) {
278
+ return stringifyError(ctxErr);
279
+ }
280
+ }
281
+ return void 0;
282
+ };
283
+ var computeMeta = (entry) => {
284
+ if (!entry.meta) {
285
+ return {};
286
+ }
287
+ const scope = entry.meta.S;
288
+ let scopeContext;
289
+ if (typeof scope === "object" && scope !== null && scope !== globalThis && Object.getPrototypeOf(scope) !== Object.prototype) {
290
+ scopeContext = getDebugName(scope);
291
+ }
292
+ return {
293
+ filename: getRelativeFilename(entry.meta.F),
294
+ line: entry.meta.L,
295
+ context: scopeContext
296
+ };
297
+ };
298
+
299
+ export {
300
+ LogLevel,
301
+ levels,
302
+ shortLevelName,
303
+ LogProcessorType,
304
+ getRelativeFilename,
305
+ logInfo,
306
+ gatherLogInfoFromScope,
307
+ LogEntry,
308
+ shouldLog,
309
+ getContextFromEntry
310
+ };
311
+ //# sourceMappingURL=chunk-V7FYKT4H.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/config.ts", "../../../src/processors/common.ts", "../../../src/scope.ts", "../../../src/context.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 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", "//\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 { getDebugName } from '@dxos/util';\n\nimport { type LogConfig, type LogFilter, type LogLevel } from './config';\nimport { type CallMetadata } from './meta';\nimport { getRelativeFilename } from './processors/common';\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 * Normalized call-site metadata suitable for display and serialization.\n */\nexport interface ComputedLogMeta {\n /** Relative filename (normalized via {@link getRelativeFilename}). */\n filename?: string;\n\n /** Line number within the file. */\n line?: number;\n\n /** Debug name of the enclosing scope (class instance), e.g. `MyClass#3`. */\n context?: string;\n}\n\n/**\n * Fields required to construct a {@link LogEntry}.\n */\nexport interface LogEntryInit {\n level: LogLevel;\n message?: string;\n context?: LogContext;\n meta?: CallMetadata;\n error?: Error;\n /** Overrides the default timestamp ({@link Date.now}). */\n timestamp?: number;\n}\n\n/**\n * Record for a single log line processed by the logging pipeline.\n *\n * Raw fields (`level`, `message`, `context`, `meta`, `error`) are preserved so processors\n * can access unmodified inputs. Derived, lazily computed getters\n * ({@link computedContext}, {@link computedError}, {@link computedMeta}) centralize\n * the formatting logic shared across processors that write to serialized stores.\n */\nexport class LogEntry {\n /** Severity of this entry. */\n readonly level: LogLevel;\n\n /** Human-readable log message, if any. */\n readonly message?: string;\n\n /**\n * Raw context value passed at the call site. May be a record, an Error, a function\n * returning either, or any other value. Processors that need the flattened /\n * JSON-safe view should prefer {@link computedContext}.\n */\n readonly context?: LogContext;\n\n /** Raw call-site metadata injected by the log transform plugin. */\n readonly meta?: CallMetadata;\n\n /** Error passed to `log.catch()` / `log.error(err)`, if any. */\n readonly error?: Error;\n\n /** Unix timestamp in milliseconds of when the entry was created. */\n readonly timestamp: number;\n\n #computedContext: Record<string, unknown> | undefined;\n #computedContextComputed = false;\n #computedError: string | undefined;\n #computedErrorComputed = false;\n #computedMeta: ComputedLogMeta | undefined;\n #resolvedContext: unknown;\n #resolvedContextComputed = false;\n\n constructor(init: LogEntryInit) {\n this.level = init.level;\n this.message = init.message;\n this.context = init.context;\n this.meta = init.meta;\n this.error = init.error;\n this.timestamp = init.timestamp ?? Date.now();\n }\n\n /**\n * Resolve a function-valued {@link context} once and cache, so getters that\n * independently consult the raw context don't trigger duplicate evaluation.\n */\n #resolveContext(): unknown {\n if (!this.#resolvedContextComputed) {\n this.#resolvedContext = typeof this.context === 'function' ? this.context() : this.context;\n this.#resolvedContextComputed = true;\n }\n return this.#resolvedContext;\n }\n\n /**\n * Flattened, JSON-safe context intended for serialized stores.\n *\n * - Single-level key-value map.\n * - Primitives (`boolean`, `number`, `string`, `null`, `undefined`) pass through.\n * - Non-primitive values are stringified one level deep via `JSON.stringify` (no recursion).\n * - The reserved `error` / `err` keys are stripped — use {@link computedError} instead.\n * - Properties from `@logInfo`-decorated members of the scope (`meta.S`) are inlined.\n *\n * Lazily computed and memoized on first access.\n */\n get computedContext(): Record<string, unknown> {\n if (!this.#computedContextComputed) {\n this.#computedContext = computeContext(this, this.#resolveContext());\n this.#computedContextComputed = true;\n }\n return this.#computedContext ?? {};\n }\n\n /**\n * Stringified error for this entry, sourced (in priority order) from:\n * 1. {@link error} (e.g. `log.catch(err)`),\n * 2. {@link context} when the context itself is an {@link Error},\n * 3. `context.error` or `context.err`.\n *\n * Formatted as `.stack` when available, falling back to `.message` or `String(err)`.\n *\n * Lazily computed and memoized on first access.\n */\n get computedError(): string | undefined {\n if (!this.#computedErrorComputed) {\n this.#computedError = computeError(this, this.#resolveContext());\n this.#computedErrorComputed = true;\n }\n return this.#computedError;\n }\n\n /**\n * Normalized call-site metadata suitable for display / serialization.\n *\n * Lazily computed and memoized on first access.\n */\n get computedMeta(): ComputedLogMeta {\n if (this.#computedMeta === undefined) {\n this.#computedMeta = computeMeta(this);\n }\n return this.#computedMeta;\n }\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\n/**\n * Merges scope info, entry context, and error into a single record — preserving nested\n * objects and Error instances so rich consumers (console inspect, devtools) can format them.\n *\n * Prefer {@link LogEntry.computedContext} for serialized / JSON outputs.\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\nconst RESERVED_ERROR_KEYS = new Set(['error', 'err']);\n\nconst stringifyOneLevel = (value: unknown): unknown => {\n if (value === null || value === undefined) {\n return value;\n }\n const type = typeof value;\n if (type === 'boolean' || type === 'number' || type === 'string') {\n return value;\n }\n if (type === 'bigint') {\n return (value as bigint).toString();\n }\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nconst computeContext = (entry: LogEntry, rawContext: unknown): Record<string, unknown> => {\n const result: Record<string, unknown> = {};\n\n const mergeInto = (source: unknown): void => {\n if (!source || typeof source !== 'object') {\n return;\n }\n for (const [key, value] of Object.entries(source)) {\n if (RESERVED_ERROR_KEYS.has(key)) {\n continue;\n }\n result[key] = stringifyOneLevel(value);\n }\n };\n\n if (entry.meta?.S !== undefined && entry.meta.S !== null) {\n mergeInto(gatherLogInfoFromScope(entry.meta.S));\n }\n\n if (rawContext instanceof Error) {\n // Structured debug info attached to thrown errors lives on `.context`.\n mergeInto((rawContext as any).context);\n } else {\n mergeInto(rawContext);\n }\n\n if (entry.error) {\n mergeInto((entry.error as any).context);\n }\n\n return result;\n};\n\nconst stringifyError = (err: unknown): string | undefined => {\n if (err === null || err === undefined) {\n return undefined;\n }\n if (err instanceof Error) {\n return err.stack ?? err.message;\n }\n return String(err);\n};\n\nconst computeError = (entry: LogEntry, rawContext: unknown): string | undefined => {\n if (entry.error !== undefined) {\n return stringifyError(entry.error);\n }\n\n if (rawContext instanceof Error) {\n return stringifyError(rawContext);\n }\n if (rawContext && typeof rawContext === 'object') {\n const ctxErr = (rawContext as any).error ?? (rawContext as any).err;\n if (ctxErr !== undefined && ctxErr !== null) {\n return stringifyError(ctxErr);\n }\n }\n\n return undefined;\n};\n\nconst computeMeta = (entry: LogEntry): ComputedLogMeta => {\n if (!entry.meta) {\n return {};\n }\n\n const scope = entry.meta.S;\n // Skip globalThis and plain object scopes (module-level logs); only report class instances.\n let scopeContext: string | undefined;\n if (\n typeof scope === 'object' &&\n scope !== null &&\n scope !== globalThis &&\n Object.getPrototypeOf(scope) !== Object.prototype\n ) {\n scopeContext = getDebugName(scope);\n }\n\n return {\n filename: getRelativeFilename(entry.meta.F),\n line: entry.meta.L,\n context: scopeContext,\n };\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,EAAA,GAAoB;EACpB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAkB;AACpB;AAEO,IAAKC,mBAAAA,0BAAAA,mBAAAA;;;;SAAAA;;;;ACnCL,IAAMC,sBAAsB,CAACC,aAAAA;AAGlC,QAAMC,QAAQD,SAASC,MAAM,wBAAA;AAC7B,MAAIA,OAAO;AACT,UAAM,CAAA,EAAGC,QAAAA,IAAYD;AACrB,WAAOC;EACT;AAEA,SAAOF;AACT;;;ACVA,IAAMG,oBAAoBC,uBAAO,mBAAA;AAc1B,IAAMC,UAAU,CAACC,QAAaC,aAAqBC,eAAAA;AAEvDF,GAAAA,OAAOH,iB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zB,MAAI2B;AACJ,MACE,OAAOD,UAAU,YACjBA,UAAU,QACVA,UAAUE,cACV3B,OAAO4B,eAAeH,KAAAA,MAAWzB,OAAO6B,WACxC;AACAH,mBAAeI,aAAaL,KAAAA;EAC9B;AAEA,SAAO;IACLM,UAAUC,oBAAoB3C,MAAMtB,KAAK0B,CAAC;IAC1CwC,MAAM5C,MAAMtB,KAAKmE;IACjBpE,SAAS4D;EACX;AACF;",
6
+ "names": ["LogLevel", "levels", "trace", "debug", "verbose", "info", "warn", "error", "shortLevelName", "LogProcessorType", "getRelativeFilename", "filename", "match", "filePath", "logInfoProperties", "Symbol", "logInfo", "target", "propertyKey", "descriptor", "push", "gatherLogInfoFromScope", "scope", "res", "prototype", "Object", "getPrototypeOf", "infoProps", "prop", "err", "message", "getDebugName", "LogEntry", "level", "message", "context", "meta", "error", "timestamp", "init", "Date", "now", "computedContext", "computeContext", "computedError", "computeError", "computedMeta", "undefined", "computeMeta", "matchFilter", "filter", "path", "pattern", "startsWith", "includes", "slice", "length", "shouldLog", "entry", "filters", "results", "map", "F", "result", "some", "getContextFromEntry", "scopeInfo", "gatherLogInfoFromScope", "S", "Object", "keys", "assign", "entryContext", "Error", "c", "stack", "RESERVED_ERROR_KEYS", "Set", "stringifyOneLevel", "value", "type", "toString", "JSON", "stringify", "String", "rawContext", "mergeInto", "source", "key", "entries", "has", "stringifyError", "err", "ctxErr", "scope", "scopeContext", "globalThis", "getPrototypeOf", "prototype", "getDebugName", "filename", "getRelativeFilename", "line", "L"]
7
+ }