import chalk from 'chalk';
/**
 * 日志工具类
 */
export class Logger {
    config;
    constructor(config = {}) {
        this.config = {
            level: 'info',
            prefix: 'Z-Tools',
            timestamp: true,
            ...config,
        };
    }
    formatMessage(level, message) {
        const timestamp = this.config.timestamp ? new Date().toISOString() : '';
        const prefix = this.config.prefix ? `[${this.config.prefix}]` : '';
        return [timestamp, prefix, message].filter(Boolean).join(' ');
    }
    shouldLog(level) {
        const levels = ['debug', 'info', 'warn', 'error'];
        const currentLevelIndex = levels.indexOf(this.config.level);
        const messageLevelIndex = levels.indexOf(level);
        return messageLevelIndex >= currentLevelIndex;
    }
    debug(message) {
        if (this.shouldLog('debug')) {
            console.log(chalk.gray(this.formatMessage('debug', message)));
        }
    }
    info(message) {
        if (this.shouldLog('info')) {
            console.log(chalk.blue(this.formatMessage('info', message)));
        }
    }
    success(message) {
        if (this.shouldLog('info')) {
            console.log(chalk.green(this.formatMessage('info', message)));
        }
    }
    warn(message) {
        if (this.shouldLog('warn')) {
            console.warn(chalk.yellow(this.formatMessage('warn', message)));
        }
    }
    error(message) {
        if (this.shouldLog('error')) {
            console.error(chalk.red(this.formatMessage('error', message)));
        }
    }
}
// 默认日志实例
export const logger = new Logger();
//# sourceMappingURL=logger.js.map