UNPKG

spruthub-cli

Version:

CLI tool for managing Spruthub smart home devices

48 lines 1.41 kB
import chalk from 'chalk'; class Logger { level; constructor() { this.level = process.env.VERBOSE ? 'debug' : 'info'; } info(message, ...args) { if (this.shouldLog('info')) { console.log(chalk.blue('[INFO]'), message, ...args); } } warn(message, ...args) { if (this.shouldLog('warn')) { console.warn(chalk.yellow('[WARN]'), message, ...args); } } error(message, ...args) { if (this.shouldLog('error')) { console.error(chalk.red('[ERROR]'), message, ...args); } } debug(message, ...args) { if (this.shouldLog('debug')) { console.log(chalk.gray('[DEBUG]'), message, ...args); } } success(message, ...args) { console.log(chalk.green('✓'), message, ...args); } shouldLog(level) { const levels = ['error', 'warn', 'info', 'debug']; const currentLevelIndex = levels.indexOf(this.level); const targetLevelIndex = levels.indexOf(level); return targetLevelIndex <= currentLevelIndex; } // Pino-compatible interface for spruthub-client child() { return this; } fatal(message, ...args) { this.error(message, ...args); } trace(message, ...args) { this.debug(message, ...args); } } export default new Logger(); //# sourceMappingURL=logger.js.map