feat:更新网络工具类返回的异常错误
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
@@ -9,22 +10,25 @@ late Logger logger;
|
||||
|
||||
// 初始化日志
|
||||
Future<void> initLogger() async {
|
||||
final directory = await getExternalStorageDirectory();
|
||||
final logFile = File('${directory?.path}/logs/app.log');
|
||||
if (kIsWeb) {
|
||||
logger = Logger(
|
||||
printer: SimplePrinter(printTime: true),
|
||||
output: ConsoleOutput(),
|
||||
);
|
||||
} else {
|
||||
final directory = await getExternalStorageDirectory();
|
||||
final logFile = File('${directory?.path}/logs/app.log');
|
||||
|
||||
// 确保文件存在(会自动创建)
|
||||
await logFile.create(recursive: true);
|
||||
// 确保文件存在(会自动创建)
|
||||
await logFile.create(recursive: true);
|
||||
|
||||
logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: SimplePrinter(printTime: true),
|
||||
output: MultiOutput([
|
||||
ConsoleOutput(),
|
||||
FileOutput(
|
||||
file: logFile,
|
||||
overrideExisting: true,
|
||||
encoding: utf8
|
||||
),
|
||||
]),
|
||||
);
|
||||
logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: SimplePrinter(printTime: true),
|
||||
output: MultiOutput([
|
||||
ConsoleOutput(),
|
||||
FileOutput(file: logFile, overrideExisting: true, encoding: utf8),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user