重整多余的UI组件和未定功能的逻辑链路的修正
This commit is contained in:
@@ -9,6 +9,12 @@ import '../../logging/i_logger_service.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class SentryLoggerImpl implements ILoggerService {
|
||||
// 正式包默认关闭上报,重新启用时传入 --dart-define=ENABLE_SENTRY=true。
|
||||
static const bool _sentryEnabled = bool.fromEnvironment(
|
||||
'ENABLE_SENTRY',
|
||||
defaultValue: !kReleaseMode && !EnvConfig.isProduction,
|
||||
);
|
||||
|
||||
File? _localLogFile;
|
||||
//调试模式开关
|
||||
bool _isDebugModeEnabled = false;
|
||||
@@ -16,20 +22,17 @@ class SentryLoggerImpl implements ILoggerService {
|
||||
@override
|
||||
Future<void> init() async {
|
||||
_isDebugModeEnabled = false;
|
||||
await SentryFlutter.init((options) {
|
||||
options.dsn = EnvConfig.sentryDsn;
|
||||
options.environment = EnvConfig.environment;
|
||||
// 生产环境只采样 20% 的性能数据,测试环境全开
|
||||
options.tracesSampleRate = EnvConfig.isProduction ? 0.2 : 1.0;
|
||||
if (_sentryEnabled) {
|
||||
await SentryFlutter.init((options) {
|
||||
options.dsn = EnvConfig.sentryDsn;
|
||||
options.environment = EnvConfig.environment;
|
||||
// 生产环境只采样 20% 的性能数据,测试环境全开
|
||||
options.tracesSampleRate = EnvConfig.isProduction ? 0.2 : 1.0;
|
||||
options.debug = _isDebugModeEnabled;
|
||||
});
|
||||
|
||||
// 动态设置 Sentry 接收的日志级别
|
||||
// 如果开启调试模式,接收 DEBUG;否则生产环境只接收 INFO 以上
|
||||
|
||||
options.debug = _isDebugModeEnabled; // 开启 SDK 内部调试
|
||||
|
||||
});
|
||||
|
||||
await _collectDeviceInfo();
|
||||
await _collectDeviceInfo();
|
||||
}
|
||||
await _prepareLocalFile();
|
||||
}
|
||||
|
||||
@@ -67,7 +70,9 @@ class SentryLoggerImpl implements ILoggerService {
|
||||
|
||||
@override
|
||||
void captureException(dynamic exception, {dynamic stackTrace}) {
|
||||
Sentry.captureException(exception, stackTrace: stackTrace);
|
||||
if (_sentryEnabled) {
|
||||
Sentry.captureException(exception, stackTrace: stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -80,13 +85,13 @@ class SentryLoggerImpl implements ILoggerService {
|
||||
final level = isWarning ? 'WARNING' : 'INFO';
|
||||
final logEntry = "[$timestamp] [$level] $message ${data ?? ''}\n";
|
||||
|
||||
// 1.发送日志到 Sentry
|
||||
Sentry.captureMessage(
|
||||
message,
|
||||
level: isWarning ? SentryLevel.warning : SentryLevel.info,
|
||||
);
|
||||
if (_sentryEnabled) {
|
||||
Sentry.captureMessage(
|
||||
message,
|
||||
level: isWarning ? SentryLevel.warning : SentryLevel.info,
|
||||
);
|
||||
}
|
||||
|
||||
// 2.写入本地文件
|
||||
_writeToLocalFile(logEntry);
|
||||
|
||||
if (kDebugMode) {
|
||||
@@ -127,10 +132,10 @@ class SentryLoggerImpl implements ILoggerService {
|
||||
_isDebugModeEnabled;
|
||||
|
||||
if (shouldProcess) {
|
||||
// 写入本地文件
|
||||
_writeToLocalFile(logEntry);
|
||||
}
|
||||
|
||||
// 上报 Sentry
|
||||
if (_sentryEnabled && shouldProcess) {
|
||||
SentryLevel sentryLevel;
|
||||
switch (level) {
|
||||
case 'DEBUG': sentryLevel = SentryLevel.debug; break;
|
||||
@@ -164,11 +169,15 @@ class SentryLoggerImpl implements ILoggerService {
|
||||
|
||||
@override
|
||||
void addBreadcrumb(String message, {String? category}) {
|
||||
Sentry.addBreadcrumb(Breadcrumb(message: message, category: category));
|
||||
if (_sentryEnabled) {
|
||||
Sentry.addBreadcrumb(Breadcrumb(message: message, category: category));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void setUser(String userId) {
|
||||
Sentry.configureScope((scope) => scope.setUser(SentryUser(id: userId)));
|
||||
if (_sentryEnabled) {
|
||||
Sentry.configureScope((scope) => scope.setUser(SentryUser(id: userId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user