feat: 完成DPML协议体系0~1阶段开发 - 三层协议架构100%实现,智能路径检测系统,@package://与package.json完美集成,用户项目集成方案,CLI框架完整实现,132/137核心测试通过(96.3%通过率)

This commit is contained in:
sean
2025-05-31 13:03:26 +08:00
parent 3338b7c21f
commit be285f55b8
89 changed files with 6071 additions and 467 deletions

90
src/lib/utils/logger.js Normal file
View File

@ -0,0 +1,90 @@
const chalk = require('chalk');
/**
* 日志工具
* 提供彩色和格式化的日志输出
*/
class Logger {
constructor(options = {}) {
this.silent = options.silent || false;
this.prefix = options.prefix || 'PromptX';
}
/**
* 信息日志
*/
info(message, ...args) {
if (this.silent) return;
console.log(chalk.blue(''), message, ...args);
}
/**
* 成功日志
*/
success(message, ...args) {
if (this.silent) return;
console.log(chalk.green('✅'), message, ...args);
}
/**
* 警告日志
*/
warn(message, ...args) {
if (this.silent) return;
console.log(chalk.yellow('⚠️'), chalk.yellow(message), ...args);
}
/**
* 错误日志
*/
error(message, ...args) {
if (this.silent) return;
console.error(chalk.red('❌'), chalk.red(message), ...args);
}
/**
* 调试日志
*/
debug(message, ...args) {
if (this.silent || !process.env.DEBUG) return;
console.log(chalk.gray('🐛'), chalk.gray(message), ...args);
}
/**
* 步骤日志(用于显示进度)
*/
step(message, ...args) {
if (this.silent) return;
console.log(chalk.cyan('▶️'), message, ...args);
}
/**
* 直接输出(不带前缀)
*/
log(message, ...args) {
if (this.silent) return;
console.log(message, ...args);
}
/**
* 空行
*/
newLine() {
if (this.silent) return;
console.log('');
}
/**
* 分隔线
*/
separator(char = '=', length = 80) {
if (this.silent) return;
console.log(chalk.gray(char.repeat(length)));
}
}
// 导出默认实例
const logger = new Logger();
module.exports = logger;
module.exports.Logger = Logger;