feat: 日志优化

This commit is contained in:
zdl
2025-10-18 12:26:08 +08:00
parent 4ebb17190f
commit a7695c7365
7 changed files with 127 additions and 36 deletions

View File

@@ -9,6 +9,7 @@ import {
VStack,
Container
} from '@chakra-ui/react';
import { logger } from '../utils/logger';
class ErrorBoundary extends React.Component {
constructor(props) {
@@ -28,14 +29,20 @@ class ErrorBoundary extends React.Component {
componentDidCatch(error, errorInfo) {
// 开发环境:打印错误到控制台,但不显示错误边界
if (process.env.NODE_ENV === 'development') {
console.error('🔴 ErrorBoundary 捕获到错误(开发模式,不拦截):');
console.error('错误:', error);
console.error('错误信息:', errorInfo);
logger.error('ErrorBoundary', 'componentDidCatch', error, {
componentStack: errorInfo.componentStack,
developmentMode: true
});
// 不更新 state让错误继续抛出
return;
}
// 生产环境:保存错误信息到 state
logger.error('ErrorBoundary', 'componentDidCatch', error, {
componentStack: errorInfo.componentStack,
productionMode: true
});
this.setState({
error: error,
errorInfo: errorInfo