@dxos/log 0.4.10-main.c32f430 → 0.4.10-main.c42bfdb

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.
@@ -87,7 +87,7 @@ var getContextFromEntry = (entry) => {
87
87
  if (entry.error) {
88
88
  const errorContext = entry.error.context;
89
89
  context = Object.assign(context ?? {}, {
90
- error: entry.error.stack,
90
+ error: entry.error,
91
91
  ...errorContext
92
92
  });
93
93
  }
@@ -95,10 +95,12 @@ var getContextFromEntry = (entry) => {
95
95
  };
96
96
 
97
97
  // packages/common/log/src/decorators.ts
98
+ import chalk from "chalk";
98
99
  import { inspect } from "@dxos/node-std/util";
99
100
  var nextPromiseId = 0;
100
101
  var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
101
102
  const method = descriptor.value;
103
+ const methodName = propertyKey;
102
104
  descriptor.value = function(...args) {
103
105
  const combinedMeta = {
104
106
  ...meta ?? {},
@@ -110,30 +112,54 @@ var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, property
110
112
  const result = method.apply(this, args);
111
113
  if (isThenable(result)) {
112
114
  const id = nextPromiseId++;
113
- log2.info(`${propertyKey}(${formattedArgs}) => Promise { #${id} }`, {}, combinedMeta);
115
+ logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
114
116
  result.then((resolvedValue) => {
115
- if (resolvedValue !== void 0) {
116
- log2.info(`\u2705 resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms => ${inspect(resolvedValue, false, 1, true)}`, {}, combinedMeta);
117
- } else {
118
- log2.info(`\u2705 resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms`, {}, combinedMeta);
119
- }
117
+ logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
120
118
  }, (err) => {
121
- log2.info(`\u{1F525} reject #${id} #${(performance.now() - startTime).toFixed(0)}ms => ${err}`, {}, combinedMeta);
119
+ logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
122
120
  });
123
121
  } else {
124
- log2.info(`${propertyKey}(${formattedArgs}) => ${inspect(result, false, 1, true)}`, {}, combinedMeta);
122
+ logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
125
123
  }
126
124
  return result;
127
125
  } catch (err) {
128
- log2.error(`${propertyKey}(${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
126
+ logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
129
127
  throw err;
130
128
  }
131
129
  };
132
130
  Object.defineProperty(descriptor.value, "name", {
133
- value: propertyKey + "$log"
131
+ value: methodName + "$log"
134
132
  });
135
133
  };
136
134
  var isThenable = (obj) => obj && typeof obj.then === "function";
135
+ var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
136
+ log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray("resolve")} ${inspect(result, false, 1, true)}`, {}, combinedMeta);
137
+ };
138
+ var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
139
+ log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
140
+ };
141
+ var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
142
+ log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${chalk.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
143
+ };
144
+ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
145
+ if (resolvedValue !== void 0) {
146
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${inspect(resolvedValue, false, 1, true)}`, {}, combinedMeta);
147
+ } else {
148
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${chalk.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
149
+ }
150
+ };
151
+ var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
152
+ log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
153
+ };
154
+ var greenCheck = chalk.green("\u2714");
155
+ var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
156
+ var COLOR_FUNCTION = [
157
+ 220,
158
+ 220,
159
+ 170
160
+ ];
161
+ var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
162
+ var formatPromise = (id) => chalk.blue(`Promise#${id}`);
137
163
 
138
164
  // packages/common/log/src/options.ts
139
165
  import defaultsDeep from "lodash.defaultsdeep";
@@ -275,6 +301,7 @@ var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_B
275
301
  import { appendFileSync, mkdirSync, openSync } from "@dxos/node-std/fs";
276
302
  import { dirname } from "@dxos/node-std/path";
277
303
  import { jsonify } from "@dxos/util";
304
+ var EAGAIN_MAX_DURATION = 1e3;
278
305
  var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
279
306
  let fd;
280
307
  return (config, entry) => {
@@ -302,7 +329,24 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
302
329
  },
303
330
  context: jsonify(getContextFromEntry(entry))
304
331
  };
305
- appendFileSync(fd, JSON.stringify(record) + "\n");
332
+ let retryTS = 0;
333
+ while (true) {
334
+ try {
335
+ return appendFileSync(fd, JSON.stringify(record) + "\n");
336
+ } catch (err) {
337
+ if (err.code !== "EAGAIN") {
338
+ throw err;
339
+ }
340
+ if (retryTS === 0) {
341
+ retryTS = performance.now();
342
+ } else {
343
+ if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
344
+ console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
345
+ throw err;
346
+ }
347
+ }
348
+ }
349
+ }
306
350
  };
307
351
  };
308
352
  var logFilePath;
@@ -391,7 +435,7 @@ var createLog = () => {
391
435
  log2.info = (...params) => processLog(LogLevel.INFO, ...params);
392
436
  log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
393
437
  log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
394
- log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.stack, context, meta, error);
438
+ log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);
395
439
  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");
396
440
  log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
397
441
  ${getFormattedStackTrace()}`, context, meta);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/config.ts", "../../../src/scope.ts", "../../../src/context.ts", "../../../src/decorators.ts", "../../../src/options.ts", "../../../src/platform/browser/index.ts", "../../../src/processors/console-stub.ts", "../../../src/processors/debug-processor.ts", "../../../src/processors/browser-processor.ts", "../../../src/processors/file-processor.ts", "../../../src/log.ts", "../../../src/experimental/ownership.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// Message helpers.\nimport omit from 'lodash.omit';\nimport pick from 'lodash.pick';\n\nexport { omit, pick };\n\nexport * from './config';\nexport * from './context';\nexport * from './log';\nexport { parseFilter } from './options';\nexport * from './processors';\nexport * from './scope';\nexport * from './meta';\n\nexport { getCurrentOwnershipScope } from './experimental/ownership';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n */\n// NOTE: Keep aligned with LogLevel in @dxos/protocols.\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n INFO = 11,\n WARN = 12,\n ERROR = 13,\n}\n\nexport const levels: { [index: string]: LogLevel } = {\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\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.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 = 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\nconst matchFilter = (filter: LogFilter, level: LogLevel, path: string) => {\n return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));\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 true;\n } else {\n return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ''));\n }\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 if (entry.context) {\n if (entry.context instanceof Error) {\n // Additional context from Error.\n const c = (entry.context as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entry.context.stack, ...c });\n } else if (typeof entry.context === 'object') {\n context = Object.assign(context ?? {}, entry.context);\n }\n }\n\n if (entry.error) {\n const errorContext = (entry.error as any).context;\n context = Object.assign(context ?? {}, { error: entry.error.stack, ...errorContext });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport type { LogMethods } from './log';\nimport { type CallMetadata } from './meta';\n\nlet nextPromiseId = 0;\n\nexport const createMethodLogDecorator =\n (log: LogMethods) =>\n (arg0?: never, arg1?: never, meta?: CallMetadata): MethodDecorator =>\n (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const method = descriptor.value!;\n descriptor.value = function (this: any, ...args: any) {\n const combinedMeta = {\n ...(meta ?? {}),\n S: this as any,\n } as CallMetadata;\n\n const formattedArgs = args.map((arg: any) => inspect(arg, false, 1, true)).join(', ');\n\n try {\n const startTime = performance.now();\n const result = method.apply(this, args);\n\n if (isThenable(result)) {\n const id = nextPromiseId++;\n log.info(`${propertyKey as string}(${formattedArgs}) => Promise { #${id} }`, {}, combinedMeta);\n result.then(\n (resolvedValue) => {\n if (resolvedValue !== undefined) {\n log.info(\n `✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms => ${inspect(\n resolvedValue,\n false,\n 1,\n true,\n )}`,\n {},\n combinedMeta,\n );\n } else {\n log.info(`✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms`, {}, combinedMeta);\n }\n },\n (err) => {\n log.info(`🔥 reject #${id} #${(performance.now() - startTime).toFixed(0)}ms => ${err}`, {}, combinedMeta);\n },\n );\n } else {\n log.info(\n `${propertyKey as string}(${formattedArgs}) => ${inspect(result, false, 1, true)}`,\n {},\n combinedMeta,\n );\n }\n\n return result;\n } catch (err) {\n log.error(`${propertyKey as string}(${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);\n throw err;\n }\n };\n Object.defineProperty(descriptor.value, 'name', { value: (propertyKey as string) + '$log' });\n };\n\nconst isThenable = (obj: any): obj is Promise<unknown> => obj && typeof obj.then === 'function';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';\nimport { type LogProcessor } from './context';\nimport { loadOptions } from './platform';\nimport { CONSOLE_PROCESSOR, DEBUG_PROCESSOR, BROWSER_PROCESSOR } from './processors';\n\n/**\n * Processor variants.\n */\nexport const processors: { [index: string]: LogProcessor } = {\n [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,\n [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,\n [LogProcessorType.DEBUG]: DEBUG_PROCESSOR,\n};\n\nconst IS_BROWSER = typeof window !== 'undefined' || typeof navigator !== 'undefined';\n\nexport const DEFAULT_PROCESSORS = [IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];\n\nexport const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] => {\n if (typeof filter === 'number') {\n return [{ level: filter }];\n }\n\n const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;\n\n const lines = typeof filter === 'string' ? filter.split(/,\\s*/) : filter;\n return lines.map((filter) => {\n const [pattern, level] = filter.split(':');\n return level ? { level: parseLogLevel(level), pattern } : { level: parseLogLevel(pattern) };\n });\n};\n\nexport const getConfig = (options?: LogOptions): LogConfig => {\n const nodeOptions: LogOptions | undefined =\n 'process' in globalThis\n ? {\n file: process!.env.LOG_CONFIG,\n filter: process!.env.LOG_FILTER,\n processor: process!.env.LOG_PROCESSOR,\n }\n : undefined;\n\n const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);\n return {\n options: mergedOptions,\n filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),\n captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),\n processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,\n prefix: mergedOptions.prefix,\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogOptions } from '../../config';\n\n// NOTE: Implementation for the browser. See `package.json`.\nexport const loadOptions = (filepath?: string): LogOptions | undefined => {\n let dxlog: string | undefined;\n // if running in a worker, use the localStorage.dxlog setting forwarded on worker initilization in\n // @dxos/client/src/worker/onconnect.ts\n if (typeof localStorage === 'undefined') {\n if ((globalThis as any).localStorage_dxlog) {\n dxlog = (globalThis as any).localStorage_dxlog;\n }\n } else {\n dxlog = localStorage.getItem('dxlog') ?? undefined;\n }\n if (!dxlog) {\n return undefined;\n }\n try {\n return JSON.parse(dxlog);\n } catch (err) {\n console.info(\"can't parse dxlog config\", err);\n return undefined;\n }\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(wittjosiah): Consider mapping console processor directly to browser processor in the browser.\nexport const CONSOLE_PROCESSOR = () => {};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { type LogProcessor } from '../context';\n\nexport const DEBUG_PROCESSOR: LogProcessor = (config, entry) => {\n console.log(inspect(entry, false, null, true));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { getDebugName, safariCheck } from '@dxos/util';\n\nimport { LogLevel } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst 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\ntype Config = {\n useTestProcessor: boolean;\n printFileLinks: boolean;\n};\n\nconst CONFIG: Config =\n typeof mochaExecutor !== 'undefined'\n ? {\n useTestProcessor: true,\n printFileLinks: true,\n }\n : {\n useTestProcessor: false,\n printFileLinks: false,\n };\n\n/**\n * For running apps in the browser normally.\n */\nconst APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n // Example local editor prefix: 'vscode://file/Users/burdon/Code/dxos/dxos/'.\n const LOG_BROWSER_PREFIX = config.prefix ?? 'https://vscode.dev/github.com/dxos/dxos/blob/main/';\n\n // TODO(burdon): CSS breaks formatting (e.g., [Object] rather than expandable property).\n // TODO(burdon): Consider custom formatters.\n // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html\n // NOTE: Cannot change color of link (from bright white).\n // const LOG_BROWSER_CSS = ['color:gray; font-size:10px; padding-bottom: 4px', 'color:#B97852; font-size:14px;'];\n const LOG_BROWSER_CSS: string[] = [];\n\n let link = '';\n if (entry.meta) {\n const filename = getRelativeFilename(entry.meta.F);\n const filepath = `${LOG_BROWSER_PREFIX.replace(/\\/$/, '')}/${filename}`;\n // TODO(burdon): Line numbers not working for app link, even with colons.\n // https://stackoverflow.com/a/54459820/2804332\n link = `${filepath}#L${entry.meta.L}`;\n }\n\n let args = [];\n\n if (entry.meta?.S) {\n const scope = entry.meta?.S;\n const scopeName = scope.name || getDebugName(scope);\n const processPrefix = entry.meta.S?.hostSessionId ? '[worker] ' : '';\n // TODO(dmaretskyi): Those can be made clickable with a custom formatter.\n args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');\n }\n\n args.push(entry.message);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n // Safari prints source code location as this file, not the caller.\n if (CONFIG.printFileLinks || safariCheck()) {\n if (LOG_BROWSER_CSS?.length) {\n args = [`%c${link}\\n%c${args.join(' ')}`, ...LOG_BROWSER_CSS];\n } else {\n args = [link + '\\n', ...args];\n }\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\n/**\n * For running unit tests in the headless browser.\n */\nconst TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n let path = '';\n if (entry.meta) {\n path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;\n }\n\n let args = [];\n\n const processPrefix = entry.meta?.S?.hostSessionId ? '[worker] ' : '';\n args.push(`${processPrefix}${entry.message}`);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n if (CONFIG.printFileLinks) {\n args = [path, ...args];\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\nexport const BROWSER_PROCESSOR: LogProcessor = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { appendFileSync, mkdirSync, openSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { jsonify } from '@dxos/util';\n\nimport { type LogFilter, LogLevel } from '../config';\nimport { type LogProcessor, getContextFromEntry, shouldLog } from '../context';\n\n/**\n * Create a file processor.\n * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.\n * @param levels - Log levels to process. Takes preference over Filters.\n * @param filters - Filters to apply.\n */\nexport const createFileProcessor = ({\n pathOrFd,\n levels,\n filters,\n}: {\n pathOrFd: string | number;\n levels: LogLevel[];\n filters?: LogFilter[];\n}): LogProcessor => {\n let fd: number | undefined;\n\n return (config, entry) => {\n if (levels.length > 0 && !levels.includes(entry.level)) {\n return;\n }\n if (!shouldLog(entry, filters)) {\n return;\n }\n if (typeof pathOrFd === 'number') {\n fd = pathOrFd;\n } else {\n try {\n mkdirSync(dirname(pathOrFd));\n } catch {}\n fd = openSync(pathOrFd, 'w');\n }\n\n const record = {\n ...entry,\n timestamp: Date.now(),\n meta: {\n file: entry.meta?.F,\n line: entry.meta?.L,\n },\n context: jsonify(getContextFromEntry(entry)),\n };\n appendFileSync(fd, JSON.stringify(record) + '\\n');\n };\n};\n\nlet logFilePath: string | undefined;\nconst getLogFilePath = () => {\n logFilePath ??=\n process.env.LOG_FILE ??\n (process.env.HOME ? `${process.env.HOME}/.dxlog/${new Date().toISOString()}.log` : undefined);\n\n return logFilePath!;\n};\n\nexport const FILE_PROCESSOR: LogProcessor = createFileProcessor({\n pathOrFd: getLogFilePath(),\n levels: [LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.TRACE],\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, LogLevel, type LogOptions } from './config';\nimport { type LogContext, type LogProcessor } from './context';\nimport { createMethodLogDecorator } from './decorators';\nimport { type CallMetadata } from './meta';\nimport { getConfig, DEFAULT_PROCESSORS } from './options';\n\n/**\n * Logging function.\n */\ntype LogFunction = (message: string, context?: LogContext, meta?: CallMetadata) => void;\n\n/**\n * Logging methods.\n */\nexport interface LogMethods {\n trace: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n catch: (error: Error | any, context?: LogContext, meta?: CallMetadata) => void;\n break: () => void;\n stack: (message?: string, context?: never, meta?: CallMetadata) => void;\n method: (arg0?: never, arg1?: never, meta?: CallMetadata) => MethodDecorator;\n}\n\n/**\n * Properties accessible on the logging function.\n */\ninterface Log extends LogMethods, LogFunction {\n config: (options: LogOptions) => void;\n addProcessor: (processor: LogProcessor) => void;\n runtimeConfig: LogConfig;\n}\n\ninterface LogImp extends Log {\n _config: LogConfig;\n}\n\nconst createLog = (): LogImp => {\n const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;\n\n log._config = getConfig();\n Object.defineProperty(log, 'runtimeConfig', { get: () => log._config });\n\n log.addProcessor = (processor: LogProcessor) => {\n if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {\n DEFAULT_PROCESSORS.push(processor);\n }\n if (log._config.processors.filter((p) => p === processor).length === 0) {\n log._config.processors.push(processor);\n }\n };\n\n // Set config.\n log.config = (options: LogOptions) => {\n log._config = getConfig(options);\n };\n\n // TODO(burdon): API to set context and separate error object.\n // E.g., log.warn('failed', { key: 123 }, err);\n\n log.trace = (...params) => processLog(LogLevel.TRACE, ...params);\n log.debug = (...params) => processLog(LogLevel.DEBUG, ...params);\n log.info = (...params) => processLog(LogLevel.INFO, ...params);\n log.warn = (...params) => processLog(LogLevel.WARN, ...params);\n log.error = (...params) => processLog(LogLevel.ERROR, ...params);\n\n // Catch only shows error message, not stacktrace.\n log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.stack, context, meta, error);\n\n // Show break.\n log.break = () => log.info('——————————————————————————————————————————————————');\n\n log.stack = (message, context, meta) =>\n processLog(LogLevel.INFO, `${message ?? 'Stack Dump'}\\n${getFormattedStackTrace()}`, context, meta);\n\n log.method = createMethodLogDecorator(log);\n\n /**\n * Process the current log call.\n */\n const processLog = (\n level: LogLevel,\n message: string,\n context: LogContext = {},\n meta?: CallMetadata,\n error?: Error,\n ) => {\n log._config.processors.forEach((processor) => processor(log._config, { level, message, context, meta, error }));\n };\n\n return log;\n};\n\n/**\n * Global logging function.\n */\nexport const log: Log = ((globalThis as any).dx_log ??= createLog());\n\n/**\n * Accessible from browser console.\n */\ndeclare global {\n // eslint-disable-next-line camelcase\n const dx_log: Log;\n}\n\nconst getFormattedStackTrace = () => new Error().stack!.split('\\n').slice(3).join('\\n');\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nconst kOwnershipScope = Symbol('kOwnershipScope');\nconst kCurrentOwnershipScope = Symbol('kCurrentOwnershipScope');\nconst kDebugInfoProperties = Symbol('kDebugInfoProperties');\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport class OwnershipScope {\n public instance: any;\n\n constructor(\n public constr: any,\n public parent?: OwnershipScope,\n ) {}\n\n getInfo() {\n if (!this.instance) {\n return {};\n }\n const props = this.constr.prototype[kDebugInfoProperties] ?? [];\n const info: any = {};\n for (const prop of props) {\n info[prop] = this.instance[prop];\n }\n return info;\n }\n\n [inspect.custom]() {\n return {\n className: this.constr.name,\n info: this.getInfo(),\n parent: this.parent,\n };\n }\n}\n\nfunction decorateMethodWeakReturnOwnership(prototype: any, key: string) {\n const original = prototype[key];\n prototype[key] = function (...args: any) {\n const res = original.apply(this, ...args);\n\n if (res && typeof res.then === 'function') {\n res.then((value: any) => {\n if (kOwnershipScope in value) {\n value[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n });\n } else {\n if (res && kOwnershipScope in res) {\n res[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n }\n\n return res;\n };\n}\n\nexport function ownershipClass<T extends { new (...args: any[]): {} }>(constr: T) {\n for (const key of Object.getOwnPropertyNames(constr.prototype)) {\n if (key !== 'constructor' && typeof constr.prototype[key] === 'function') {\n decorateMethodWeakReturnOwnership(constr.prototype, key);\n }\n }\n\n return class extends constr {\n constructor(...args: any[]) {\n const currentCausality = (globalThis as any)[kCurrentOwnershipScope];\n (globalThis as any)[kCurrentOwnershipScope] = new OwnershipScope(constr, currentCausality);\n super(...args);\n (this as any)[kOwnershipScope] = (globalThis as any)[kCurrentOwnershipScope];\n (this as any)[kOwnershipScope].instance = this;\n (globalThis as any)[kCurrentOwnershipScope] = currentCausality;\n }\n };\n}\n\nexport const debugInfo = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[kDebugInfoProperties] ??= []).push(propertyKey);\n};\n\nexport const getCurrentOwnershipScope = (thisRef: any) => thisRef;\n"],
5
- "mappings": ";AAKA,OAAOA,UAAU;AACjB,OAAOC,UAAU;;;;UCKLC,WAAAA;;;;;;GAAAA,aAAAA,WAAAA,CAAAA,EAAAA;AAQL,IAAMC,SAAwC;EACnDC,OAAK;EACLC,OAAK;EACLC,MAAI;EACJC,MAAI;EACJC,OAAK;AACP;AAEO,IAAMC,iBAAiB;EAC5B,CAAA,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,QAAI,CAAC,KAAKC,UAAU;AAClB,aAAO,CAAC;IACV;AACA,UAAMC,QAAQ,KAAKJ,OAAOK,UAAUR,oBAAAA,KAAyB,CAAA;AAC7D,UAAMS,OAAY,CAAC;AACnB,eAAWC,QAAQH,OAAO;AACxBE,WAAKC,IAAAA,IAAQ,KAAKJ,SAASI,IAAAA;IAC7B;AACA,WAAOD;EACT;EAEA,CAACE,SAAQC,MAAM,IAAI;AACjB,WAAO;MACLC,WAAW,KAAKV,OAAOW;MACvBL,MAAM,KAAKJ,QAAO;MAClBD,QAAQ,KAAKA;IACf;EACF;AACF;AA+CO,IAAMW,2BAA2B,CAACC,YAAiBA;",
6
- "names": ["omit", "pick", "LogLevel", "levels", "trace", "debug", "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", "includes", "shouldLog", "entry", "filters", "undefined", "some", "meta", "F", "getContextFromEntry", "context", "scopeInfo", "gatherLogInfoFromScope", "S", "Object", "keys", "length", "assign", "Error", "c", "error", "stack", "errorContext", "inspect", "nextPromiseId", "createMethodLogDecorator", "log", "arg0", "arg1", "meta", "target", "propertyKey", "descriptor", "method", "value", "args", "combinedMeta", "S", "formattedArgs", "map", "arg", "inspect", "join", "startTime", "performance", "now", "result", "apply", "isThenable", "id", "info", "then", "resolvedValue", "undefined", "toFixed", "err", "error", "Object", "defineProperty", "obj", "defaultsDeep", "loadOptions", "filepath", "dxlog", "localStorage", "globalThis", "localStorage_dxlog", "getItem", "undefined", "JSON", "parse", "err", "console", "info", "CONSOLE_PROCESSOR", "inspect", "DEBUG_PROCESSOR", "config", "entry", "console", "log", "inspect", "getDebugName", "safariCheck", "getRelativeFilename", "filename", "match", "filePath", "CONFIG", "mochaExecutor", "useTestProcessor", "printFileLinks", "APP_BROWSER_PROCESSOR", "config", "entry", "shouldLog", "filters", "LOG_BROWSER_PREFIX", "prefix", "LOG_BROWSER_CSS", "link", "meta", "F", "filepath", "replace", "L", "args", "S", "scope", "scopeName", "name", "getDebugName", "processPrefix", "hostSessionId", "push", "message", "context", "getContextFromEntry", "levels", "LogLevel", "ERROR", "console", "error", "WARN", "warn", "DEBUG", "log", "safariCheck", "length", "join", "level", "C", "TEST_BROWSER_PROCESSOR", "path", "BROWSER_PROCESSOR", "appendFileSync", "mkdirSync", "openSync", "dirname", "jsonify", "createFileProcessor", "pathOrFd", "levels", "filters", "fd", "config", "entry", "length", "includes", "level", "shouldLog", "mkdirSync", "dirname", "openSync", "record", "timestamp", "Date", "now", "meta", "file", "F", "line", "L", "context", "jsonify", "getContextFromEntry", "appendFileSync", "JSON", "stringify", "logFilePath", "getLogFilePath", "process", "env", "LOG_FILE", "HOME", "toISOString", "undefined", "FILE_PROCESSOR", "LogLevel", "ERROR", "WARN", "INFO", "TRACE", "processors", "LogProcessorType", "CONSOLE", "CONSOLE_PROCESSOR", "BROWSER", "BROWSER_PROCESSOR", "DEBUG", "DEBUG_PROCESSOR", "IS_BROWSER", "window", "navigator", "DEFAULT_PROCESSORS", "parseFilter", "filter", "level", "parseLogLevel", "defValue", "LogLevel", "WARN", "levels", "toLowerCase", "lines", "split", "map", "pattern", "getConfig", "options", "nodeOptions", "globalThis", "file", "process", "env", "LOG_CONFIG", "LOG_FILTER", "processor", "LOG_PROCESSOR", "undefined", "mergedOptions", "defaultsDeep", "loadOptions", "filters", "INFO", "captureFilters", "captureFilter", "prefix", "createLog", "log", "params", "processLog", "LogLevel", "DEBUG", "_config", "getConfig", "Object", "defineProperty", "get", "addProcessor", "processor", "DEFAULT_PROCESSORS", "filter", "p", "length", "push", "processors", "config", "options", "trace", "TRACE", "debug", "info", "INFO", "warn", "WARN", "error", "ERROR", "catch", "context", "meta", "stack", "break", "message", "getFormattedStackTrace", "method", "createMethodLogDecorator", "level", "forEach", "globalThis", "dx_log", "Error", "split", "slice", "join", "inspect", "kOwnershipScope", "Symbol", "kCurrentOwnershipScope", "kDebugInfoProperties", "OwnershipScope", "constructor", "constr", "parent", "getInfo", "instance", "props", "prototype", "info", "prop", "inspect", "custom", "className", "name", "getCurrentOwnershipScope", "thisRef"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// Message helpers.\nimport omit from 'lodash.omit';\nimport pick from 'lodash.pick';\n\nexport { omit, pick };\n\nexport * from './config';\nexport * from './context';\nexport * from './log';\nexport { parseFilter } from './options';\nexport * from './processors';\nexport * from './scope';\nexport * from './meta';\n\nexport { getCurrentOwnershipScope } from './experimental/ownership';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n */\n// NOTE: Keep aligned with LogLevel in @dxos/protocols.\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n INFO = 11,\n WARN = 12,\n ERROR = 13,\n}\n\nexport const levels: { [index: string]: LogLevel } = {\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\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.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 = 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\nconst matchFilter = (filter: LogFilter, level: LogLevel, path: string) => {\n return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));\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 true;\n } else {\n return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ''));\n }\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 if (entry.context) {\n if (entry.context instanceof Error) {\n // Additional context from Error.\n const c = (entry.context as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entry.context.stack, ...c });\n } else if (typeof entry.context === 'object') {\n context = Object.assign(context ?? {}, entry.context);\n }\n }\n\n if (entry.error) {\n const errorContext = (entry.error as any).context;\n context = Object.assign(context ?? {}, { error: entry.error, ...errorContext });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport chalk from 'chalk';\nimport { inspect } from 'node:util';\n\nimport type { LogMethods } from './log';\nimport { type CallMetadata } from './meta';\n\nlet nextPromiseId = 0;\n\nexport const createMethodLogDecorator =\n (log: LogMethods) =>\n (arg0?: never, arg1?: never, meta?: CallMetadata): MethodDecorator =>\n (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const method = descriptor.value!;\n const methodName = propertyKey as string;\n descriptor.value = function (this: any, ...args: any) {\n const combinedMeta = {\n ...(meta ?? {}),\n S: this as any,\n } as CallMetadata;\n\n const formattedArgs = args.map((arg: any) => inspect(arg, false, 1, true)).join(', ');\n\n try {\n const startTime = performance.now();\n const result = method.apply(this, args);\n\n if (isThenable(result)) {\n const id = nextPromiseId++;\n logAsyncBegin(log, methodName, formattedArgs, id, combinedMeta);\n result.then(\n (resolvedValue) => {\n logAsyncResolved(log, methodName, resolvedValue, id, startTime, combinedMeta);\n },\n (err) => {\n logAsyncRejected(log, methodName, err, id, startTime, combinedMeta);\n },\n );\n } else {\n logSyncCall(log, methodName, formattedArgs, result, combinedMeta);\n }\n\n return result;\n } catch (err: any) {\n logSyncError(log, methodName, formattedArgs, err, combinedMeta);\n throw err;\n }\n };\n Object.defineProperty(descriptor.value, 'name', { value: methodName + '$log' });\n };\n\nconst isThenable = (obj: any): obj is Promise<unknown> => obj && typeof obj.then === 'function';\n\nconst logSyncCall = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n result: unknown,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray('resolve')} ${inspect(result, false, 1, true)}`,\n {},\n combinedMeta,\n );\n};\n\nconst logSyncError = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n err: Error,\n combinedMeta: CallMetadata,\n) => {\n log.error(`.${formatFunction(methodName)} (${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);\n};\n\nconst logAsyncBegin = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n promiseId: number,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} ↴ (${formattedArgs}) ${chalk.gray('=>')} ${formatPromise(promiseId)}`,\n {},\n combinedMeta,\n );\n};\n\nconst logAsyncResolved = (\n log: LogMethods,\n methodName: string,\n resolvedValue: unknown | undefined,\n promiseId: number,\n startTime: number,\n combinedMeta: CallMetadata,\n) => {\n if (resolvedValue !== undefined) {\n log.info(\n `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${inspect(\n resolvedValue,\n false,\n 1,\n true,\n )}`,\n {},\n combinedMeta,\n );\n } else {\n log.info(\n `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`,\n {},\n combinedMeta,\n );\n }\n};\n\nconst logAsyncRejected = (\n log: LogMethods,\n methodName: string,\n err: Error,\n promiseId: number,\n startTime: number,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} ↲ 🔥 ${chalk.gray('reject')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${err}`,\n {},\n combinedMeta,\n );\n};\n\nconst greenCheck = chalk.green('✔');\n\nconst formatTimeElapsed = (startTime: number) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);\n\nconst COLOR_FUNCTION = [220, 220, 170] as const;\n\nconst formatFunction = (name: string) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));\n\nconst formatPromise = (id: number) => chalk.blue(`Promise#${id}`);\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';\nimport { type LogProcessor } from './context';\nimport { loadOptions } from './platform';\nimport { CONSOLE_PROCESSOR, DEBUG_PROCESSOR, BROWSER_PROCESSOR } from './processors';\n\n/**\n * Processor variants.\n */\nexport const processors: { [index: string]: LogProcessor } = {\n [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,\n [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,\n [LogProcessorType.DEBUG]: DEBUG_PROCESSOR,\n};\n\nconst IS_BROWSER = typeof window !== 'undefined' || typeof navigator !== 'undefined';\n\nexport const DEFAULT_PROCESSORS = [IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];\n\nexport const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] => {\n if (typeof filter === 'number') {\n return [{ level: filter }];\n }\n\n const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;\n\n const lines = typeof filter === 'string' ? filter.split(/,\\s*/) : filter;\n return lines.map((filter) => {\n const [pattern, level] = filter.split(':');\n return level ? { level: parseLogLevel(level), pattern } : { level: parseLogLevel(pattern) };\n });\n};\n\nexport const getConfig = (options?: LogOptions): LogConfig => {\n const nodeOptions: LogOptions | undefined =\n 'process' in globalThis\n ? {\n file: process!.env.LOG_CONFIG,\n filter: process!.env.LOG_FILTER,\n processor: process!.env.LOG_PROCESSOR,\n }\n : undefined;\n\n const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);\n return {\n options: mergedOptions,\n filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),\n captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),\n processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,\n prefix: mergedOptions.prefix,\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogOptions } from '../../config';\n\n// NOTE: Implementation for the browser. See `package.json`.\nexport const loadOptions = (filepath?: string): LogOptions | undefined => {\n let dxlog: string | undefined;\n // if running in a worker, use the localStorage.dxlog setting forwarded on worker initilization in\n // @dxos/client/src/worker/onconnect.ts\n if (typeof localStorage === 'undefined') {\n if ((globalThis as any).localStorage_dxlog) {\n dxlog = (globalThis as any).localStorage_dxlog;\n }\n } else {\n dxlog = localStorage.getItem('dxlog') ?? undefined;\n }\n if (!dxlog) {\n return undefined;\n }\n try {\n return JSON.parse(dxlog);\n } catch (err) {\n console.info(\"can't parse dxlog config\", err);\n return undefined;\n }\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\n// TODO(wittjosiah): Consider mapping console processor directly to browser processor in the browser.\nexport const CONSOLE_PROCESSOR = () => {};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { type LogProcessor } from '../context';\n\nexport const DEBUG_PROCESSOR: LogProcessor = (config, entry) => {\n console.log(inspect(entry, false, null, true));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { getDebugName, safariCheck } from '@dxos/util';\n\nimport { LogLevel } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst 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\ntype Config = {\n useTestProcessor: boolean;\n printFileLinks: boolean;\n};\n\nconst CONFIG: Config =\n typeof mochaExecutor !== 'undefined'\n ? {\n useTestProcessor: true,\n printFileLinks: true,\n }\n : {\n useTestProcessor: false,\n printFileLinks: false,\n };\n\n/**\n * For running apps in the browser normally.\n */\nconst APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n // Example local editor prefix: 'vscode://file/Users/burdon/Code/dxos/dxos/'.\n const LOG_BROWSER_PREFIX = config.prefix ?? 'https://vscode.dev/github.com/dxos/dxos/blob/main/';\n\n // TODO(burdon): CSS breaks formatting (e.g., [Object] rather than expandable property).\n // TODO(burdon): Consider custom formatters.\n // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html\n // NOTE: Cannot change color of link (from bright white).\n // const LOG_BROWSER_CSS = ['color:gray; font-size:10px; padding-bottom: 4px', 'color:#B97852; font-size:14px;'];\n const LOG_BROWSER_CSS: string[] = [];\n\n let link = '';\n if (entry.meta) {\n const filename = getRelativeFilename(entry.meta.F);\n const filepath = `${LOG_BROWSER_PREFIX.replace(/\\/$/, '')}/${filename}`;\n // TODO(burdon): Line numbers not working for app link, even with colons.\n // https://stackoverflow.com/a/54459820/2804332\n link = `${filepath}#L${entry.meta.L}`;\n }\n\n let args = [];\n\n if (entry.meta?.S) {\n const scope = entry.meta?.S;\n const scopeName = scope.name || getDebugName(scope);\n const processPrefix = entry.meta.S?.hostSessionId ? '[worker] ' : '';\n // TODO(dmaretskyi): Those can be made clickable with a custom formatter.\n args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');\n }\n\n args.push(entry.message);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n // Safari prints source code location as this file, not the caller.\n if (CONFIG.printFileLinks || safariCheck()) {\n if (LOG_BROWSER_CSS?.length) {\n args = [`%c${link}\\n%c${args.join(' ')}`, ...LOG_BROWSER_CSS];\n } else {\n args = [link + '\\n', ...args];\n }\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\n/**\n * For running unit tests in the headless browser.\n */\nconst TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n let path = '';\n if (entry.meta) {\n path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;\n }\n\n let args = [];\n\n const processPrefix = entry.meta?.S?.hostSessionId ? '[worker] ' : '';\n args.push(`${processPrefix}${entry.message}`);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n if (CONFIG.printFileLinks) {\n args = [path, ...args];\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\nexport const BROWSER_PROCESSOR: LogProcessor = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { appendFileSync, mkdirSync, openSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { jsonify } from '@dxos/util';\n\nimport { type LogFilter, LogLevel } from '../config';\nimport { type LogProcessor, getContextFromEntry, shouldLog } from '../context';\n\n// Amount of time to retry writing after encountering EAGAIN before giving up.\nconst EAGAIN_MAX_DURATION = 1000;\n/**\n * Create a file processor.\n * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.\n * @param levels - Log levels to process. Takes preference over Filters.\n * @param filters - Filters to apply.\n */\nexport const createFileProcessor = ({\n pathOrFd,\n levels,\n filters,\n}: {\n pathOrFd: string | number;\n levels: LogLevel[];\n filters?: LogFilter[];\n}): LogProcessor => {\n let fd: number | undefined;\n\n return (config, entry) => {\n if (levels.length > 0 && !levels.includes(entry.level)) {\n return;\n }\n if (!shouldLog(entry, filters)) {\n return;\n }\n if (typeof pathOrFd === 'number') {\n fd = pathOrFd;\n } else {\n try {\n mkdirSync(dirname(pathOrFd));\n } catch {}\n fd = openSync(pathOrFd, 'w');\n }\n\n const record = {\n ...entry,\n timestamp: Date.now(),\n meta: {\n file: entry.meta?.F,\n line: entry.meta?.L,\n },\n context: jsonify(getContextFromEntry(entry)),\n };\n let retryTS: number = 0;\n\n // Retry writing if EAGAIN is encountered.\n //\n // Node may set stdout and stderr to non-blocking. https://github.com/nodejs/node/issues/42826\n // This can cause EAGAIN errors when writing to them.\n // In order to not drop logs, make log methods asynchronous, or deal with buffering/delayed writes, spin until write succeeds.\n\n while (true) {\n try {\n return appendFileSync(fd, JSON.stringify(record) + '\\n');\n } catch (err: any) {\n if (err.code !== 'EAGAIN') {\n throw err;\n }\n if (retryTS === 0) {\n retryTS = performance.now();\n } else {\n if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {\n console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);\n throw err;\n }\n }\n }\n }\n };\n};\n\nlet logFilePath: string | undefined;\nconst getLogFilePath = () => {\n logFilePath ??=\n process.env.LOG_FILE ??\n (process.env.HOME ? `${process.env.HOME}/.dxlog/${new Date().toISOString()}.log` : undefined);\n\n return logFilePath!;\n};\n\nexport const FILE_PROCESSOR: LogProcessor = createFileProcessor({\n pathOrFd: getLogFilePath(),\n levels: [LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.TRACE],\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, LogLevel, type LogOptions } from './config';\nimport { type LogContext, type LogProcessor } from './context';\nimport { createMethodLogDecorator } from './decorators';\nimport { type CallMetadata } from './meta';\nimport { getConfig, DEFAULT_PROCESSORS } from './options';\n\n/**\n * Logging function.\n */\ntype LogFunction = (message: string, context?: LogContext, meta?: CallMetadata) => void;\n\n/**\n * Logging methods.\n */\nexport interface LogMethods {\n trace: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n catch: (error: Error | any, context?: LogContext, meta?: CallMetadata) => void;\n break: () => void;\n stack: (message?: string, context?: never, meta?: CallMetadata) => void;\n method: (arg0?: never, arg1?: never, meta?: CallMetadata) => MethodDecorator;\n}\n\n/**\n * Properties accessible on the logging function.\n */\ninterface Log extends LogMethods, LogFunction {\n config: (options: LogOptions) => void;\n addProcessor: (processor: LogProcessor) => void;\n runtimeConfig: LogConfig;\n}\n\ninterface LogImp extends Log {\n _config: LogConfig;\n}\n\nconst createLog = (): LogImp => {\n const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;\n\n log._config = getConfig();\n Object.defineProperty(log, 'runtimeConfig', { get: () => log._config });\n\n log.addProcessor = (processor: LogProcessor) => {\n if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {\n DEFAULT_PROCESSORS.push(processor);\n }\n if (log._config.processors.filter((p) => p === processor).length === 0) {\n log._config.processors.push(processor);\n }\n };\n\n // Set config.\n log.config = (options: LogOptions) => {\n log._config = getConfig(options);\n };\n\n // TODO(burdon): API to set context and separate error object.\n // E.g., log.warn('failed', { key: 123 }, err);\n\n log.trace = (...params) => processLog(LogLevel.TRACE, ...params);\n log.debug = (...params) => processLog(LogLevel.DEBUG, ...params);\n log.info = (...params) => processLog(LogLevel.INFO, ...params);\n log.warn = (...params) => processLog(LogLevel.WARN, ...params);\n log.error = (...params) => processLog(LogLevel.ERROR, ...params);\n\n // Catch only shows error message, not stacktrace.\n log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);\n\n // Show break.\n log.break = () => log.info('——————————————————————————————————————————————————');\n\n log.stack = (message, context, meta) =>\n processLog(LogLevel.INFO, `${message ?? 'Stack Dump'}\\n${getFormattedStackTrace()}`, context, meta);\n\n log.method = createMethodLogDecorator(log);\n\n /**\n * Process the current log call.\n */\n const processLog = (\n level: LogLevel,\n message: string,\n context: LogContext = {},\n meta?: CallMetadata,\n error?: Error,\n ) => {\n log._config.processors.forEach((processor) => processor(log._config, { level, message, context, meta, error }));\n };\n\n return log;\n};\n\n/**\n * Global logging function.\n */\nexport const log: Log = ((globalThis as any).dx_log ??= createLog());\n\n/**\n * Accessible from browser console.\n */\ndeclare global {\n // eslint-disable-next-line camelcase\n const dx_log: Log;\n}\n\nconst getFormattedStackTrace = () => new Error().stack!.split('\\n').slice(3).join('\\n');\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nconst kOwnershipScope = Symbol('kOwnershipScope');\nconst kCurrentOwnershipScope = Symbol('kCurrentOwnershipScope');\nconst kDebugInfoProperties = Symbol('kDebugInfoProperties');\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport class OwnershipScope {\n public instance: any;\n\n constructor(\n public constr: any,\n public parent?: OwnershipScope,\n ) {}\n\n getInfo() {\n if (!this.instance) {\n return {};\n }\n const props = this.constr.prototype[kDebugInfoProperties] ?? [];\n const info: any = {};\n for (const prop of props) {\n info[prop] = this.instance[prop];\n }\n return info;\n }\n\n [inspect.custom]() {\n return {\n className: this.constr.name,\n info: this.getInfo(),\n parent: this.parent,\n };\n }\n}\n\nfunction decorateMethodWeakReturnOwnership(prototype: any, key: string) {\n const original = prototype[key];\n prototype[key] = function (...args: any) {\n const res = original.apply(this, ...args);\n\n if (res && typeof res.then === 'function') {\n res.then((value: any) => {\n if (kOwnershipScope in value) {\n value[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n });\n } else {\n if (res && kOwnershipScope in res) {\n res[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n }\n\n return res;\n };\n}\n\nexport function ownershipClass<T extends { new (...args: any[]): {} }>(constr: T) {\n for (const key of Object.getOwnPropertyNames(constr.prototype)) {\n if (key !== 'constructor' && typeof constr.prototype[key] === 'function') {\n decorateMethodWeakReturnOwnership(constr.prototype, key);\n }\n }\n\n return class extends constr {\n constructor(...args: any[]) {\n const currentCausality = (globalThis as any)[kCurrentOwnershipScope];\n (globalThis as any)[kCurrentOwnershipScope] = new OwnershipScope(constr, currentCausality);\n super(...args);\n (this as any)[kOwnershipScope] = (globalThis as any)[kCurrentOwnershipScope];\n (this as any)[kOwnershipScope].instance = this;\n (globalThis as any)[kCurrentOwnershipScope] = currentCausality;\n }\n };\n}\n\nexport const debugInfo = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[kDebugInfoProperties] ??= []).push(propertyKey);\n};\n\nexport const getCurrentOwnershipScope = (thisRef: any) => thisRef;\n"],
5
+ "mappings": ";AAKA,OAAOA,UAAU;AACjB,OAAOC,UAAU;;;;UCKLC,WAAAA;;;;;;GAAAA,aAAAA,WAAAA,CAAAA,EAAAA;AAQL,IAAMC,SAAwC;EACnDC,OAAK;EACLC,OAAK;EACLC,MAAI;EACJC,MAAI;EACJC,OAAK;AACP;AAEO,IAAMC,iBAAiB;EAC5B,CAAA,CAAA,GAAkB;EAClB,CAAA,EAAA,GAAkB;EAClB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAkB;AACpB;;UAEYC,mBAAAA;;;;GAAAA,qBAAAA,mBAAAA,CAAAA,EAAAA;;;AC/BZ,IAAMC,oBAAoBC,OAAO,mBAAA;AAc1B,IAAMC,UAAU,CAACC,QAAaC,aAAqBC,eAAAA;AAEvDF,GAAAA,OAAOH,iBAAAA,MAAuB,CAAA,GAAIM,KAAKF,WAAAA;AAC1C;AAMO,IAAMG,yBAAyB,CAACC,UAAAA;AACrC,MAAI,CAAC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BAAyBD,OAAO,wBAAA;AACtC,IAAME,uBAAuBF,OAAO,sBAAA;AAM7B,IAAMG,iBAAN,MAAMA;EAGXC,YACSC,QACAC,QACP;SAFOD,SAAAA;SACAC,SAAAA;EACN;EAEHC,UAAU;AACR,QAAI,CAAC,KAAKC,UAAU;AAClB,aAAO,CAAC;IACV;AACA,UAAMC,QAAQ,KAAKJ,OAAOK,UAAUR,oBAAAA,KAAyB,CAAA;AAC7D,UAAMS,OAAY,CAAC;AACnB,eAAWC,QAAQH,OAAO;AACxBE,WAAKC,IAAAA,IAAQ,KAAKJ,SAASI,IAAAA;IAC7B;AACA,WAAOD;EACT;EAEA,CAACE,SAAQC,MAAM,IAAI;AACjB,WAAO;MACLC,WAAW,KAAKV,OAAOW;MACvBL,MAAM,KAAKJ,QAAO;MAClBD,QAAQ,KAAKA;IACf;EACF;AACF;AA+CO,IAAMW,2BAA2B,CAACC,YAAiBA;",
6
+ "names": ["omit", "pick", "LogLevel", "levels", "trace", "debug", "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", "includes", "shouldLog", "entry", "filters", "undefined", "some", "meta", "F", "getContextFromEntry", "context", "scopeInfo", "gatherLogInfoFromScope", "S", "Object", "keys", "length", "assign", "Error", "c", "error", "stack", "errorContext", "chalk", "inspect", "nextPromiseId", "createMethodLogDecorator", "log", "arg0", "arg1", "meta", "target", "propertyKey", "descriptor", "method", "value", "methodName", "args", "combinedMeta", "S", "formattedArgs", "map", "arg", "inspect", "join", "startTime", "performance", "now", "result", "apply", "isThenable", "id", "logAsyncBegin", "then", "resolvedValue", "logAsyncResolved", "err", "logAsyncRejected", "logSyncCall", "logSyncError", "Object", "defineProperty", "obj", "info", "formatFunction", "chalk", "gray", "error", "promiseId", "formatPromise", "undefined", "greenCheck", "formatTimeElapsed", "green", "toFixed", "COLOR_FUNCTION", "name", "bold", "rgb", "blue", "defaultsDeep", "loadOptions", "filepath", "dxlog", "localStorage", "globalThis", "localStorage_dxlog", "getItem", "undefined", "JSON", "parse", "err", "console", "info", "CONSOLE_PROCESSOR", "inspect", "DEBUG_PROCESSOR", "config", "entry", "console", "log", "inspect", "getDebugName", "safariCheck", "getRelativeFilename", "filename", "match", "filePath", "CONFIG", "mochaExecutor", "useTestProcessor", "printFileLinks", "APP_BROWSER_PROCESSOR", "config", "entry", "shouldLog", "filters", "LOG_BROWSER_PREFIX", "prefix", "LOG_BROWSER_CSS", "link", "meta", "F", "filepath", "replace", "L", "args", "S", "scope", "scopeName", "name", "getDebugName", "processPrefix", "hostSessionId", "push", "message", "context", "getContextFromEntry", "levels", "LogLevel", "ERROR", "console", "error", "WARN", "warn", "DEBUG", "log", "safariCheck", "length", "join", "level", "C", "TEST_BROWSER_PROCESSOR", "path", "BROWSER_PROCESSOR", "appendFileSync", "mkdirSync", "openSync", "dirname", "jsonify", "EAGAIN_MAX_DURATION", "createFileProcessor", "pathOrFd", "levels", "filters", "fd", "config", "entry", "length", "includes", "level", "shouldLog", "mkdirSync", "dirname", "openSync", "record", "timestamp", "Date", "now", "meta", "file", "F", "line", "L", "context", "jsonify", "getContextFromEntry", "retryTS", "appendFileSync", "JSON", "stringify", "err", "code", "performance", "console", "log", "logFilePath", "getLogFilePath", "process", "env", "LOG_FILE", "HOME", "toISOString", "undefined", "FILE_PROCESSOR", "LogLevel", "ERROR", "WARN", "INFO", "TRACE", "processors", "LogProcessorType", "CONSOLE", "CONSOLE_PROCESSOR", "BROWSER", "BROWSER_PROCESSOR", "DEBUG", "DEBUG_PROCESSOR", "IS_BROWSER", "window", "navigator", "DEFAULT_PROCESSORS", "parseFilter", "filter", "level", "parseLogLevel", "defValue", "LogLevel", "WARN", "levels", "toLowerCase", "lines", "split", "map", "pattern", "getConfig", "options", "nodeOptions", "globalThis", "file", "process", "env", "LOG_CONFIG", "LOG_FILTER", "processor", "LOG_PROCESSOR", "undefined", "mergedOptions", "defaultsDeep", "loadOptions", "filters", "INFO", "captureFilters", "captureFilter", "prefix", "createLog", "log", "params", "processLog", "LogLevel", "DEBUG", "_config", "getConfig", "Object", "defineProperty", "get", "addProcessor", "processor", "DEFAULT_PROCESSORS", "filter", "p", "length", "push", "processors", "config", "options", "trace", "TRACE", "debug", "info", "INFO", "warn", "WARN", "error", "ERROR", "catch", "context", "meta", "message", "break", "stack", "getFormattedStackTrace", "method", "createMethodLogDecorator", "level", "forEach", "globalThis", "dx_log", "Error", "split", "slice", "join", "inspect", "kOwnershipScope", "Symbol", "kCurrentOwnershipScope", "kDebugInfoProperties", "OwnershipScope", "constructor", "constr", "parent", "getInfo", "instance", "props", "prototype", "info", "prop", "inspect", "custom", "className", "name", "getCurrentOwnershipScope", "thisRef"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/log/src/config.ts":{"bytes":3536,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3852,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6644,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":8231,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/browser/index.ts":{"bytes":2848,"imports":[],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":460,"imports":[{"path":"packages/common/log/src/platform/browser/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/console-stub.ts":{"bytes":828,"imports":[],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1070,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":14799,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/file-processor.ts":{"bytes":6675,"imports":[{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/index.ts":{"bytes":817,"imports":[{"path":"packages/common/log/src/processors/console-stub.ts","kind":"import-statement","original":"./console-processor"},{"path":"packages/common/log/src/processors/debug-processor.ts","kind":"import-statement","original":"./debug-processor"},{"path":"packages/common/log/src/processors/browser-processor.ts","kind":"import-statement","original":"./browser-processor"},{"path":"packages/common/log/src/processors/file-processor.ts","kind":"import-statement","original":"./file-processor"}],"format":"esm"},"packages/common/log/src/options.ts":{"bytes":7558,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/platform/index.ts","kind":"import-statement","original":"./platform"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"}],"format":"esm"},"packages/common/log/src/log.ts":{"bytes":10311,"imports":[{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/decorators.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"}],"format":"esm"},"packages/common/log/src/meta.ts":{"bytes":1625,"imports":[],"format":"esm"},"packages/common/log/src/experimental/ownership.ts":{"bytes":9286,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/index.ts":{"bytes":1663,"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/log/src/log.ts","kind":"import-statement","original":"./log"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"},{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"},{"path":"packages/common/log/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/common/log/src/experimental/ownership.ts","kind":"import-statement","original":"./experimental/ownership"}],"format":"esm"}},"outputs":{"packages/common/log/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":37819},"packages/common/log/dist/lib/browser/index.mjs":{"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"exports":["BROWSER_PROCESSOR","CONSOLE_PROCESSOR","DEBUG_PROCESSOR","FILE_PROCESSOR","LogLevel","LogProcessorType","createFileProcessor","gatherLogInfoFromScope","getContextFromEntry","getCurrentOwnershipScope","levels","log","logInfo","omit","parseFilter","pick","shortLevelName","shouldLog"],"entryPoint":"packages/common/log/src/index.ts","inputs":{"packages/common/log/src/index.ts":{"bytesInOutput":64},"packages/common/log/src/config.ts":{"bytesInOutput":703},"packages/common/log/src/scope.ts":{"bytesInOutput":571},"packages/common/log/src/context.ts":{"bytesInOutput":1159},"packages/common/log/src/decorators.ts":{"bytesInOutput":1662},"packages/common/log/src/options.ts":{"bytesInOutput":1542},"packages/common/log/src/platform/browser/index.ts":{"bytesInOutput":424},"packages/common/log/src/platform/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/console-stub.ts":{"bytesInOutput":35},"packages/common/log/src/processors/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/debug-processor.ts":{"bytesInOutput":156},"packages/common/log/src/processors/browser-processor.ts":{"bytesInOutput":2759},"packages/common/log/src/processors/file-processor.ts":{"bytesInOutput":1262},"packages/common/log/src/log.ts":{"bytesInOutput":1928},"packages/common/log/src/experimental/ownership.ts":{"bytesInOutput":792}},"bytes":14047}}}
1
+ {"inputs":{"packages/common/log/src/config.ts":{"bytes":3536,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3852,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6618,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":13956,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/browser/index.ts":{"bytes":2848,"imports":[],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":460,"imports":[{"path":"packages/common/log/src/platform/browser/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/console-stub.ts":{"bytes":828,"imports":[],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1070,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":14794,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/file-processor.ts":{"bytes":9703,"imports":[{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/index.ts":{"bytes":817,"imports":[{"path":"packages/common/log/src/processors/console-stub.ts","kind":"import-statement","original":"./console-processor"},{"path":"packages/common/log/src/processors/debug-processor.ts","kind":"import-statement","original":"./debug-processor"},{"path":"packages/common/log/src/processors/browser-processor.ts","kind":"import-statement","original":"./browser-processor"},{"path":"packages/common/log/src/processors/file-processor.ts","kind":"import-statement","original":"./file-processor"}],"format":"esm"},"packages/common/log/src/options.ts":{"bytes":7558,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/platform/index.ts","kind":"import-statement","original":"./platform"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"}],"format":"esm"},"packages/common/log/src/log.ts":{"bytes":10313,"imports":[{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/decorators.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"}],"format":"esm"},"packages/common/log/src/meta.ts":{"bytes":1625,"imports":[],"format":"esm"},"packages/common/log/src/experimental/ownership.ts":{"bytes":9286,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/index.ts":{"bytes":1663,"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/log/src/log.ts","kind":"import-statement","original":"./log"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"},{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"},{"path":"packages/common/log/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/common/log/src/experimental/ownership.ts","kind":"import-statement","original":"./experimental/ownership"}],"format":"esm"}},"outputs":{"packages/common/log/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":42504},"packages/common/log/dist/lib/browser/index.mjs":{"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true}],"exports":["BROWSER_PROCESSOR","CONSOLE_PROCESSOR","DEBUG_PROCESSOR","FILE_PROCESSOR","LogLevel","LogProcessorType","createFileProcessor","gatherLogInfoFromScope","getContextFromEntry","getCurrentOwnershipScope","levels","log","logInfo","omit","parseFilter","pick","shortLevelName","shouldLog"],"entryPoint":"packages/common/log/src/index.ts","inputs":{"packages/common/log/src/index.ts":{"bytesInOutput":64},"packages/common/log/src/config.ts":{"bytesInOutput":703},"packages/common/log/src/scope.ts":{"bytesInOutput":571},"packages/common/log/src/context.ts":{"bytesInOutput":1153},"packages/common/log/src/decorators.ts":{"bytesInOutput":3148},"packages/common/log/src/options.ts":{"bytesInOutput":1542},"packages/common/log/src/platform/browser/index.ts":{"bytesInOutput":424},"packages/common/log/src/platform/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/console-stub.ts":{"bytesInOutput":35},"packages/common/log/src/processors/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/debug-processor.ts":{"bytesInOutput":156},"packages/common/log/src/processors/browser-processor.ts":{"bytesInOutput":2759},"packages/common/log/src/processors/file-processor.ts":{"bytesInOutput":1762},"packages/common/log/src/log.ts":{"bytesInOutput":1930},"packages/common/log/src/experimental/ownership.ts":{"bytesInOutput":792}},"bytes":16029}}}
@@ -53,11 +53,12 @@ __export(node_exports, {
53
53
  module.exports = __toCommonJS(node_exports);
54
54
  var import_lodash = __toESM(require("lodash.omit"));
55
55
  var import_lodash2 = __toESM(require("lodash.pick"));
56
+ var import_chalk = __toESM(require("chalk"));
56
57
  var import_node_util = require("node:util");
57
58
  var import_lodash3 = __toESM(require("lodash.defaultsdeep"));
58
59
  var import_js_yaml = __toESM(require("js-yaml"));
59
60
  var import_node_fs = __toESM(require("node:fs"));
60
- var import_chalk = __toESM(require("chalk"));
61
+ var import_chalk2 = __toESM(require("chalk"));
61
62
  var import_lodash4 = __toESM(require("lodash.pickby"));
62
63
  var import_node_util2 = require("node:util");
63
64
  var import_util = require("@dxos/util");
@@ -147,7 +148,7 @@ var getContextFromEntry = (entry) => {
147
148
  if (entry.error) {
148
149
  const errorContext = entry.error.context;
149
150
  context = Object.assign(context ?? {}, {
150
- error: entry.error.stack,
151
+ error: entry.error,
151
152
  ...errorContext
152
153
  });
153
154
  }
@@ -156,6 +157,7 @@ var getContextFromEntry = (entry) => {
156
157
  var nextPromiseId = 0;
157
158
  var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
158
159
  const method = descriptor.value;
160
+ const methodName = propertyKey;
159
161
  descriptor.value = function(...args) {
160
162
  const combinedMeta = {
161
163
  ...meta ?? {},
@@ -167,30 +169,54 @@ var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, property
167
169
  const result = method.apply(this, args);
168
170
  if (isThenable(result)) {
169
171
  const id = nextPromiseId++;
170
- log2.info(`${propertyKey}(${formattedArgs}) => Promise { #${id} }`, {}, combinedMeta);
172
+ logAsyncBegin(log2, methodName, formattedArgs, id, combinedMeta);
171
173
  result.then((resolvedValue) => {
172
- if (resolvedValue !== void 0) {
173
- log2.info(`\u2705 resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms => ${(0, import_node_util.inspect)(resolvedValue, false, 1, true)}`, {}, combinedMeta);
174
- } else {
175
- log2.info(`\u2705 resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms`, {}, combinedMeta);
176
- }
174
+ logAsyncResolved(log2, methodName, resolvedValue, id, startTime, combinedMeta);
177
175
  }, (err) => {
178
- log2.info(`\u{1F525} reject #${id} #${(performance.now() - startTime).toFixed(0)}ms => ${err}`, {}, combinedMeta);
176
+ logAsyncRejected(log2, methodName, err, id, startTime, combinedMeta);
179
177
  });
180
178
  } else {
181
- log2.info(`${propertyKey}(${formattedArgs}) => ${(0, import_node_util.inspect)(result, false, 1, true)}`, {}, combinedMeta);
179
+ logSyncCall(log2, methodName, formattedArgs, result, combinedMeta);
182
180
  }
183
181
  return result;
184
182
  } catch (err) {
185
- log2.error(`${propertyKey}(${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
183
+ logSyncError(log2, methodName, formattedArgs, err, combinedMeta);
186
184
  throw err;
187
185
  }
188
186
  };
189
187
  Object.defineProperty(descriptor.value, "name", {
190
- value: propertyKey + "$log"
188
+ value: methodName + "$log"
191
189
  });
192
190
  };
193
191
  var isThenable = (obj) => obj && typeof obj.then === "function";
192
+ var logSyncCall = (log2, methodName, formattedArgs, result, combinedMeta) => {
193
+ log2.info(`.${formatFunction(methodName)} (${formattedArgs}) ${import_chalk.default.gray("resolve")} ${(0, import_node_util.inspect)(result, false, 1, true)}`, {}, combinedMeta);
194
+ };
195
+ var logSyncError = (log2, methodName, formattedArgs, err, combinedMeta) => {
196
+ log2.error(`.${formatFunction(methodName)} (${formattedArgs}) \u{1F525} ${err}`, {}, combinedMeta);
197
+ };
198
+ var logAsyncBegin = (log2, methodName, formattedArgs, promiseId, combinedMeta) => {
199
+ log2.info(`.${formatFunction(methodName)} \u21B4 (${formattedArgs}) ${import_chalk.default.gray("=>")} ${formatPromise(promiseId)}`, {}, combinedMeta);
200
+ };
201
+ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, combinedMeta) => {
202
+ if (resolvedValue !== void 0) {
203
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${import_chalk.default.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${import_chalk.default.gray("=>")} ${(0, import_node_util.inspect)(resolvedValue, false, 1, true)}`, {}, combinedMeta);
204
+ } else {
205
+ log2.info(`.${formatFunction(methodName)} \u21B2 ${greenCheck} ${import_chalk.default.gray("resolve")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`, {}, combinedMeta);
206
+ }
207
+ };
208
+ var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
209
+ log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${import_chalk.default.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${import_chalk.default.gray("=>")} ${err}`, {}, combinedMeta);
210
+ };
211
+ var greenCheck = import_chalk.default.green("\u2714");
212
+ var formatTimeElapsed = (startTime) => import_chalk.default.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
213
+ var COLOR_FUNCTION = [
214
+ 220,
215
+ 220,
216
+ 170
217
+ ];
218
+ var formatFunction = (name) => import_chalk.default.bold(import_chalk.default.rgb(...COLOR_FUNCTION)(name));
219
+ var formatPromise = (id) => import_chalk.default.blue(`Promise#${id}`);
194
220
  var loadOptions = (filepath) => {
195
221
  if (filepath) {
196
222
  try {
@@ -222,17 +248,17 @@ var getRelativeFilename = (filename) => {
222
248
  }
223
249
  return filename;
224
250
  };
225
- var DEFAULT_FORMATTER = (config, { path, line, timestamp, level, message, context, error, scope }) => {
251
+ var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
226
252
  const column = config.options?.formatter?.column;
227
- const filepath = path !== void 0 && line !== void 0 ? import_chalk.default.grey(`${path}:${line}`) : void 0;
253
+ const filepath = path !== void 0 && line !== void 0 ? import_chalk2.default.grey(`${path}:${line}`) : void 0;
228
254
  let instance;
229
255
  if (scope) {
230
256
  const prototype = Object.getPrototypeOf(scope);
231
257
  const id = (0, import_util.getPrototypeSpecificInstanceId)(scope);
232
- instance = import_chalk.default.magentaBright(`${prototype.constructor.name}#${id}`);
258
+ instance = import_chalk2.default.magentaBright(`${prototype.constructor.name}#${id}`);
233
259
  }
234
260
  const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
235
- const formattedLevel = import_chalk.default[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
261
+ const formattedLevel = import_chalk2.default[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
236
262
  const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
237
263
  return config.options?.formatter?.timestampFirst ? [
238
264
  formattedTimestamp,
@@ -256,11 +282,13 @@ var DEFAULT_FORMATTER = (config, { path, line, timestamp, level, message, contex
256
282
  error
257
283
  ];
258
284
  };
259
- var SHORT_FORMATTER = (config, { path, level, message }) => [
260
- import_chalk.default.grey(truncate(path, 16, true)),
261
- import_chalk.default[LEVEL_COLORS[level]](shortLevelName[level]),
262
- message
263
- ];
285
+ var SHORT_FORMATTER = (config, { path, level, message }) => {
286
+ return [
287
+ import_chalk2.default.grey(truncate(path, 16, true)),
288
+ import_chalk2.default[LEVEL_COLORS[level]](shortLevelName[level]),
289
+ message
290
+ ];
291
+ };
264
292
  var formatter = DEFAULT_FORMATTER;
265
293
  var CONSOLE_PROCESSOR = (config, entry) => {
266
294
  const { level, message, meta, error } = entry;
@@ -395,6 +423,7 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
395
423
  }
396
424
  };
397
425
  var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
426
+ var EAGAIN_MAX_DURATION = 1e3;
398
427
  var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
399
428
  let fd;
400
429
  return (config, entry) => {
@@ -422,7 +451,24 @@ var createFileProcessor = ({ pathOrFd, levels: levels2, filters }) => {
422
451
  },
423
452
  context: (0, import_util3.jsonify)(getContextFromEntry(entry))
424
453
  };
425
- (0, import_node_fs2.appendFileSync)(fd, JSON.stringify(record) + "\n");
454
+ let retryTS = 0;
455
+ while (true) {
456
+ try {
457
+ return (0, import_node_fs2.appendFileSync)(fd, JSON.stringify(record) + "\n");
458
+ } catch (err) {
459
+ if (err.code !== "EAGAIN") {
460
+ throw err;
461
+ }
462
+ if (retryTS === 0) {
463
+ retryTS = performance.now();
464
+ } else {
465
+ if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
466
+ console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
467
+ throw err;
468
+ }
469
+ }
470
+ }
471
+ }
426
472
  };
427
473
  };
428
474
  var logFilePath;
@@ -507,7 +553,7 @@ var createLog = () => {
507
553
  log2.info = (...params) => processLog(LogLevel.INFO, ...params);
508
554
  log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
509
555
  log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
510
- log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.stack, context, meta, error);
556
+ log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);
511
557
  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");
512
558
  log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
513
559
  ${getFormattedStackTrace()}`, context, meta);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/config.ts", "../../../src/scope.ts", "../../../src/context.ts", "../../../src/decorators.ts", "../../../src/options.ts", "../../../src/platform/node/index.ts", "../../../src/processors/console-processor.ts", "../../../src/processors/debug-processor.ts", "../../../src/processors/browser-processor.ts", "../../../src/processors/file-processor.ts", "../../../src/log.ts", "../../../src/experimental/ownership.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// Message helpers.\nimport omit from 'lodash.omit';\nimport pick from 'lodash.pick';\n\nexport { omit, pick };\n\nexport * from './config';\nexport * from './context';\nexport * from './log';\nexport { parseFilter } from './options';\nexport * from './processors';\nexport * from './scope';\nexport * from './meta';\n\nexport { getCurrentOwnershipScope } from './experimental/ownership';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n */\n// NOTE: Keep aligned with LogLevel in @dxos/protocols.\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n INFO = 11,\n WARN = 12,\n ERROR = 13,\n}\n\nexport const levels: { [index: string]: LogLevel } = {\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\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.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 = 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\nconst matchFilter = (filter: LogFilter, level: LogLevel, path: string) => {\n return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));\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 true;\n } else {\n return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ''));\n }\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 if (entry.context) {\n if (entry.context instanceof Error) {\n // Additional context from Error.\n const c = (entry.context as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entry.context.stack, ...c });\n } else if (typeof entry.context === 'object') {\n context = Object.assign(context ?? {}, entry.context);\n }\n }\n\n if (entry.error) {\n const errorContext = (entry.error as any).context;\n context = Object.assign(context ?? {}, { error: entry.error.stack, ...errorContext });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport type { LogMethods } from './log';\nimport { type CallMetadata } from './meta';\n\nlet nextPromiseId = 0;\n\nexport const createMethodLogDecorator =\n (log: LogMethods) =>\n (arg0?: never, arg1?: never, meta?: CallMetadata): MethodDecorator =>\n (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const method = descriptor.value!;\n descriptor.value = function (this: any, ...args: any) {\n const combinedMeta = {\n ...(meta ?? {}),\n S: this as any,\n } as CallMetadata;\n\n const formattedArgs = args.map((arg: any) => inspect(arg, false, 1, true)).join(', ');\n\n try {\n const startTime = performance.now();\n const result = method.apply(this, args);\n\n if (isThenable(result)) {\n const id = nextPromiseId++;\n log.info(`${propertyKey as string}(${formattedArgs}) => Promise { #${id} }`, {}, combinedMeta);\n result.then(\n (resolvedValue) => {\n if (resolvedValue !== undefined) {\n log.info(\n `✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms => ${inspect(\n resolvedValue,\n false,\n 1,\n true,\n )}`,\n {},\n combinedMeta,\n );\n } else {\n log.info(`✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms`, {}, combinedMeta);\n }\n },\n (err) => {\n log.info(`🔥 reject #${id} #${(performance.now() - startTime).toFixed(0)}ms => ${err}`, {}, combinedMeta);\n },\n );\n } else {\n log.info(\n `${propertyKey as string}(${formattedArgs}) => ${inspect(result, false, 1, true)}`,\n {},\n combinedMeta,\n );\n }\n\n return result;\n } catch (err) {\n log.error(`${propertyKey as string}(${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);\n throw err;\n }\n };\n Object.defineProperty(descriptor.value, 'name', { value: (propertyKey as string) + '$log' });\n };\n\nconst isThenable = (obj: any): obj is Promise<unknown> => obj && typeof obj.then === 'function';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';\nimport { type LogProcessor } from './context';\nimport { loadOptions } from './platform';\nimport { CONSOLE_PROCESSOR, DEBUG_PROCESSOR, BROWSER_PROCESSOR } from './processors';\n\n/**\n * Processor variants.\n */\nexport const processors: { [index: string]: LogProcessor } = {\n [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,\n [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,\n [LogProcessorType.DEBUG]: DEBUG_PROCESSOR,\n};\n\nconst IS_BROWSER = typeof window !== 'undefined' || typeof navigator !== 'undefined';\n\nexport const DEFAULT_PROCESSORS = [IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];\n\nexport const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] => {\n if (typeof filter === 'number') {\n return [{ level: filter }];\n }\n\n const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;\n\n const lines = typeof filter === 'string' ? filter.split(/,\\s*/) : filter;\n return lines.map((filter) => {\n const [pattern, level] = filter.split(':');\n return level ? { level: parseLogLevel(level), pattern } : { level: parseLogLevel(pattern) };\n });\n};\n\nexport const getConfig = (options?: LogOptions): LogConfig => {\n const nodeOptions: LogOptions | undefined =\n 'process' in globalThis\n ? {\n file: process!.env.LOG_CONFIG,\n filter: process!.env.LOG_FILTER,\n processor: process!.env.LOG_PROCESSOR,\n }\n : undefined;\n\n const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);\n return {\n options: mergedOptions,\n filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),\n captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),\n processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,\n prefix: mergedOptions.prefix,\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport fs from 'node:fs';\n\nimport { type LogOptions } from '../../config';\n\n/**\n * Node config loader.\n */\nexport const loadOptions = (filepath?: string): LogOptions | undefined => {\n if (filepath) {\n // console.log(`Log file: ${fullpath}`);\n try {\n const text = fs.readFileSync(filepath, 'utf-8');\n if (text) {\n return yaml.load(text) as LogOptions;\n }\n } catch (err) {\n console.warn(`Invalid log file: ${filepath}`);\n }\n }\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport chalk from 'chalk';\nimport pickBy from 'lodash.pickby';\nimport { inspect } from 'node:util';\n\nimport { getPrototypeSpecificInstanceId } from '@dxos/util';\n\nimport { type LogConfig, LogLevel, shortLevelName } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {\n [LogLevel.TRACE]: 'gray',\n [LogLevel.DEBUG]: 'gray',\n [LogLevel.INFO]: 'white',\n [LogLevel.WARN]: 'yellow',\n [LogLevel.ERROR]: 'red',\n};\n\nexport const truncate = (text?: string, length = 0, right = false) => {\n const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';\n return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');\n};\n\nconst 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// TODO(burdon): Optional package name.\n// TODO(burdon): Show exceptions on one line.\nexport type FormatParts = {\n path?: string;\n line?: number;\n timestamp?: string;\n level: LogLevel;\n message: string;\n context?: any;\n error?: Error;\n scope?: any;\n};\n\nexport type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[];\n\nexport const DEFAULT_FORMATTER: Formatter = (\n config,\n { path, line, timestamp, level, message, context, error, scope },\n) => {\n const column = config.options?.formatter?.column;\n\n const filepath = path !== undefined && line !== undefined ? chalk.grey(`${path}:${line}`) : undefined;\n\n let instance;\n if (scope) {\n const prototype = Object.getPrototypeOf(scope);\n const id = getPrototypeSpecificInstanceId(scope);\n instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);\n }\n\n const formattedTimestamp = config.options?.formatter?.timestamp ? new Date().toISOString() : undefined;\n const formattedLevel = chalk[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);\n const padding = column && filepath ? ''.padStart(column - filepath.length) : undefined;\n\n return config.options?.formatter?.timestampFirst\n ? [formattedTimestamp, filepath, padding, formattedLevel, instance, message, context, error]\n : [\n // NOTE: File path must come fist for console hyperlinks.\n // Must not truncate for terminal output.\n filepath,\n padding,\n formattedTimestamp,\n formattedLevel,\n instance,\n message,\n context,\n error,\n ];\n};\n\nexport const SHORT_FORMATTER: Formatter = (config, { path, level, message }) => [\n chalk.grey(truncate(path, 16, true)), // NOTE: Breaks terminal linking.\n chalk[LEVEL_COLORS[level]](shortLevelName[level]),\n message,\n];\n\n// TODO(burdon): Config option.\nconst formatter = DEFAULT_FORMATTER;\n\nexport const CONSOLE_PROCESSOR: LogProcessor = (config, entry) => {\n const { level, message, meta, error } = entry;\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n const parts: FormatParts = {\n level,\n message,\n error,\n path: undefined,\n line: undefined,\n scope: undefined,\n context: undefined,\n };\n\n if (meta) {\n parts.path = getRelativeFilename(meta.F);\n parts.line = meta.L;\n parts.scope = meta.S;\n }\n\n const context = getContextFromEntry(entry);\n if (context) {\n // Remove undefined fields.\n // https://nodejs.org/api/util.html#utilinspectobject-options\n parts.context = inspect(\n pickBy(context, (value?: unknown) => value !== undefined),\n { depth: config.options.depth, colors: true, maxArrayLength: 8, sorted: false },\n );\n }\n\n const line = formatter(config, parts).filter(Boolean).join(' ');\n console.log(line);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { type LogProcessor } from '../context';\n\nexport const DEBUG_PROCESSOR: LogProcessor = (config, entry) => {\n console.log(inspect(entry, false, null, true));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { getDebugName, safariCheck } from '@dxos/util';\n\nimport { LogLevel } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst 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\ntype Config = {\n useTestProcessor: boolean;\n printFileLinks: boolean;\n};\n\nconst CONFIG: Config =\n typeof mochaExecutor !== 'undefined'\n ? {\n useTestProcessor: true,\n printFileLinks: true,\n }\n : {\n useTestProcessor: false,\n printFileLinks: false,\n };\n\n/**\n * For running apps in the browser normally.\n */\nconst APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n // Example local editor prefix: 'vscode://file/Users/burdon/Code/dxos/dxos/'.\n const LOG_BROWSER_PREFIX = config.prefix ?? 'https://vscode.dev/github.com/dxos/dxos/blob/main/';\n\n // TODO(burdon): CSS breaks formatting (e.g., [Object] rather than expandable property).\n // TODO(burdon): Consider custom formatters.\n // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html\n // NOTE: Cannot change color of link (from bright white).\n // const LOG_BROWSER_CSS = ['color:gray; font-size:10px; padding-bottom: 4px', 'color:#B97852; font-size:14px;'];\n const LOG_BROWSER_CSS: string[] = [];\n\n let link = '';\n if (entry.meta) {\n const filename = getRelativeFilename(entry.meta.F);\n const filepath = `${LOG_BROWSER_PREFIX.replace(/\\/$/, '')}/${filename}`;\n // TODO(burdon): Line numbers not working for app link, even with colons.\n // https://stackoverflow.com/a/54459820/2804332\n link = `${filepath}#L${entry.meta.L}`;\n }\n\n let args = [];\n\n if (entry.meta?.S) {\n const scope = entry.meta?.S;\n const scopeName = scope.name || getDebugName(scope);\n const processPrefix = entry.meta.S?.hostSessionId ? '[worker] ' : '';\n // TODO(dmaretskyi): Those can be made clickable with a custom formatter.\n args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');\n }\n\n args.push(entry.message);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n // Safari prints source code location as this file, not the caller.\n if (CONFIG.printFileLinks || safariCheck()) {\n if (LOG_BROWSER_CSS?.length) {\n args = [`%c${link}\\n%c${args.join(' ')}`, ...LOG_BROWSER_CSS];\n } else {\n args = [link + '\\n', ...args];\n }\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\n/**\n * For running unit tests in the headless browser.\n */\nconst TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n let path = '';\n if (entry.meta) {\n path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;\n }\n\n let args = [];\n\n const processPrefix = entry.meta?.S?.hostSessionId ? '[worker] ' : '';\n args.push(`${processPrefix}${entry.message}`);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n if (CONFIG.printFileLinks) {\n args = [path, ...args];\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\nexport const BROWSER_PROCESSOR: LogProcessor = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { appendFileSync, mkdirSync, openSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { jsonify } from '@dxos/util';\n\nimport { type LogFilter, LogLevel } from '../config';\nimport { type LogProcessor, getContextFromEntry, shouldLog } from '../context';\n\n/**\n * Create a file processor.\n * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.\n * @param levels - Log levels to process. Takes preference over Filters.\n * @param filters - Filters to apply.\n */\nexport const createFileProcessor = ({\n pathOrFd,\n levels,\n filters,\n}: {\n pathOrFd: string | number;\n levels: LogLevel[];\n filters?: LogFilter[];\n}): LogProcessor => {\n let fd: number | undefined;\n\n return (config, entry) => {\n if (levels.length > 0 && !levels.includes(entry.level)) {\n return;\n }\n if (!shouldLog(entry, filters)) {\n return;\n }\n if (typeof pathOrFd === 'number') {\n fd = pathOrFd;\n } else {\n try {\n mkdirSync(dirname(pathOrFd));\n } catch {}\n fd = openSync(pathOrFd, 'w');\n }\n\n const record = {\n ...entry,\n timestamp: Date.now(),\n meta: {\n file: entry.meta?.F,\n line: entry.meta?.L,\n },\n context: jsonify(getContextFromEntry(entry)),\n };\n appendFileSync(fd, JSON.stringify(record) + '\\n');\n };\n};\n\nlet logFilePath: string | undefined;\nconst getLogFilePath = () => {\n logFilePath ??=\n process.env.LOG_FILE ??\n (process.env.HOME ? `${process.env.HOME}/.dxlog/${new Date().toISOString()}.log` : undefined);\n\n return logFilePath!;\n};\n\nexport const FILE_PROCESSOR: LogProcessor = createFileProcessor({\n pathOrFd: getLogFilePath(),\n levels: [LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.TRACE],\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, LogLevel, type LogOptions } from './config';\nimport { type LogContext, type LogProcessor } from './context';\nimport { createMethodLogDecorator } from './decorators';\nimport { type CallMetadata } from './meta';\nimport { getConfig, DEFAULT_PROCESSORS } from './options';\n\n/**\n * Logging function.\n */\ntype LogFunction = (message: string, context?: LogContext, meta?: CallMetadata) => void;\n\n/**\n * Logging methods.\n */\nexport interface LogMethods {\n trace: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n catch: (error: Error | any, context?: LogContext, meta?: CallMetadata) => void;\n break: () => void;\n stack: (message?: string, context?: never, meta?: CallMetadata) => void;\n method: (arg0?: never, arg1?: never, meta?: CallMetadata) => MethodDecorator;\n}\n\n/**\n * Properties accessible on the logging function.\n */\ninterface Log extends LogMethods, LogFunction {\n config: (options: LogOptions) => void;\n addProcessor: (processor: LogProcessor) => void;\n runtimeConfig: LogConfig;\n}\n\ninterface LogImp extends Log {\n _config: LogConfig;\n}\n\nconst createLog = (): LogImp => {\n const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;\n\n log._config = getConfig();\n Object.defineProperty(log, 'runtimeConfig', { get: () => log._config });\n\n log.addProcessor = (processor: LogProcessor) => {\n if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {\n DEFAULT_PROCESSORS.push(processor);\n }\n if (log._config.processors.filter((p) => p === processor).length === 0) {\n log._config.processors.push(processor);\n }\n };\n\n // Set config.\n log.config = (options: LogOptions) => {\n log._config = getConfig(options);\n };\n\n // TODO(burdon): API to set context and separate error object.\n // E.g., log.warn('failed', { key: 123 }, err);\n\n log.trace = (...params) => processLog(LogLevel.TRACE, ...params);\n log.debug = (...params) => processLog(LogLevel.DEBUG, ...params);\n log.info = (...params) => processLog(LogLevel.INFO, ...params);\n log.warn = (...params) => processLog(LogLevel.WARN, ...params);\n log.error = (...params) => processLog(LogLevel.ERROR, ...params);\n\n // Catch only shows error message, not stacktrace.\n log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.stack, context, meta, error);\n\n // Show break.\n log.break = () => log.info('——————————————————————————————————————————————————');\n\n log.stack = (message, context, meta) =>\n processLog(LogLevel.INFO, `${message ?? 'Stack Dump'}\\n${getFormattedStackTrace()}`, context, meta);\n\n log.method = createMethodLogDecorator(log);\n\n /**\n * Process the current log call.\n */\n const processLog = (\n level: LogLevel,\n message: string,\n context: LogContext = {},\n meta?: CallMetadata,\n error?: Error,\n ) => {\n log._config.processors.forEach((processor) => processor(log._config, { level, message, context, meta, error }));\n };\n\n return log;\n};\n\n/**\n * Global logging function.\n */\nexport const log: Log = ((globalThis as any).dx_log ??= createLog());\n\n/**\n * Accessible from browser console.\n */\ndeclare global {\n // eslint-disable-next-line camelcase\n const dx_log: Log;\n}\n\nconst getFormattedStackTrace = () => new Error().stack!.split('\\n').slice(3).join('\\n');\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nconst kOwnershipScope = Symbol('kOwnershipScope');\nconst kCurrentOwnershipScope = Symbol('kCurrentOwnershipScope');\nconst kDebugInfoProperties = Symbol('kDebugInfoProperties');\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport class OwnershipScope {\n public instance: any;\n\n constructor(\n public constr: any,\n public parent?: OwnershipScope,\n ) {}\n\n getInfo() {\n if (!this.instance) {\n return {};\n }\n const props = this.constr.prototype[kDebugInfoProperties] ?? [];\n const info: any = {};\n for (const prop of props) {\n info[prop] = this.instance[prop];\n }\n return info;\n }\n\n [inspect.custom]() {\n return {\n className: this.constr.name,\n info: this.getInfo(),\n parent: this.parent,\n };\n }\n}\n\nfunction decorateMethodWeakReturnOwnership(prototype: any, key: string) {\n const original = prototype[key];\n prototype[key] = function (...args: any) {\n const res = original.apply(this, ...args);\n\n if (res && typeof res.then === 'function') {\n res.then((value: any) => {\n if (kOwnershipScope in value) {\n value[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n });\n } else {\n if (res && kOwnershipScope in res) {\n res[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n }\n\n return res;\n };\n}\n\nexport function ownershipClass<T extends { new (...args: any[]): {} }>(constr: T) {\n for (const key of Object.getOwnPropertyNames(constr.prototype)) {\n if (key !== 'constructor' && typeof constr.prototype[key] === 'function') {\n decorateMethodWeakReturnOwnership(constr.prototype, key);\n }\n }\n\n return class extends constr {\n constructor(...args: any[]) {\n const currentCausality = (globalThis as any)[kCurrentOwnershipScope];\n (globalThis as any)[kCurrentOwnershipScope] = new OwnershipScope(constr, currentCausality);\n super(...args);\n (this as any)[kOwnershipScope] = (globalThis as any)[kCurrentOwnershipScope];\n (this as any)[kOwnershipScope].instance = this;\n (globalThis as any)[kCurrentOwnershipScope] = currentCausality;\n }\n };\n}\n\nexport const debugInfo = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[kDebugInfoProperties] ??= []).push(propertyKey);\n};\n\nexport const getCurrentOwnershipScope = (thisRef: any) => thisRef;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,oBAAiB;AACjB,IAAAA,iBAAiB;AIFjB,uBAAwB;ACAxB,IAAAA,iBAAyB;ACAzB,qBAAiB;AACjB,qBAAe;ACDf,mBAAkB;AAClB,IAAAA,iBAAmB;AACnB,IAAAC,oBAAwB;AAExB,kBAA+C;ACJ/C,IAAAA,oBA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AAI5J,MAAAA,EAAQE,MAAOqI,MAAM,IAAA,EAAMxF,MAAM,CAAA,EAAG9B,KAAK,IAAA;AC1GlF,IAAM8I,kBAAkBnM,OAAO,iBAAA;AAC/B,IAAMoM,yBAAyBpM,OAAO,wBAAA;AACtC,IAAMqM,uBAAuBrM,OAAO,sBAAA;AAM7B,IAAMsM,iBAAN,MAAMA;EAGX/F,YACSgG,QACAC,QACP;SAFOD,SAAAA;SACAC,SAAAA;EACN;EAEHC,UAAU;AACR,QAAI,CAAC,KAAKrG,UAAU;AAClB,aAAO,CAAC;IACV;AACA,UAAMsG,QAAQ,KAAKH,OAAO9L,UAAU4L,oBAAAA,KAAyB,CAAA;AAC7D,UAAM3M,OAAY,CAAC;AACnB,eAAWmB,QAAQ6L,OAAO;AACxBhN,WAAKmB,IAAAA,IAAQ,KAAKuF,SAASvF,IAAAA;IAC7B;AACA,WAAOnB;EACT;EAEA,CAAC0D,kBAAAA,QAAQuJ,MAAM,IAAI;AACjB,WAAO;MACLC,WAAW,KAAKL,OAAO/F;MACvB9G,MAAM,KAAK+M,QAAO;MAClBD,QAAQ,KAAKA;IACf;EACF;AACF;AA+CO,IAAMK,2BAA2B,CAACC,YAAiBA;",
6
- "names": ["import_lodash", "import_node_util", "import_util", "import_node_fs", "LogLevel", "levels", "trace", "debug", "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", "includes", "shouldLog", "entry", "filters", "undefined", "some", "meta", "F", "getContextFromEntry", "context", "scopeInfo", "S", "keys", "length", "assign", "Error", "c", "stack", "errorContext", "nextPromiseId", "createMethodLogDecorator", "log", "arg0", "arg1", "method", "value", "args", "combinedMeta", "formattedArgs", "map", "arg", "inspect", "join", "startTime", "performance", "now", "result", "apply", "isThenable", "id", "then", "resolvedValue", "toFixed", "defineProperty", "obj", "loadOptions", "filepath", "text", "fs", "readFileSync", "yaml", "load", "console", "LEVEL_COLORS", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "truncate", "right", "str", "slice", "substring", "padStart", "padEnd", "getRelativeFilename", "filename", "match", "filePath", "DEFAULT_FORMATTER", "config", "line", "timestamp", "column", "options", "formatter", "chalk", "grey", "instance", "getPrototypeSpecificInstanceId", "magentaBright", "constructor", "name", "formattedTimestamp", "Date", "toISOString", "formattedLevel", "padding", "timestampFirst", "SHORT_FORMATTER", "CONSOLE_PROCESSOR", "parts", "L", "pickBy", "depth", "colors", "maxArrayLength", "sorted", "Boolean", "DEBUG_PROCESSOR", "CONFIG", "mochaExecutor", "useTestProcessor", "printFileLinks", "APP_BROWSER_PROCESSOR", "LOG_BROWSER_PREFIX", "prefix", "LOG_BROWSER_CSS", "link", "replace", "scopeName", "getDebugName", "processPrefix", "hostSessionId", "safariCheck", "C", "TEST_BROWSER_PROCESSOR", "BROWSER_PROCESSOR", "createFileProcessor", "pathOrFd", "fd", "mkdirSync", "dirname", "openSync", "record", "file", "jsonify", "appendFileSync", "JSON", "stringify", "logFilePath", "getLogFilePath", "process", "env", "LOG_FILE", "HOME", "FILE_PROCESSOR", "processors", "CONSOLE", "BROWSER", "IS_BROWSER", "window", "navigator", "DEFAULT_PROCESSORS", "parseFilter", "parseLogLevel", "defValue", "toLowerCase", "lines", "split", "getConfig", "nodeOptions", "globalThis", "LOG_CONFIG", "LOG_FILTER", "processor", "LOG_PROCESSOR", "mergedOptions", "defaultsDeep", "captureFilters", "captureFilter", "createLog", "params", "processLog", "_config", "get", "addProcessor", "p", "catch", "break", "getFormattedStackTrace", "forEach", "dx_log", "kOwnershipScope", "kCurrentOwnershipScope", "kDebugInfoProperties", "OwnershipScope", "constr", "parent", "getInfo", "props", "custom", "className", "getCurrentOwnershipScope", "thisRef"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// Message helpers.\nimport omit from 'lodash.omit';\nimport pick from 'lodash.pick';\n\nexport { omit, pick };\n\nexport * from './config';\nexport * from './context';\nexport * from './log';\nexport { parseFilter } from './options';\nexport * from './processors';\nexport * from './scope';\nexport * from './meta';\n\nexport { getCurrentOwnershipScope } from './experimental/ownership';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n */\n// NOTE: Keep aligned with LogLevel in @dxos/protocols.\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n INFO = 11,\n WARN = 12,\n ERROR = 13,\n}\n\nexport const levels: { [index: string]: LogLevel } = {\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\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.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 = 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\nconst matchFilter = (filter: LogFilter, level: LogLevel, path: string) => {\n return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));\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 true;\n } else {\n return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ''));\n }\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 if (entry.context) {\n if (entry.context instanceof Error) {\n // Additional context from Error.\n const c = (entry.context as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entry.context.stack, ...c });\n } else if (typeof entry.context === 'object') {\n context = Object.assign(context ?? {}, entry.context);\n }\n }\n\n if (entry.error) {\n const errorContext = (entry.error as any).context;\n context = Object.assign(context ?? {}, { error: entry.error, ...errorContext });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport chalk from 'chalk';\nimport { inspect } from 'node:util';\n\nimport type { LogMethods } from './log';\nimport { type CallMetadata } from './meta';\n\nlet nextPromiseId = 0;\n\nexport const createMethodLogDecorator =\n (log: LogMethods) =>\n (arg0?: never, arg1?: never, meta?: CallMetadata): MethodDecorator =>\n (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const method = descriptor.value!;\n const methodName = propertyKey as string;\n descriptor.value = function (this: any, ...args: any) {\n const combinedMeta = {\n ...(meta ?? {}),\n S: this as any,\n } as CallMetadata;\n\n const formattedArgs = args.map((arg: any) => inspect(arg, false, 1, true)).join(', ');\n\n try {\n const startTime = performance.now();\n const result = method.apply(this, args);\n\n if (isThenable(result)) {\n const id = nextPromiseId++;\n logAsyncBegin(log, methodName, formattedArgs, id, combinedMeta);\n result.then(\n (resolvedValue) => {\n logAsyncResolved(log, methodName, resolvedValue, id, startTime, combinedMeta);\n },\n (err) => {\n logAsyncRejected(log, methodName, err, id, startTime, combinedMeta);\n },\n );\n } else {\n logSyncCall(log, methodName, formattedArgs, result, combinedMeta);\n }\n\n return result;\n } catch (err: any) {\n logSyncError(log, methodName, formattedArgs, err, combinedMeta);\n throw err;\n }\n };\n Object.defineProperty(descriptor.value, 'name', { value: methodName + '$log' });\n };\n\nconst isThenable = (obj: any): obj is Promise<unknown> => obj && typeof obj.then === 'function';\n\nconst logSyncCall = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n result: unknown,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray('resolve')} ${inspect(result, false, 1, true)}`,\n {},\n combinedMeta,\n );\n};\n\nconst logSyncError = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n err: Error,\n combinedMeta: CallMetadata,\n) => {\n log.error(`.${formatFunction(methodName)} (${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);\n};\n\nconst logAsyncBegin = (\n log: LogMethods,\n methodName: string,\n formattedArgs: string,\n promiseId: number,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} ↴ (${formattedArgs}) ${chalk.gray('=>')} ${formatPromise(promiseId)}`,\n {},\n combinedMeta,\n );\n};\n\nconst logAsyncResolved = (\n log: LogMethods,\n methodName: string,\n resolvedValue: unknown | undefined,\n promiseId: number,\n startTime: number,\n combinedMeta: CallMetadata,\n) => {\n if (resolvedValue !== undefined) {\n log.info(\n `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${inspect(\n resolvedValue,\n false,\n 1,\n true,\n )}`,\n {},\n combinedMeta,\n );\n } else {\n log.info(\n `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`,\n {},\n combinedMeta,\n );\n }\n};\n\nconst logAsyncRejected = (\n log: LogMethods,\n methodName: string,\n err: Error,\n promiseId: number,\n startTime: number,\n combinedMeta: CallMetadata,\n) => {\n log.info(\n `.${formatFunction(methodName)} ↲ 🔥 ${chalk.gray('reject')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${err}`,\n {},\n combinedMeta,\n );\n};\n\nconst greenCheck = chalk.green('✔');\n\nconst formatTimeElapsed = (startTime: number) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);\n\nconst COLOR_FUNCTION = [220, 220, 170] as const;\n\nconst formatFunction = (name: string) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));\n\nconst formatPromise = (id: number) => chalk.blue(`Promise#${id}`);\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\n\nimport { type LogConfig, type LogFilter, LogLevel, type LogOptions, LogProcessorType, levels } from './config';\nimport { type LogProcessor } from './context';\nimport { loadOptions } from './platform';\nimport { CONSOLE_PROCESSOR, DEBUG_PROCESSOR, BROWSER_PROCESSOR } from './processors';\n\n/**\n * Processor variants.\n */\nexport const processors: { [index: string]: LogProcessor } = {\n [LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,\n [LogProcessorType.BROWSER]: BROWSER_PROCESSOR,\n [LogProcessorType.DEBUG]: DEBUG_PROCESSOR,\n};\n\nconst IS_BROWSER = typeof window !== 'undefined' || typeof navigator !== 'undefined';\n\nexport const DEFAULT_PROCESSORS = [IS_BROWSER ? BROWSER_PROCESSOR : CONSOLE_PROCESSOR];\n\nexport const parseFilter = (filter: string | string[] | LogLevel): LogFilter[] => {\n if (typeof filter === 'number') {\n return [{ level: filter }];\n }\n\n const parseLogLevel = (level: string, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;\n\n const lines = typeof filter === 'string' ? filter.split(/,\\s*/) : filter;\n return lines.map((filter) => {\n const [pattern, level] = filter.split(':');\n return level ? { level: parseLogLevel(level), pattern } : { level: parseLogLevel(pattern) };\n });\n};\n\nexport const getConfig = (options?: LogOptions): LogConfig => {\n const nodeOptions: LogOptions | undefined =\n 'process' in globalThis\n ? {\n file: process!.env.LOG_CONFIG,\n filter: process!.env.LOG_FILTER,\n processor: process!.env.LOG_PROCESSOR,\n }\n : undefined;\n\n const mergedOptions: LogOptions = defaultsDeep({}, loadOptions(nodeOptions?.file), nodeOptions, options);\n return {\n options: mergedOptions,\n filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),\n captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),\n processors: mergedOptions.processor ? [processors[mergedOptions.processor]] : DEFAULT_PROCESSORS,\n prefix: mergedOptions.prefix,\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport fs from 'node:fs';\n\nimport { type LogOptions } from '../../config';\n\n/**\n * Node config loader.\n */\nexport const loadOptions = (filepath?: string): LogOptions | undefined => {\n if (filepath) {\n // console.log(`Log file: ${fullpath}`);\n try {\n const text = fs.readFileSync(filepath, 'utf-8');\n if (text) {\n return yaml.load(text) as LogOptions;\n }\n } catch (err) {\n console.warn(`Invalid log file: ${filepath}`);\n }\n }\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport chalk from 'chalk';\nimport pickBy from 'lodash.pickby';\nimport { inspect } from 'node:util';\n\nimport { getPrototypeSpecificInstanceId } from '@dxos/util';\n\nimport { type LogConfig, LogLevel, shortLevelName } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = {\n [LogLevel.TRACE]: 'gray',\n [LogLevel.DEBUG]: 'gray',\n [LogLevel.INFO]: 'white',\n [LogLevel.WARN]: 'yellow',\n [LogLevel.ERROR]: 'red',\n};\n\nexport const truncate = (text?: string, length = 0, right = false) => {\n const str = text && length ? (right ? text.slice(-length) : text.substring(0, length)) : text ?? '';\n return right ? str.padStart(length, ' ') : str.padEnd(length, ' ');\n};\n\nconst 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// TODO(burdon): Optional package name.\n// TODO(burdon): Show exceptions on one line.\nexport type FormatParts = {\n path?: string;\n line?: number;\n timestamp?: string;\n level: LogLevel;\n message: string;\n context?: any;\n error?: Error;\n scope?: any;\n};\n\nexport type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[];\n\nexport const DEFAULT_FORMATTER: Formatter = (\n config,\n { path, line, level, message, context, error, scope },\n): string[] => {\n const column = config.options?.formatter?.column;\n const filepath = path !== undefined && line !== undefined ? chalk.grey(`${path}:${line}`) : undefined;\n\n let instance;\n if (scope) {\n const prototype = Object.getPrototypeOf(scope);\n const id = getPrototypeSpecificInstanceId(scope);\n instance = chalk.magentaBright(`${prototype.constructor.name}#${id}`);\n }\n\n const formattedTimestamp = config.options?.formatter?.timestamp ? new Date().toISOString() : undefined;\n const formattedLevel = chalk[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);\n const padding = column && filepath ? ''.padStart(column - filepath.length) : undefined;\n\n return config.options?.formatter?.timestampFirst\n ? [formattedTimestamp, filepath, padding, formattedLevel, instance, message, context, error]\n : [\n // NOTE: File path must come fist for console hyperlinks.\n // Must not truncate for terminal output.\n filepath,\n padding,\n formattedTimestamp,\n formattedLevel,\n instance,\n message,\n context,\n error,\n ];\n};\n\nexport const SHORT_FORMATTER: Formatter = (config, { path, level, message }) => {\n return [\n chalk.grey(truncate(path, 16, true)), // NOTE: Breaks terminal linking.\n chalk[LEVEL_COLORS[level]](shortLevelName[level]),\n message,\n ];\n};\n\n// TODO(burdon): Config option.\nconst formatter = DEFAULT_FORMATTER;\n\nexport const CONSOLE_PROCESSOR: LogProcessor = (config, entry) => {\n const { level, message, meta, error } = entry;\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n const parts: FormatParts = {\n level,\n message,\n error,\n path: undefined,\n line: undefined,\n scope: undefined,\n context: undefined,\n };\n\n if (meta) {\n parts.path = getRelativeFilename(meta.F);\n parts.line = meta.L;\n parts.scope = meta.S;\n }\n\n const context = getContextFromEntry(entry);\n if (context) {\n // Remove undefined fields.\n // https://nodejs.org/api/util.html#utilinspectobject-options\n parts.context = inspect(\n pickBy(context, (value?: unknown) => value !== undefined),\n { depth: config.options.depth, colors: true, maxArrayLength: 8, sorted: false },\n );\n }\n\n const line = formatter(config, parts).filter(Boolean).join(' ');\n console.log(line);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nimport { type LogProcessor } from '../context';\n\nexport const DEBUG_PROCESSOR: LogProcessor = (config, entry) => {\n console.log(inspect(entry, false, null, true));\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { getDebugName, safariCheck } from '@dxos/util';\n\nimport { LogLevel } from '../config';\nimport { getContextFromEntry, type LogProcessor, shouldLog } from '../context';\n\nconst 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\ntype Config = {\n useTestProcessor: boolean;\n printFileLinks: boolean;\n};\n\nconst CONFIG: Config =\n typeof mochaExecutor !== 'undefined'\n ? {\n useTestProcessor: true,\n printFileLinks: true,\n }\n : {\n useTestProcessor: false,\n printFileLinks: false,\n };\n\n/**\n * For running apps in the browser normally.\n */\nconst APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n // Example local editor prefix: 'vscode://file/Users/burdon/Code/dxos/dxos/'.\n const LOG_BROWSER_PREFIX = config.prefix ?? 'https://vscode.dev/github.com/dxos/dxos/blob/main/';\n\n // TODO(burdon): CSS breaks formatting (e.g., [Object] rather than expandable property).\n // TODO(burdon): Consider custom formatters.\n // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html\n // NOTE: Cannot change color of link (from bright white).\n // const LOG_BROWSER_CSS = ['color:gray; font-size:10px; padding-bottom: 4px', 'color:#B97852; font-size:14px;'];\n const LOG_BROWSER_CSS: string[] = [];\n\n let link = '';\n if (entry.meta) {\n const filename = getRelativeFilename(entry.meta.F);\n const filepath = `${LOG_BROWSER_PREFIX.replace(/\\/$/, '')}/${filename}`;\n // TODO(burdon): Line numbers not working for app link, even with colons.\n // https://stackoverflow.com/a/54459820/2804332\n link = `${filepath}#L${entry.meta.L}`;\n }\n\n let args = [];\n\n if (entry.meta?.S) {\n const scope = entry.meta?.S;\n const scopeName = scope.name || getDebugName(scope);\n const processPrefix = entry.meta.S?.hostSessionId ? '[worker] ' : '';\n // TODO(dmaretskyi): Those can be made clickable with a custom formatter.\n args.push(`%c${processPrefix}${scopeName}`, 'color:#C026D3;font-weight:bold');\n }\n\n args.push(entry.message);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n // Safari prints source code location as this file, not the caller.\n if (CONFIG.printFileLinks || safariCheck()) {\n if (LOG_BROWSER_CSS?.length) {\n args = [`%c${link}\\n%c${args.join(' ')}`, ...LOG_BROWSER_CSS];\n } else {\n args = [link + '\\n', ...args];\n }\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\n/**\n * For running unit tests in the headless browser.\n */\nconst TEST_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {\n if (!shouldLog(entry, config.filters)) {\n return;\n }\n\n let path = '';\n if (entry.meta) {\n path = `${getRelativeFilename(entry.meta.F)}:${entry.meta.L}`;\n }\n\n let args = [];\n\n const processPrefix = entry.meta?.S?.hostSessionId ? '[worker] ' : '';\n args.push(`${processPrefix}${entry.message}`);\n\n const context = getContextFromEntry(entry);\n if (context) {\n args.push(context);\n }\n\n const levels: any = {\n [LogLevel.ERROR]: console.error,\n [LogLevel.WARN]: console.warn,\n [LogLevel.DEBUG]: console.log,\n };\n\n if (CONFIG.printFileLinks) {\n args = [path, ...args];\n }\n\n const level = levels[entry.level] ?? console.log;\n if (typeof entry.meta?.C === 'function') {\n entry.meta.C(level, args);\n } else {\n level(...args);\n }\n};\n\nexport const BROWSER_PROCESSOR: LogProcessor = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { appendFileSync, mkdirSync, openSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { jsonify } from '@dxos/util';\n\nimport { type LogFilter, LogLevel } from '../config';\nimport { type LogProcessor, getContextFromEntry, shouldLog } from '../context';\n\n// Amount of time to retry writing after encountering EAGAIN before giving up.\nconst EAGAIN_MAX_DURATION = 1000;\n/**\n * Create a file processor.\n * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.\n * @param levels - Log levels to process. Takes preference over Filters.\n * @param filters - Filters to apply.\n */\nexport const createFileProcessor = ({\n pathOrFd,\n levels,\n filters,\n}: {\n pathOrFd: string | number;\n levels: LogLevel[];\n filters?: LogFilter[];\n}): LogProcessor => {\n let fd: number | undefined;\n\n return (config, entry) => {\n if (levels.length > 0 && !levels.includes(entry.level)) {\n return;\n }\n if (!shouldLog(entry, filters)) {\n return;\n }\n if (typeof pathOrFd === 'number') {\n fd = pathOrFd;\n } else {\n try {\n mkdirSync(dirname(pathOrFd));\n } catch {}\n fd = openSync(pathOrFd, 'w');\n }\n\n const record = {\n ...entry,\n timestamp: Date.now(),\n meta: {\n file: entry.meta?.F,\n line: entry.meta?.L,\n },\n context: jsonify(getContextFromEntry(entry)),\n };\n let retryTS: number = 0;\n\n // Retry writing if EAGAIN is encountered.\n //\n // Node may set stdout and stderr to non-blocking. https://github.com/nodejs/node/issues/42826\n // This can cause EAGAIN errors when writing to them.\n // In order to not drop logs, make log methods asynchronous, or deal with buffering/delayed writes, spin until write succeeds.\n\n while (true) {\n try {\n return appendFileSync(fd, JSON.stringify(record) + '\\n');\n } catch (err: any) {\n if (err.code !== 'EAGAIN') {\n throw err;\n }\n if (retryTS === 0) {\n retryTS = performance.now();\n } else {\n if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {\n console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);\n throw err;\n }\n }\n }\n }\n };\n};\n\nlet logFilePath: string | undefined;\nconst getLogFilePath = () => {\n logFilePath ??=\n process.env.LOG_FILE ??\n (process.env.HOME ? `${process.env.HOME}/.dxlog/${new Date().toISOString()}.log` : undefined);\n\n return logFilePath!;\n};\n\nexport const FILE_PROCESSOR: LogProcessor = createFileProcessor({\n pathOrFd: getLogFilePath(),\n levels: [LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO, LogLevel.TRACE],\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, LogLevel, type LogOptions } from './config';\nimport { type LogContext, type LogProcessor } from './context';\nimport { createMethodLogDecorator } from './decorators';\nimport { type CallMetadata } from './meta';\nimport { getConfig, DEFAULT_PROCESSORS } from './options';\n\n/**\n * Logging function.\n */\ntype LogFunction = (message: string, context?: LogContext, meta?: CallMetadata) => void;\n\n/**\n * Logging methods.\n */\nexport interface LogMethods {\n trace: LogFunction;\n debug: LogFunction;\n info: LogFunction;\n warn: LogFunction;\n error: LogFunction;\n catch: (error: Error | any, context?: LogContext, meta?: CallMetadata) => void;\n break: () => void;\n stack: (message?: string, context?: never, meta?: CallMetadata) => void;\n method: (arg0?: never, arg1?: never, meta?: CallMetadata) => MethodDecorator;\n}\n\n/**\n * Properties accessible on the logging function.\n */\ninterface Log extends LogMethods, LogFunction {\n config: (options: LogOptions) => void;\n addProcessor: (processor: LogProcessor) => void;\n runtimeConfig: LogConfig;\n}\n\ninterface LogImp extends Log {\n _config: LogConfig;\n}\n\nconst createLog = (): LogImp => {\n const log: LogImp = ((...params) => processLog(LogLevel.DEBUG, ...params)) as LogImp;\n\n log._config = getConfig();\n Object.defineProperty(log, 'runtimeConfig', { get: () => log._config });\n\n log.addProcessor = (processor: LogProcessor) => {\n if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {\n DEFAULT_PROCESSORS.push(processor);\n }\n if (log._config.processors.filter((p) => p === processor).length === 0) {\n log._config.processors.push(processor);\n }\n };\n\n // Set config.\n log.config = (options: LogOptions) => {\n log._config = getConfig(options);\n };\n\n // TODO(burdon): API to set context and separate error object.\n // E.g., log.warn('failed', { key: 123 }, err);\n\n log.trace = (...params) => processLog(LogLevel.TRACE, ...params);\n log.debug = (...params) => processLog(LogLevel.DEBUG, ...params);\n log.info = (...params) => processLog(LogLevel.INFO, ...params);\n log.warn = (...params) => processLog(LogLevel.WARN, ...params);\n log.error = (...params) => processLog(LogLevel.ERROR, ...params);\n\n // Catch only shows error message, not stacktrace.\n log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);\n\n // Show break.\n log.break = () => log.info('——————————————————————————————————————————————————');\n\n log.stack = (message, context, meta) =>\n processLog(LogLevel.INFO, `${message ?? 'Stack Dump'}\\n${getFormattedStackTrace()}`, context, meta);\n\n log.method = createMethodLogDecorator(log);\n\n /**\n * Process the current log call.\n */\n const processLog = (\n level: LogLevel,\n message: string,\n context: LogContext = {},\n meta?: CallMetadata,\n error?: Error,\n ) => {\n log._config.processors.forEach((processor) => processor(log._config, { level, message, context, meta, error }));\n };\n\n return log;\n};\n\n/**\n * Global logging function.\n */\nexport const log: Log = ((globalThis as any).dx_log ??= createLog());\n\n/**\n * Accessible from browser console.\n */\ndeclare global {\n // eslint-disable-next-line camelcase\n const dx_log: Log;\n}\n\nconst getFormattedStackTrace = () => new Error().stack!.split('\\n').slice(3).join('\\n');\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { inspect } from 'node:util';\n\nconst kOwnershipScope = Symbol('kOwnershipScope');\nconst kCurrentOwnershipScope = Symbol('kCurrentOwnershipScope');\nconst kDebugInfoProperties = Symbol('kDebugInfoProperties');\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport class OwnershipScope {\n public instance: any;\n\n constructor(\n public constr: any,\n public parent?: OwnershipScope,\n ) {}\n\n getInfo() {\n if (!this.instance) {\n return {};\n }\n const props = this.constr.prototype[kDebugInfoProperties] ?? [];\n const info: any = {};\n for (const prop of props) {\n info[prop] = this.instance[prop];\n }\n return info;\n }\n\n [inspect.custom]() {\n return {\n className: this.constr.name,\n info: this.getInfo(),\n parent: this.parent,\n };\n }\n}\n\nfunction decorateMethodWeakReturnOwnership(prototype: any, key: string) {\n const original = prototype[key];\n prototype[key] = function (...args: any) {\n const res = original.apply(this, ...args);\n\n if (res && typeof res.then === 'function') {\n res.then((value: any) => {\n if (kOwnershipScope in value) {\n value[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n });\n } else {\n if (res && kOwnershipScope in res) {\n res[kOwnershipScope].parent ??= this[kOwnershipScope];\n }\n }\n\n return res;\n };\n}\n\nexport function ownershipClass<T extends { new (...args: any[]): {} }>(constr: T) {\n for (const key of Object.getOwnPropertyNames(constr.prototype)) {\n if (key !== 'constructor' && typeof constr.prototype[key] === 'function') {\n decorateMethodWeakReturnOwnership(constr.prototype, key);\n }\n }\n\n return class extends constr {\n constructor(...args: any[]) {\n const currentCausality = (globalThis as any)[kCurrentOwnershipScope];\n (globalThis as any)[kCurrentOwnershipScope] = new OwnershipScope(constr, currentCausality);\n super(...args);\n (this as any)[kOwnershipScope] = (globalThis as any)[kCurrentOwnershipScope];\n (this as any)[kOwnershipScope].instance = this;\n (globalThis as any)[kCurrentOwnershipScope] = currentCausality;\n }\n };\n}\n\nexport const debugInfo = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[kDebugInfoProperties] ??= []).push(propertyKey);\n};\n\nexport const getCurrentOwnershipScope = (thisRef: any) => thisRef;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,oBAAiB;AACjB,IAAAA,iBAAiB;AIFjB,mBAAkB;AAClB,uBAAwB;ACDxB,IAAAA,iBAAyB;ACAzB,q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mB,IAAAA,IAAQ,KAAKwG,SAASxG,IAAAA;IAC7B;AACA,WAAOnB;EACT;EAEA,CAAC2D,kBAAAA,QAAQ0K,MAAM,IAAI;AACjB,WAAO;MACLC,WAAW,KAAKL,OAAO1I;MACvBvF,MAAM,KAAKmO,QAAO;MAClBD,QAAQ,KAAKA;IACf;EACF;AACF;AA+CO,IAAMK,2BAA2B,CAACC,YAAiBA;",
6
+ "names": ["import_lodash", "import_chalk", "import_node_util", "import_util", "import_node_fs", "LogLevel", "levels", "trace", "debug", "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", "includes", "shouldLog", "entry", "filters", "undefined", "some", "meta", "F", "getContextFromEntry", "context", "scopeInfo", "S", "keys", "length", "assign", "Error", "c", "stack", "errorContext", "nextPromiseId", "createMethodLogDecorator", "log", "arg0", "arg1", "method", "value", "methodName", "args", "combinedMeta", "formattedArgs", "map", "arg", "inspect", "join", "startTime", "performance", "now", "result", "apply", "isThenable", "id", "logAsyncBegin", "then", "resolvedValue", "logAsyncResolved", "logAsyncRejected", "logSyncCall", "logSyncError", "defineProperty", "obj", "formatFunction", "chalk", "gray", "promiseId", "formatPromise", "greenCheck", "formatTimeElapsed", "green", "toFixed", "COLOR_FUNCTION", "name", "bold", "rgb", "blue", "loadOptions", "filepath", "text", "fs", "readFileSync", "yaml", "load", "console", "LEVEL_COLORS", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "truncate", "right", "str", "slice", "substring", "padStart", "padEnd", "getRelativeFilename", "filename", "match", "filePath", "DEFAULT_FORMATTER", "config", "line", "column", "options", "formatter", "grey", "instance", "getPrototypeSpecificInstanceId", "magentaBright", "constructor", "formattedTimestamp", "timestamp", "Date", "toISOString", "formattedLevel", "padding", "timestampFirst", "SHORT_FORMATTER", "CONSOLE_PROCESSOR", "parts", "L", "pickBy", "depth", "colors", "maxArrayLength", "sorted", "Boolean", "DEBUG_PROCESSOR", "CONFIG", "mochaExecutor", "useTestProcessor", "printFileLinks", "APP_BROWSER_PROCESSOR", "LOG_BROWSER_PREFIX", "prefix", "LOG_BROWSER_CSS", "link", "replace", "scopeName", "getDebugName", "processPrefix", "hostSessionId", "safariCheck", "C", "TEST_BROWSER_PROCESSOR", "BROWSER_PROCESSOR", "EAGAIN_MAX_DURATION", "createFileProcessor", "pathOrFd", "fd", "mkdirSync", "dirname", "openSync", "record", "file", "jsonify", "retryTS", "appendFileSync", "JSON", "stringify", "code", "logFilePath", "getLogFilePath", "process", "env", "LOG_FILE", "HOME", "FILE_PROCESSOR", "processors", "CONSOLE", "BROWSER", "IS_BROWSER", "window", "navigator", "DEFAULT_PROCESSORS", "parseFilter", "parseLogLevel", "defValue", "toLowerCase", "lines", "split", "getConfig", "nodeOptions", "globalThis", "LOG_CONFIG", "LOG_FILTER", "processor", "LOG_PROCESSOR", "mergedOptions", "defaultsDeep", "captureFilters", "captureFilter", "createLog", "params", "processLog", "_config", "get", "addProcessor", "p", "catch", "break", "getFormattedStackTrace", "forEach", "dx_log", "kOwnershipScope", "kCurrentOwnershipScope", "kDebugInfoProperties", "OwnershipScope", "constr", "parent", "getInfo", "props", "custom", "className", "getCurrentOwnershipScope", "thisRef"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/log/src/config.ts":{"bytes":3536,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3852,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6644,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":8231,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/node/index.ts":{"bytes":2051,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":460,"imports":[{"path":"packages/common/log/src/platform/node/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/console-processor.ts":{"bytes":14089,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"lodash.pickby","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1070,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":14799,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/file-processor.ts":{"bytes":6675,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/index.ts":{"bytes":817,"imports":[{"path":"packages/common/log/src/processors/console-processor.ts","kind":"import-statement","original":"./console-processor"},{"path":"packages/common/log/src/processors/debug-processor.ts","kind":"import-statement","original":"./debug-processor"},{"path":"packages/common/log/src/processors/browser-processor.ts","kind":"import-statement","original":"./browser-processor"},{"path":"packages/common/log/src/processors/file-processor.ts","kind":"import-statement","original":"./file-processor"}],"format":"esm"},"packages/common/log/src/options.ts":{"bytes":7558,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/platform/index.ts","kind":"import-statement","original":"./platform"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"}],"format":"esm"},"packages/common/log/src/log.ts":{"bytes":10311,"imports":[{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/decorators.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"}],"format":"esm"},"packages/common/log/src/meta.ts":{"bytes":1625,"imports":[],"format":"esm"},"packages/common/log/src/experimental/ownership.ts":{"bytes":9286,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/index.ts":{"bytes":1663,"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/log/src/log.ts","kind":"import-statement","original":"./log"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"},{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"},{"path":"packages/common/log/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/common/log/src/experimental/ownership.ts","kind":"import-statement","original":"./experimental/ownership"}],"format":"esm"}},"outputs":{"packages/common/log/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":44511},"packages/common/log/dist/lib/node/index.cjs":{"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"lodash.pickby","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["BROWSER_PROCESSOR","CONSOLE_PROCESSOR","DEBUG_PROCESSOR","DEFAULT_FORMATTER","FILE_PROCESSOR","LogLevel","LogProcessorType","SHORT_FORMATTER","createFileProcessor","gatherLogInfoFromScope","getContextFromEntry","getCurrentOwnershipScope","levels","log","logInfo","omit","parseFilter","pick","shortLevelName","shouldLog","truncate"],"entryPoint":"packages/common/log/src/index.ts","inputs":{"packages/common/log/src/index.ts":{"bytesInOutput":64},"packages/common/log/src/config.ts":{"bytesInOutput":703},"packages/common/log/src/scope.ts":{"bytesInOutput":571},"packages/common/log/src/context.ts":{"bytesInOutput":1159},"packages/common/log/src/decorators.ts":{"bytesInOutput":1652},"packages/common/log/src/options.ts":{"bytesInOutput":1542},"packages/common/log/src/platform/node/index.ts":{"bytesInOutput":315},"packages/common/log/src/platform/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/console-processor.ts":{"bytesInOutput":2905},"packages/common/log/src/processors/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/debug-processor.ts":{"bytesInOutput":146},"packages/common/log/src/processors/browser-processor.ts":{"bytesInOutput":2762},"packages/common/log/src/processors/file-processor.ts":{"bytesInOutput":1242},"packages/common/log/src/log.ts":{"bytesInOutput":1928},"packages/common/log/src/experimental/ownership.ts":{"bytesInOutput":782}},"bytes":16815}}}
1
+ {"inputs":{"packages/common/log/src/config.ts":{"bytes":3536,"imports":[],"format":"esm"},"packages/common/log/src/scope.ts":{"bytes":3852,"imports":[],"format":"esm"},"packages/common/log/src/context.ts":{"bytes":6618,"imports":[{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"}],"format":"esm"},"packages/common/log/src/decorators.ts":{"bytes":13956,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/node/index.ts":{"bytes":2051,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/platform/index.ts":{"bytes":460,"imports":[{"path":"packages/common/log/src/platform/node/index.ts","kind":"import-statement","original":"./node"}],"format":"esm"},"packages/common/log/src/processors/console-processor.ts":{"bytes":14122,"imports":[{"path":"chalk","kind":"import-statement","external":true},{"path":"lodash.pickby","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/debug-processor.ts":{"bytes":1070,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/processors/browser-processor.ts":{"bytes":14794,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/file-processor.ts":{"bytes":9703,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"../context"}],"format":"esm"},"packages/common/log/src/processors/index.ts":{"bytes":817,"imports":[{"path":"packages/common/log/src/processors/console-processor.ts","kind":"import-statement","original":"./console-processor"},{"path":"packages/common/log/src/processors/debug-processor.ts","kind":"import-statement","original":"./debug-processor"},{"path":"packages/common/log/src/processors/browser-processor.ts","kind":"import-statement","original":"./browser-processor"},{"path":"packages/common/log/src/processors/file-processor.ts","kind":"import-statement","original":"./file-processor"}],"format":"esm"},"packages/common/log/src/options.ts":{"bytes":7558,"imports":[{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/platform/index.ts","kind":"import-statement","original":"./platform"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"}],"format":"esm"},"packages/common/log/src/log.ts":{"bytes":10313,"imports":[{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/decorators.ts","kind":"import-statement","original":"./decorators"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"}],"format":"esm"},"packages/common/log/src/meta.ts":{"bytes":1625,"imports":[],"format":"esm"},"packages/common/log/src/experimental/ownership.ts":{"bytes":9286,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/log/src/index.ts":{"bytes":1663,"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"packages/common/log/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/common/log/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/log/src/log.ts","kind":"import-statement","original":"./log"},{"path":"packages/common/log/src/options.ts","kind":"import-statement","original":"./options"},{"path":"packages/common/log/src/processors/index.ts","kind":"import-statement","original":"./processors"},{"path":"packages/common/log/src/scope.ts","kind":"import-statement","original":"./scope"},{"path":"packages/common/log/src/meta.ts","kind":"import-statement","original":"./meta"},{"path":"packages/common/log/src/experimental/ownership.ts","kind":"import-statement","original":"./experimental/ownership"}],"format":"esm"}},"outputs":{"packages/common/log/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":49225},"packages/common/log/dist/lib/node/index.cjs":{"imports":[{"path":"lodash.omit","kind":"import-statement","external":true},{"path":"lodash.pick","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"chalk","kind":"import-statement","external":true},{"path":"lodash.pickby","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["BROWSER_PROCESSOR","CONSOLE_PROCESSOR","DEBUG_PROCESSOR","DEFAULT_FORMATTER","FILE_PROCESSOR","LogLevel","LogProcessorType","SHORT_FORMATTER","createFileProcessor","gatherLogInfoFromScope","getContextFromEntry","getCurrentOwnershipScope","levels","log","logInfo","omit","parseFilter","pick","shortLevelName","shouldLog","truncate"],"entryPoint":"packages/common/log/src/index.ts","inputs":{"packages/common/log/src/index.ts":{"bytesInOutput":64},"packages/common/log/src/config.ts":{"bytesInOutput":703},"packages/common/log/src/scope.ts":{"bytesInOutput":571},"packages/common/log/src/context.ts":{"bytesInOutput":1153},"packages/common/log/src/decorators.ts":{"bytesInOutput":3138},"packages/common/log/src/options.ts":{"bytesInOutput":1542},"packages/common/log/src/platform/node/index.ts":{"bytesInOutput":315},"packages/common/log/src/platform/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/console-processor.ts":{"bytesInOutput":2922},"packages/common/log/src/processors/index.ts":{"bytesInOutput":0},"packages/common/log/src/processors/debug-processor.ts":{"bytesInOutput":146},"packages/common/log/src/processors/browser-processor.ts":{"bytesInOutput":2762},"packages/common/log/src/processors/file-processor.ts":{"bytesInOutput":1742},"packages/common/log/src/log.ts":{"bytesInOutput":1930},"packages/common/log/src/experimental/ownership.ts":{"bytesInOutput":782}},"bytes":18814}}}
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/decorators.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAI3C,eAAO,MAAM,wBAAwB,QAC7B,UAAU,aACR,KAAK,SAAS,KAAK,SAAS,YAAY,KAAG,eAsDlD,CAAC"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/decorators.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAI3C,eAAO,MAAM,wBAAwB,QAC7B,UAAU,aACR,KAAK,SAAS,KAAK,SAAS,YAAY,KAAG,eAsClD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"console-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/console-processor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAC;AACrE,OAAO,EAAuB,KAAK,YAAY,EAAa,MAAM,YAAY,CAAC;AAU/E,eAAO,MAAM,QAAQ,UAAW,MAAM,6CAGrC,CAAC;AAgBF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;AAE1F,eAAO,MAAM,iBAAiB,EAAE,SAiC/B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAI7B,CAAC;AAKF,eAAO,MAAM,iBAAiB,EAAE,YAkC/B,CAAC"}
1
+ {"version":3,"file":"console-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/console-processor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAC;AACrE,OAAO,EAAuB,KAAK,YAAY,EAAa,MAAM,YAAY,CAAC;AAU/E,eAAO,MAAM,QAAQ,UAAW,MAAM,6CAGrC,CAAC;AAgBF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;AAE1F,eAAO,MAAM,iBAAiB,EAAE,SAgC/B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAM7B,CAAC;AAKF,eAAO,MAAM,iBAAiB,EAAE,YAkC/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"file-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/file-processor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,YAAY,CAAC;AAE/E;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;cAKpB,MAAM,GAAG,MAAM;YACjB,QAAQ,EAAE;;MAEhB,YA8BH,CAAC;AAWF,eAAO,MAAM,cAAc,EAAE,YAG3B,CAAC"}
1
+ {"version":3,"file":"file-processor.d.ts","sourceRoot":"","sources":["../../../../src/processors/file-processor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,YAAY,CAAC;AAI/E;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;cAKpB,MAAM,GAAG,MAAM;YACjB,QAAQ,EAAE;;MAEhB,YAsDH,CAAC;AAWF,eAAO,MAAM,cAAc,EAAE,YAG3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/log",
3
- "version": "0.4.10-main.c32f430",
3
+ "version": "0.4.10-main.c42bfdb",
4
4
  "description": "Logger",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,8 +24,8 @@
24
24
  "lodash.omit": "^4.5.0",
25
25
  "lodash.pick": "^4.4.0",
26
26
  "lodash.pickby": "^4.6.0",
27
- "@dxos/node-std": "0.4.10-main.c32f430",
28
- "@dxos/util": "0.4.10-main.c32f430"
27
+ "@dxos/node-std": "0.4.10-main.c42bfdb",
28
+ "@dxos/util": "0.4.10-main.c42bfdb"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@swc-node/sourcemap-support": "^0.2.0",
package/src/context.ts CHANGED
@@ -64,7 +64,7 @@ export const getContextFromEntry = (entry: LogEntry): Record<string, any> | unde
64
64
 
65
65
  if (entry.error) {
66
66
  const errorContext = (entry.error as any).context;
67
- context = Object.assign(context ?? {}, { error: entry.error.stack, ...errorContext });
67
+ context = Object.assign(context ?? {}, { error: entry.error, ...errorContext });
68
68
  }
69
69
 
70
70
  return context && Object.keys(context).length > 0 ? context : undefined;
package/src/decorators.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ import chalk from 'chalk';
5
6
  import { inspect } from 'node:util';
6
7
 
7
8
  import type { LogMethods } from './log';
@@ -14,6 +15,7 @@ export const createMethodLogDecorator =
14
15
  (arg0?: never, arg1?: never, meta?: CallMetadata): MethodDecorator =>
15
16
  (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
16
17
  const method = descriptor.value!;
18
+ const methodName = propertyKey as string;
17
19
  descriptor.value = function (this: any, ...args: any) {
18
20
  const combinedMeta = {
19
21
  ...(meta ?? {}),
@@ -28,43 +30,117 @@ export const createMethodLogDecorator =
28
30
 
29
31
  if (isThenable(result)) {
30
32
  const id = nextPromiseId++;
31
- log.info(`${propertyKey as string}(${formattedArgs}) => Promise { #${id} }`, {}, combinedMeta);
33
+ logAsyncBegin(log, methodName, formattedArgs, id, combinedMeta);
32
34
  result.then(
33
35
  (resolvedValue) => {
34
- if (resolvedValue !== undefined) {
35
- log.info(
36
- `✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms => ${inspect(
37
- resolvedValue,
38
- false,
39
- 1,
40
- true,
41
- )}`,
42
- {},
43
- combinedMeta,
44
- );
45
- } else {
46
- log.info(`✅ resolve #${id} ${(performance.now() - startTime).toFixed(0)}ms`, {}, combinedMeta);
47
- }
36
+ logAsyncResolved(log, methodName, resolvedValue, id, startTime, combinedMeta);
48
37
  },
49
38
  (err) => {
50
- log.info(`🔥 reject #${id} #${(performance.now() - startTime).toFixed(0)}ms => ${err}`, {}, combinedMeta);
39
+ logAsyncRejected(log, methodName, err, id, startTime, combinedMeta);
51
40
  },
52
41
  );
53
42
  } else {
54
- log.info(
55
- `${propertyKey as string}(${formattedArgs}) => ${inspect(result, false, 1, true)}`,
56
- {},
57
- combinedMeta,
58
- );
43
+ logSyncCall(log, methodName, formattedArgs, result, combinedMeta);
59
44
  }
60
45
 
61
46
  return result;
62
- } catch (err) {
63
- log.error(`${propertyKey as string}(${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);
47
+ } catch (err: any) {
48
+ logSyncError(log, methodName, formattedArgs, err, combinedMeta);
64
49
  throw err;
65
50
  }
66
51
  };
67
- Object.defineProperty(descriptor.value, 'name', { value: (propertyKey as string) + '$log' });
52
+ Object.defineProperty(descriptor.value, 'name', { value: methodName + '$log' });
68
53
  };
69
54
 
70
55
  const isThenable = (obj: any): obj is Promise<unknown> => obj && typeof obj.then === 'function';
56
+
57
+ const logSyncCall = (
58
+ log: LogMethods,
59
+ methodName: string,
60
+ formattedArgs: string,
61
+ result: unknown,
62
+ combinedMeta: CallMetadata,
63
+ ) => {
64
+ log.info(
65
+ `.${formatFunction(methodName)} (${formattedArgs}) ${chalk.gray('resolve')} ${inspect(result, false, 1, true)}`,
66
+ {},
67
+ combinedMeta,
68
+ );
69
+ };
70
+
71
+ const logSyncError = (
72
+ log: LogMethods,
73
+ methodName: string,
74
+ formattedArgs: string,
75
+ err: Error,
76
+ combinedMeta: CallMetadata,
77
+ ) => {
78
+ log.error(`.${formatFunction(methodName)} (${formattedArgs}) 🔥 ${err}`, {}, combinedMeta);
79
+ };
80
+
81
+ const logAsyncBegin = (
82
+ log: LogMethods,
83
+ methodName: string,
84
+ formattedArgs: string,
85
+ promiseId: number,
86
+ combinedMeta: CallMetadata,
87
+ ) => {
88
+ log.info(
89
+ `.${formatFunction(methodName)} ↴ (${formattedArgs}) ${chalk.gray('=>')} ${formatPromise(promiseId)}`,
90
+ {},
91
+ combinedMeta,
92
+ );
93
+ };
94
+
95
+ const logAsyncResolved = (
96
+ log: LogMethods,
97
+ methodName: string,
98
+ resolvedValue: unknown | undefined,
99
+ promiseId: number,
100
+ startTime: number,
101
+ combinedMeta: CallMetadata,
102
+ ) => {
103
+ if (resolvedValue !== undefined) {
104
+ log.info(
105
+ `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${inspect(
106
+ resolvedValue,
107
+ false,
108
+ 1,
109
+ true,
110
+ )}`,
111
+ {},
112
+ combinedMeta,
113
+ );
114
+ } else {
115
+ log.info(
116
+ `.${formatFunction(methodName)} ↲ ${greenCheck} ${chalk.gray('resolve')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)}`,
117
+ {},
118
+ combinedMeta,
119
+ );
120
+ }
121
+ };
122
+
123
+ const logAsyncRejected = (
124
+ log: LogMethods,
125
+ methodName: string,
126
+ err: Error,
127
+ promiseId: number,
128
+ startTime: number,
129
+ combinedMeta: CallMetadata,
130
+ ) => {
131
+ log.info(
132
+ `.${formatFunction(methodName)} ↲ 🔥 ${chalk.gray('reject')} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray('=>')} ${err}`,
133
+ {},
134
+ combinedMeta,
135
+ );
136
+ };
137
+
138
+ const greenCheck = chalk.green('✔');
139
+
140
+ const formatTimeElapsed = (startTime: number) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
141
+
142
+ const COLOR_FUNCTION = [220, 220, 170] as const;
143
+
144
+ const formatFunction = (name: string) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
145
+
146
+ const formatPromise = (id: number) => chalk.blue(`Promise#${id}`);
package/src/log.ts CHANGED
@@ -71,7 +71,7 @@ const createLog = (): LogImp => {
71
71
  log.error = (...params) => processLog(LogLevel.ERROR, ...params);
72
72
 
73
73
  // Catch only shows error message, not stacktrace.
74
- log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.stack, context, meta, error);
74
+ log.catch = (error: Error | any, context, meta) => processLog(LogLevel.ERROR, error.message, context, meta, error);
75
75
 
76
76
  // Show break.
77
77
  log.break = () => log.info('——————————————————————————————————————————————————');
@@ -58,7 +58,7 @@ const APP_BROWSER_PROCESSOR: LogProcessor = (config, entry) => {
58
58
  const filename = getRelativeFilename(entry.meta.F);
59
59
  const filepath = `${LOG_BROWSER_PREFIX.replace(/\/$/, '')}/${filename}`;
60
60
  // TODO(burdon): Line numbers not working for app link, even with colons.
61
- // https://stackoverflow.com/a/54459820/2804332
61
+ // https://stackoverflow.com/a/54459820/2804332
62
62
  link = `${filepath}#L${entry.meta.L}`;
63
63
  }
64
64
 
@@ -53,10 +53,9 @@ export type Formatter = (config: LogConfig, parts: FormatParts) => (string | und
53
53
 
54
54
  export const DEFAULT_FORMATTER: Formatter = (
55
55
  config,
56
- { path, line, timestamp, level, message, context, error, scope },
57
- ) => {
56
+ { path, line, level, message, context, error, scope },
57
+ ): string[] => {
58
58
  const column = config.options?.formatter?.column;
59
-
60
59
  const filepath = path !== undefined && line !== undefined ? chalk.grey(`${path}:${line}`) : undefined;
61
60
 
62
61
  let instance;
@@ -86,11 +85,13 @@ export const DEFAULT_FORMATTER: Formatter = (
86
85
  ];
87
86
  };
88
87
 
89
- export const SHORT_FORMATTER: Formatter = (config, { path, level, message }) => [
90
- chalk.grey(truncate(path, 16, true)), // NOTE: Breaks terminal linking.
91
- chalk[LEVEL_COLORS[level]](shortLevelName[level]),
92
- message,
93
- ];
88
+ export const SHORT_FORMATTER: Formatter = (config, { path, level, message }) => {
89
+ return [
90
+ chalk.grey(truncate(path, 16, true)), // NOTE: Breaks terminal linking.
91
+ chalk[LEVEL_COLORS[level]](shortLevelName[level]),
92
+ message,
93
+ ];
94
+ };
94
95
 
95
96
  // TODO(burdon): Config option.
96
97
  const formatter = DEFAULT_FORMATTER;
@@ -10,6 +10,8 @@ import { jsonify } from '@dxos/util';
10
10
  import { type LogFilter, LogLevel } from '../config';
11
11
  import { type LogProcessor, getContextFromEntry, shouldLog } from '../context';
12
12
 
13
+ // Amount of time to retry writing after encountering EAGAIN before giving up.
14
+ const EAGAIN_MAX_DURATION = 1000;
13
15
  /**
14
16
  * Create a file processor.
15
17
  * @param path - Path to log file to create or append to, or existing open file descriptor e.g. stdout.
@@ -52,7 +54,31 @@ export const createFileProcessor = ({
52
54
  },
53
55
  context: jsonify(getContextFromEntry(entry)),
54
56
  };
55
- appendFileSync(fd, JSON.stringify(record) + '\n');
57
+ let retryTS: number = 0;
58
+
59
+ // Retry writing if EAGAIN is encountered.
60
+ //
61
+ // Node may set stdout and stderr to non-blocking. https://github.com/nodejs/node/issues/42826
62
+ // This can cause EAGAIN errors when writing to them.
63
+ // In order to not drop logs, make log methods asynchronous, or deal with buffering/delayed writes, spin until write succeeds.
64
+
65
+ while (true) {
66
+ try {
67
+ return appendFileSync(fd, JSON.stringify(record) + '\n');
68
+ } catch (err: any) {
69
+ if (err.code !== 'EAGAIN') {
70
+ throw err;
71
+ }
72
+ if (retryTS === 0) {
73
+ retryTS = performance.now();
74
+ } else {
75
+ if (performance.now() - retryTS > EAGAIN_MAX_DURATION) {
76
+ console.log(`could not write after ${EAGAIN_MAX_DURATION}ms of EAGAIN failures, giving up`);
77
+ throw err;
78
+ }
79
+ }
80
+ }
81
+ }
56
82
  };
57
83
  };
58
84