* 调试日志函数,只在开发模式下输出 * @param type 日志类型 * @param message 日志消息 * @param ...args 日志参数
(type: string, message: string, ...args: any[])
| 17 | * @param ...args 日志参数 |
| 18 | */ |
| 19 | function debugLog(type: string, message: string, ...args: any[]): void { |
| 20 | if (!isDev) return; |
| 21 | |
| 22 | // 为不同类型设置不同颜色 |
| 23 | const colors: {[key: string]: string} = { |
| 24 | 'Twitter': 'color: #1DA1F2; font-weight: bold', |
| 25 | 'GitHub': 'color: #6e5494; font-weight: bold', |
| 26 | 'StackOverflow': 'color: #f48024; font-weight: bold', |
| 27 | 'Reddit': 'color: #FF4500; font-weight: bold', |
| 28 | 'Medium': 'color: #00ab6c; font-weight: bold', |
| 29 | 'YouTube': 'color: #FF0000; font-weight: bold', // 添加YouTube的颜色 |
| 30 | 'Compat': 'color: #0366d6; font-weight: bold', |
| 31 | 'Skip': 'color: #d73a49; font-weight: bold', |
| 32 | 'Content': 'color: #28a745; font-weight: bold', |
| 33 | 'Default': 'color: #24292e; font-weight: bold' |
| 34 | }; |
| 35 | |
| 36 | const color = colors[type] || colors['Default']; |
| 37 | const prefix = `%c[FluentRead][${type}]`; |
| 38 | |
| 39 | // 根据日志类型决定是否需要分组 |
| 40 | if (['Content', 'Skip', 'YouTube', 'GitHub', 'Twitter'].includes(type) && args.length > 0) { |
| 41 | // 使用折叠分组,减少日志视觉干扰 |
| 42 | console.groupCollapsed(prefix, color, message); |
| 43 | args.forEach((arg, index) => { |
| 44 | if (typeof arg === 'string') { |
| 45 | console.log(`参数${index + 1}:`, arg.substring(0, 100) + (arg.length > 100 ? '...' : '')); |
| 46 | } else { |
| 47 | console.log(`参数${index + 1}:`, arg); |
| 48 | } |
| 49 | }); |
| 50 | console.groupEnd(); |
| 51 | } else { |
| 52 | // 常规日志输出 |
| 53 | console.log(prefix, color, message, ...args); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | interface ReplaceCompatFn { |
| 58 | [domain: string]: ReplaceFunction; |
no outgoing calls
no test coverage detected