/** Additional options for log methods */ export type LogOptions = { /** Do not append line-feed to message (`process.stdout.write` instead of `console.log`) */ noLineBreak?: boolean; /** Do not indent lines even if logged while a spinner is active */ noIndent?: boolean; }; /** Additional options for {@link Logger.debug} method */ export type DebugLogOptions = LogOptions & { /** Print debug message even if verbose flag is not set */ force?: boolean; }; /** * Rich logging implementation for Code PushUp CLI, plugins, etc. * * Use {@link logger} singleton. */ export declare class Logger { #private; /** * Logs an error to the console (red). * * Automatically adapts to logger state if called within {@link task}, {@link group}, etc. * * @example * logger.error('Config file is invalid'); * * @param message Error text * @param options Additional options */ error(message: string, options?: LogOptions): void; /** * Logs a warning to the console (yellow). * * Automatically adapts to logger state if called within {@link task}, {@link group}, etc. * * @example * logger.warn('Skipping invalid audits'); * * @param message Warning text * @param options Additional options */ warn(message: string, options?: LogOptions): void; /** * Logs an informational message to the console (unstyled). * * Automatically adapts to logger state if called within {@link task}, {@link group}, etc. * * @example * logger.info('Code PushUp CLI v0.80.2'); * * @param message Info text * @param options Additional options */ info(message: string, options?: LogOptions): void; /** * Logs a debug message to the console (gray), but **only if verbose** flag is set (see {@link isVerbose}). * * Automatically adapts to logger state if called within {@link task}, {@link group}, etc. * * @example * logger.debug('Running ESLint version 9.16.0'); * * @param message Debug text * @param options Additional options */ debug(message: string, options?: DebugLogOptions): void; /** * Print a blank line to the console, used to separate logs for readability. * * Automatically adapts to logger state if called within {@link task}, {@link group}, etc. * * @example * logger.newline(); */ newline(): void; /** * Is verbose flag set? * * Verbosity is configured by {@link setVerbose} call or `CP_VERBOSE` environment variable. * * @example * if (logger.isVerbose()) { * // ... * } */ isVerbose(): boolean; /** * Sets verbose flag for this logger. * * Also sets the `CP_VERBOSE` environment variable. * This means any future {@link Logger} instantiations (including child processes) will use the same verbosity level. * * @example * logger.setVerbose(process.argv.includes('--verbose')); * * @param isVerbose Verbosity level */ setVerbose(isVerbose: boolean): void; /** * Animates asynchronous work using a spinner. * * Basic logs are supported within the worker function, they will be printed with indentation once the spinner completes. * * In CI environments, the spinner animation is disabled, and inner logs are printed immediately. * * Spinners may be nested within a {@link group} call, in which case line symbols are used instead of dots, as well the group's color. * * The task's duration is included in the logged output as a suffix. * * Listens for `SIGINT` event in order to cancel and restore spinner before exiting. * * Concurrent or nested spinners are not supported, nor can groups be nested in spinners. * * @example * await logger.task('Uploading report to portal', async () => { * // ... * return 'Uploaded report to portal'; * }); * * @param title Display text used as pending message. * @param worker Asynchronous implementation. Returned promise determines spinner status and final message. Support for inner logs has some limitations (described above). */ task(title: string, worker: () => Promise): Promise; /** * Similar to {@link task}, but spinner texts are formatted as shell commands. * * A `$`-prefix is added. Its color indicates the status (blue=pending, green=success, red=failure). * * If the command's working directory isn't `process.cwd()`, a relative path is prefixed to the output. * * @example * await logger.command('npx eslint . --format=json', async () => { * // ... * }); * * @param bin Command string with arguments. * @param worker Asynchronous execution of the command (not implemented by the logger). * @param options Custom CWD path where the command is executed (default is `process.cwd()`). * @template T Type of resolved worker value. */ command(bin: string, worker: () => Promise, options?: { cwd?: string; }): Promise; /** * Groups many logs into a visually distinct section. * * Groups alternate prefix colors between cyan and magenta. * * The group's total duration is included in the logged output. * * Nested groups are not supported. * * @example * const eslintResult = await logger.group('Running plugin "ESLint"', async () => { * logger.debug('ESLint version is 9.16.0'); * const result = await logger.command('npx eslint . --format=json', () => { * // ... * }) * logger.info('Found 42 lint errors.'); * return { * message: 'Completed "ESLint" plugin execution', * result, * }; * }); * * @param title Display title for the group. * @param worker Asynchronous implementation. Returned promise determines group status and ending message. Inner logs are attached to the group. */ group(title: string, worker: () => Promise): Promise; } /** * Shared {@link Logger} instance. * * @example * import { logger } from '@code-pushup/utils'; * * logger.info('Made with ❤️ by Code PushUp'); */ export declare const logger: Logger;