UNPKG

@callstack/reassure-logger

Version:
59 lines (56 loc) 1.6 kB
import readline from 'readline'; import chalk from 'chalk'; import { colors } from './colors'; const defaultConfig = { verbose: false, silent: false }; let config = { ...defaultConfig }; const colorError = chalk.hex(colors.error); const colorWarn = chalk.hex(colors.warn); const colorVerbose = chalk.hex(colors.verbose); export function configure(options) { config = { ...config, ...options }; } // Jest is wrapping console.* calls, so we need to get the raw console object const rawConsole = require('console'); export function error(message, ...args) { rawConsole.error(colorError(message, ...args)); } export function warn(message, ...args) { if (config.silent) return; rawConsole.warn(colorWarn(message, ...args)); } export function log(message, ...args) { if (config.silent) return; rawConsole.log(message, ...args); } export function verbose(message, ...args) { if (!config.verbose || config.silent) return; rawConsole.log(colorVerbose(message, ...args)); } export function newLine() { if (config.silent) return; rawConsole.log(); } export function color(color, ...args) { if (config.silent) return; return rawConsole.log(chalk.hex(colors[color])(...args)); } /** Log message that indicates progress of operation, does not output the trailing newline. */ export function progress(message) { process.stdout.write(message); } /** * Clears current lint. To be used in conjunction with `progress`. */ export function clearLine() { readline.clearLine(process.stdout, 0); readline.cursorTo(process.stdout, 0); } //# sourceMappingURL=logger.js.map