(context: string, error: any)
| 29 | |
| 30 | // 记录错误但不泄露敏感信息 |
| 31 | static logError(context: string, error: any): void { |
| 32 | const safeMessage = this.sanitizeErrorMessage(error); |
| 33 | |
| 34 | if (this.isDevelopment) { |
| 35 | console.error(`${context}: ${safeMessage}`); |
| 36 | console.error('Stack:', error.stack); |
| 37 | } else { |
| 38 | // 生产环境:只记录安全的信息 |
| 39 | console.error(`${context}: ${safeMessage}`); |
| 40 | // 可以将完整错误发送到内部日志系统 |
| 41 | this.sendToInternalLogging(context, error); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | private static sendToInternalLogging(context: string, error: any): void { |
| 46 | // 实现内部日志记录,不对外暴露 |
no test coverage detected