优化掉核心功能中print打印影响性能的代码用日志对象代替打印
This commit is contained in:
@@ -15,6 +15,8 @@ import '../../../domain/entities/device_location_entity.dart';
|
||||
class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
final Dio dio;
|
||||
final UserStorage _userStorage; // 🔥 新增字段
|
||||
final ILoggerService _logger = GetIt.I<ILoggerService>();
|
||||
|
||||
|
||||
// 🔥 修改构造函数,注入 UserStorage
|
||||
DeviceHttpDatasourceImpl(this.dio, this._userStorage);
|
||||
@@ -22,7 +24,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
// 🔥 辅助方法:获取 Token
|
||||
Future<String?> _getToken() async {
|
||||
final user = await _userStorage.getUser();
|
||||
debugPrint('用户信息: $user');
|
||||
_logger.logWithLevel('用户信息: $user', level: 'INFO');
|
||||
return user?.token;
|
||||
}
|
||||
|
||||
@@ -94,7 +96,8 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
|
||||
Future<int> switchDevice(String platform, String deviceId) async {
|
||||
final logger = GetIt.I<ILoggerService>() as SentryLoggerImpl;
|
||||
final token = await _getToken();
|
||||
print('用户点击switchDevice方法开始触发: $token');
|
||||
// print('用户点击switchDevice方法开始触发: $token');
|
||||
_logger.logWithLevel('用户点击switchDevice方法开始触发', level: 'DEBUG');
|
||||
logger.logWithLevel('用户点击switchDevice方法开始触发', level: 'DEBUG');
|
||||
logger.logWithLevel('用户点击switchDevice方法API 请求开始', level: 'INFO', data: {'url': 'https://serviceri.satabot.com/iot/device/switchDevice'});
|
||||
var response = await dio.post(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:maibu_satabot_v2/common.dart';
|
||||
|
||||
import '../../../../../core/logging/i_logger_service.dart';
|
||||
import '../../../../../core/storage/user_storage.dart';
|
||||
import '../../models/device_add_path_point_model.dart';
|
||||
import '../path_http_datasource.dart';
|
||||
@@ -10,21 +12,23 @@ import 'package:logger/logger.dart';
|
||||
|
||||
class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
final UserStorage _userStorage;
|
||||
final ILoggerService _logger = GetIt.I<ILoggerService>();
|
||||
|
||||
PathHttpDatasourceImpl(this._userStorage);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Future<List<DeviceAddPathPointModel>> generatePathRaw({required Map<String, dynamic> body}) async {
|
||||
try {
|
||||
// 1. 先打印基础信息
|
||||
print('=== 最终发送给后端的请求体 ===');
|
||||
print('请求体类型:${body.runtimeType}');
|
||||
_logger.logWithLevel( '请求体类型:${body.runtimeType}',level: 'INFO');
|
||||
|
||||
// 2. 格式化打印JSON(带缩进,清晰展示嵌套结构)
|
||||
final jsonString = const JsonEncoder.withIndent(' ').convert(body);
|
||||
|
||||
final _jsonString = jsonEncode(body);
|
||||
print('完整JSON请求体:\n$jsonString');
|
||||
// print('完整JSON请求体:\n$jsonString');
|
||||
_logger.logWithLevel( '请求体:$_jsonString',level: 'INFO');
|
||||
|
||||
// 3. 可选:单独打印holes的JSON(重点关注)
|
||||
//final holesJson = body['holes'] as List;
|
||||
@@ -38,9 +42,11 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
//}
|
||||
} catch (e) {
|
||||
// 防止JSON序列化失败导致崩溃
|
||||
print('打印请求体失败:$e');
|
||||
//print('打印请求体失败:$e');
|
||||
_logger.logWithLevel( '打印请求体失败:$e',level: 'ERROR');
|
||||
// 降级打印原始body(虽然格式乱,但能看基础数据)
|
||||
print('原始body数据:$body');
|
||||
// print('原始body数据:$body');
|
||||
_logger.logWithLevel( '原始body数据:$body',level: 'ERROR');
|
||||
}
|
||||
|
||||
final token = (await _userStorage.getUser())?.token;
|
||||
@@ -58,7 +64,8 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (decoded['success'] == true) {
|
||||
final pathJson = decoded['data']?['path'];
|
||||
print('路径数据: $pathJson'); // 调试输出路径数据
|
||||
// print('路径数据: $pathJson'); // 调试输出路径数据
|
||||
_logger.logWithLevel( '路径数据: $pathJson',level: 'INFO');
|
||||
if (pathJson == null) {
|
||||
throw Exception('API returned null for "path"');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user