repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { consola } from 'consola'; |
| #2 | import { colors } from 'consola/utils'; |
| #3 | |
| #4 | /** |
| #5 | * 统一日志工具类 |
| #6 | * 提供结构化的日志功能和美化的输出 |
| #7 | */ |
| #8 | export const Logger = { |
| #9 | /** |
| #10 | * 调试日志 |
| #11 | * @param message 调试信息 |
| #12 | * @param data 调试数据 |
| #13 | */ |
| #14 | debug(message: string, data?: any) { |
| #15 | if (data !== undefined) { |
| #16 | consola.debug(colors.magenta('🐛'), message, data); |
| #17 | } else { |
| #18 | consola.debug(colors.magenta('🐛'), message); |
| #19 | } |
| #20 | }, |
| #21 | |
| #22 | /** |
| #23 | * 错误日志 |
| #24 | * @param message 错误信息 |
| #25 | * @param error 错误对象或详情 |
| #26 | */ |
| #27 | error(message: string, error?: any) { |
| #28 | if (error) { |
| #29 | if (error instanceof Error) { |
| #30 | consola.error(colors.red('✗'), message, colors.gray(error.message)); |
| #31 | } else { |
| #32 | consola.error(colors.red('✗'), message, colors.gray(String(error))); |
| #33 | } |
| #34 | } else { |
| #35 | consola.error(colors.red('✗'), message); |
| #36 | } |
| #37 | }, |
| #38 | |
| #39 | /** |
| #40 | * 文件操作日志 |
| #41 | * @param operation 操作类型 |
| #42 | * @param filePath 文件路径 |
| #43 | * @param status 操作状态 |
| #44 | */ |
| #45 | file( |
| #46 | operation: 'read' | 'write' | 'delete' | 'create', |
| #47 | filePath: string, |
| #48 | status: 'start' | 'success' | 'error' = 'success', |
| #49 | ) { |
| #50 | const icons = { |
| #51 | create: '📄', |
| #52 | delete: '🗑️', |
| #53 | read: '📖', |
| #54 | write: '📝', |
| #55 | }; |
| #56 | |
| #57 | const statusColors = { |
| #58 | error: colors.red, |
| #59 | start: colors.blue, |
| #60 | success: colors.green, |
| #61 | }; |
| #62 | |
| #63 | const message = `${icons[operation]} ${operation.charAt(0).toUpperCase() + operation.slice(1)} file`; |
| #64 | const coloredPath = colors.gray(filePath); |
| #65 | |
| #66 | switch (status) { |
| #67 | case 'start': { |
| #68 | consola.start(statusColors[status](message), coloredPath); |
| #69 | break; |
| #70 | } |
| #71 | case 'success': { |
| #72 | consola.success(statusColors[status](message), coloredPath); |
| #73 | break; |
| #74 | } |
| #75 | case 'error': { |
| #76 | consola.error(statusColors[status](message), coloredPath); |
| #77 | break; |
| #78 | } |
| #79 | } |
| #80 | }, |
| #81 | |
| #82 | /** |
| #83 | * 信息日志 |
| #84 | * @param message 信息内容 |
| #85 | * @param data 相关数据 |
| #86 | */ |
| #87 | info(message: string, data?: any) { |
| #88 | if (data !== undefined) { |
| #89 | consola.info(colors.cyan('ℹ'), message, colors.gray(String(data))); |
| #90 | } else { |
| #91 | consola.info(colors.cyan('ℹ'), message); |
| #92 | } |
| #93 | }, |
| #94 | |
| #95 | /** |
| #96 | * 进度日志 |
| #97 | * @param current 当前进度 |
| #98 | * @param total 总数 |
| #99 | * @param action 操作名称 |
| #100 | */ |
| #101 | progress(current: number, total: number, action: string) { |
| #102 | const percentage = Math.round((current / total) * 100); |
| #103 | const progressBar = |
| #104 | '█'.repeat(Math.floor(percentage / 5)) + '░'.repeat(20 - Math.floor(percentage / 5)); |
| #105 | consola.info( |
| #106 | colors.cyan(`[${progressBar}]`), |
| #107 | colors.yellow(`${percentage}%`), |
| #108 | colors.gray(`(${current}/${total})`), |
| #109 | action, |
| #110 | ); |
| #111 | }, |
| #112 | |
| #113 | /** |
| #114 | * 打印分隔线 |
| #115 | * @param title 分隔线标题 |
| #116 | * @param char 分隔符字符 |
| #117 | */ |
| #118 | split(title: string, char: string = '=') { |
| #119 | consola.log(''); |
| #120 | const line = char.repeat(Math.max(0, 50 - title.length)); |
| #121 | consola.log(colors.gray(`${line} ${title} ${line}`)); |
| #122 | }, |
| #123 | |
| #124 | /** |
| #125 | * 开始操作日志 |
| #126 | * @param action 操作名称 |
| #127 | * @param target 目标对象 |
| #128 | * @param details 详细信息 |
| #129 | */ |
| #130 | start(action: string, target?: string, details?: string) { |
| #131 | if (target && details) { |
| #132 | consola.start(colors.blue('⚡'), action, colors.yellow(target), colors.gray(`(${details})`)); |
| #133 | } else if (target) { |
| #134 | consola.start(colors.blue('⚡'), action, colors.yellow(target)); |
| #135 | } else { |
| #136 | consola.start(colors.blue('⚡'), action); |
| #137 | } |
| #138 | }, |
| #139 | |
| #140 | /** |
| #141 | * 统计信息日志 |
| #142 | * @param stats 统计数据 |
| #143 | */ |
| #144 | stats(stats: Record<string, number | string>) { |
| #145 | consola.log(''); |
| #146 | consola.log(colors.cyan('📊 统计信息:')); |
| #147 | Object.entries(stats).forEach(([key, value]) => { |
| #148 | const coloredValue = |
| #149 | typeof value === 'number' ? colors.yellow(String(value)) : colors.gray(String(value)); |
| #150 | consola.log(` ${colors.gray('•')} ${key}: ${coloredValue}`); |
| #151 | }); |
| #152 | }, |
| #153 | |
| #154 | /** |
| #155 | * 成功操作日志 |
| #156 | * @param action 操作名称 |
| #157 | * @param target 目标对象 |
| #158 | * @param details 详细信息 |
| #159 | */ |
| #160 | success(action: string, target?: string, details?: string) { |
| #161 | if (target && details) { |
| #162 | consola.success( |
| #163 | colors.green('✓'), |
| #164 | action, |
| #165 | colors.yellow(target), |
| #166 | colors.gray(`(${details})`), |
| #167 | ); |
| #168 | } else if (target) { |
| #169 | consola.success(colors.green('✓'), action, colors.yellow(target)); |
| #170 | } else { |
| #171 | consola.success(colors.green('✓'), action); |
| #172 | } |
| #173 | }, |
| #174 | |
| #175 | /** |
| #176 | * 翻译过程日志 |
| #177 | * @param id Agent ID |
| #178 | * @param fromLang 源语言 |
| #179 | * @param toLang 目标语言 |
| #180 | * @param status 状态 |
| #181 | */ |
| #182 | translate( |
| #183 | id: string, |
| #184 | fromLang: string, |
| #185 | toLang: string, |
| #186 | status: 'start' | 'success' | 'skip' | 'error' = 'success', |
| #187 | ) { |
| #188 | const statusIcons = { |
| #189 | error: '❌', |
| #190 | skip: '⏭️', |
| #191 | start: '🔄', |
| #192 | success: '✅', |
| #193 | }; |
| #194 | |
| #195 | const message = `${statusIcons[status]} ${colors.yellow(id)} ${colors.gray('翻译')} ${colors.cyan(`[${fromLang}]`)} → ${colors.cyan(`[${toLang}]`)}`; |
| #196 | |
| #197 | switch (status) { |
| #198 | case 'start': { |
| #199 | consola.start(message); |
| #200 | break; |
| #201 | } |
| #202 | case 'success': { |
| #203 | consola.success(message); |
| #204 | break; |
| #205 | } |
| #206 | case 'skip': { |
| #207 | consola.info(message); |
| #208 | break; |
| #209 | } |
| #210 | case 'error': { |
| #211 | consola.error(message); |
| #212 | break; |
| #213 | } |
| #214 | } |
| #215 | }, |
| #216 | |
| #217 | /** |
| #218 | * 警告日志 |
| #219 | * @param message 警告信息 |
| #220 | * @param reason 警告原因 |
| #221 | */ |
| #222 | warn(message: string, reason?: string) { |
| #223 | if (reason) { |
| #224 | consola.warn(colors.yellow('⚠'), message, colors.gray(`- ${reason}`)); |
| #225 | } else { |
| #226 | consola.warn(colors.yellow('⚠'), message); |
| #227 | } |
| #228 | }, |
| #229 | }; |
| #230 | |
| #231 | /** |
| #232 | * 导出便捷的日志函数 |
| #233 | */ |
| #234 | export const { split, start, success, info, warn, error, debug, file, stats, translate, progress } = |
| #235 | Logger; |
| #236 | |
| #237 | |
| #238 |