Quellcode durchsuchen

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

gjh vor 2 Wochen
Ursprung
Commit
0fe8f92461
1 geänderte Dateien mit 13 neuen und 8 gelöschten Zeilen
  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(