@curvenote/cli
Version:
CLI Client library for Curvenote
55 lines • 2.88 kB
TypeScript
import type { ServerInfo } from 'myst-cli';
import type { Logger } from 'myst-cli-utils';
import { LogLevel } from 'myst-cli-utils';
type SendJsonFn = ServerInfo['contentServer']['sendJson'];
/**
* Builds a composite {@link Logger} that fans out each log call to both a
* chalk-styled terminal logger and, optionally, a websocket logger.
*
* For every level (`debug`, `info`, `warn`, `error`), the returned logger:
* - Short-circuits when the message is below the configured {@link LogLevel}.
* - Delegates first to {@link chalkLogger} for terminal output.
* - Delegates to {@link websocketLogger} when `sendJson` is provided, otherwise
* falls back to {@link silentLogger} so websocket calls are no-ops.
*
* @param level - Minimum {@link LogLevel} to emit; lower-severity messages are
* discarded before either underlying logger is invoked.
* @param cwd - Optional working directory whose prefix is stripped from string
* arguments so logged paths are displayed relative to it.
* @param sendJson - Optional transport for forwarding log envelopes over a
* websocket (typically `AppServer.contentServer.sendJson`).
* When omitted, only terminal logging is active.
* @returns A {@link Logger} that multiplexes log output to the terminal and
* (when configured) to websocket clients.
*/
export declare function compositeLoggerFactory(levels?: {
websocket: LogLevel;
terminal: LogLevel;
}, cwd?: string, sendJson?: SendJsonFn): Logger;
/**
* Creates a {@link Logger} that forwards log messages over a websocket by
* emitting `LOG` envelopes through the provided `sendJson` function.
*
* Each log method:
* - Respects the configured {@link LogLevel}, dropping messages below it.
* - Normalizes arguments with {@link replaceCwd} so absolute paths are shown
* relative to `cwd`.
* - Applies a chalk style per level (`dim` for debug, `reset` for info,
* `yellow` for warn, `red` for error) before sending the serialized message.
*
* The emitted payload shape is:
* `{ type: 'LOG', level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR', message: string }`.
*
* @param sendJson - Transport function used to deliver JSON log envelopes to
* connected websocket clients (typically
* `AppServer.contentServer.sendJson`).
* @param level - Minimum {@link LogLevel} to forward; lower-severity messages
* are ignored.
* @param cwd - Optional working directory whose prefix is stripped from string
* arguments before formatting.
* @returns A {@link Logger} whose `debug`, `info`, `warn`, and `error` methods
* publish styled log messages over the websocket.
*/
export declare function websocketLogger(sendJson: SendJsonFn, level: LogLevel, cwd?: string): Logger;
export {};
//# sourceMappingURL=logger.d.ts.map