Parcourir la source

日志初始化优化,只有android版有文件日志

gjh il y a 1 semaine
Parent
commit
0fe8f92461
1 fichiers modifiés avec 13 ajouts et 8 suppressions
  1. 13 8
      lib/funcs.dart

+ 13 - 8
lib/funcs.dart

@@ -40,15 +40,20 @@ late Logger logger;
40 40
 ///初始化日志
41 41
 Future<dynamic> initLog() async {
42 42
   LogOutput? output;
43
-  Directory? dir = await getDownloadsDirectory();
44
-  if (dir != null) {
45
-    dir = Directory("${dir.path}/logs");
46
-    if (!await dir.exists()) {
47
-      await dir.create(recursive: true);
43
+  //android版有文件日志
44
+  if (Platform.isAndroid) {
45
+    Directory? dir = await getDownloadsDirectory();
46
+    if (dir != null) {
47
+      dir = Directory("${dir.path}/logs");
48
+      if (!await dir.exists()) {
49
+        await dir.create(recursive: true);
50
+      }
51
+      output = kDebugMode
52
+          ? MultiOutput([ConsoleOutput(), AdvancedFileOutput(path: dir.path)])
53
+          : ConsoleOutput();
48 54
     }
49
-    output = kDebugMode
50
-        ? MultiOutput([ConsoleOutput(), AdvancedFileOutput(path: dir.path)])
51
-        : ConsoleOutput();
55
+  } else {
56
+    output = ConsoleOutput();
52 57
   }
53 58
   logger = Logger(
54 59
       printer: PrettyPrinter(