|
@@ -23,6 +23,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
23
|
23
|
import 'package:logger/logger.dart';
|
24
|
24
|
import 'package:network_info_plus/network_info_plus.dart';
|
25
|
25
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
26
|
+import 'package:path_provider/path_provider.dart';
|
26
|
27
|
import 'package:permission_handler/permission_handler.dart';
|
27
|
28
|
|
28
|
29
|
import 'global.dart';
|
|
@@ -30,7 +31,27 @@ import 'global.dart';
|
30
|
31
|
///国际化
|
31
|
32
|
S getS() => S.of(navigatorKey.currentState!.context);
|
32
|
33
|
|
33
|
|
-Logger logger = Logger(printer: PrettyPrinter(methodCount: 5));
|
|
34
|
+late Logger logger;
|
|
35
|
+
|
|
36
|
+///初始化日志
|
|
37
|
+Future<dynamic> initLog() async {
|
|
38
|
+ LogOutput? output;
|
|
39
|
+ Directory? dir = await getDownloadsDirectory();
|
|
40
|
+ if (dir != null) {
|
|
41
|
+ dir = Directory("${dir.path}/logs");
|
|
42
|
+ if (!await dir.exists()) {
|
|
43
|
+ await dir.create(recursive: true);
|
|
44
|
+ }
|
|
45
|
+ File file =
|
|
46
|
+ File("${dir.path}/log_${DateTime.now().millisecondsSinceEpoch}.log");
|
|
47
|
+ output = MultiOutput(
|
|
48
|
+ [ConsoleOutput(), FileOutput(file: file, overrideExisting: true)]);
|
|
49
|
+ }
|
|
50
|
+ logger = Logger(
|
|
51
|
+ printer: PrettyPrinter(
|
|
52
|
+ methodCount: 5, dateTimeFormat: DateTimeFormat.dateAndTime),
|
|
53
|
+ output: output);
|
|
54
|
+}
|
34
|
55
|
|
35
|
56
|
void logd(
|
36
|
57
|
dynamic message, {
|
|
@@ -38,7 +59,8 @@ void logd(
|
38
|
59
|
Object? error,
|
39
|
60
|
StackTrace? stackTrace,
|
40
|
61
|
}) {
|
41
|
|
- logger.d(message, time: time, error: error, stackTrace: stackTrace);
|
|
62
|
+ logger.d(message,
|
|
63
|
+ time: time ?? DateTime.now(), error: error, stackTrace: stackTrace);
|
42
|
64
|
}
|
43
|
65
|
|
44
|
66
|
void logi(
|
|
@@ -47,7 +69,8 @@ void logi(
|
47
|
69
|
Object? error,
|
48
|
70
|
StackTrace? stackTrace,
|
49
|
71
|
}) {
|
50
|
|
- logger.i(message, time: time, error: error, stackTrace: stackTrace);
|
|
72
|
+ logger.i(message,
|
|
73
|
+ time: time ?? DateTime.now(), error: error, stackTrace: stackTrace);
|
51
|
74
|
}
|
52
|
75
|
|
53
|
76
|
void loge(
|
|
@@ -56,7 +79,8 @@ void loge(
|
56
|
79
|
Object? error,
|
57
|
80
|
StackTrace? stackTrace,
|
58
|
81
|
}) {
|
59
|
|
- logger.e(message, time: time, error: error, stackTrace: stackTrace);
|
|
82
|
+ logger.e(message,
|
|
83
|
+ time: time ?? DateTime.now(), error: error, stackTrace: stackTrace);
|
60
|
84
|
}
|
61
|
85
|
|
62
|
86
|
void logw(
|
|
@@ -65,7 +89,8 @@ void logw(
|
65
|
89
|
Object? error,
|
66
|
90
|
StackTrace? stackTrace,
|
67
|
91
|
}) {
|
68
|
|
- logger.w(message, time: time, error: error, stackTrace: stackTrace);
|
|
92
|
+ logger.w(message,
|
|
93
|
+ time: time ?? DateTime.now(), error: error, stackTrace: stackTrace);
|
69
|
94
|
}
|
70
|
95
|
|
71
|
96
|
void logf(
|
|
@@ -74,7 +99,8 @@ void logf(
|
74
|
99
|
Object? error,
|
75
|
100
|
StackTrace? stackTrace,
|
76
|
101
|
}) {
|
77
|
|
- logger.f(message, time: time, error: error, stackTrace: stackTrace);
|
|
102
|
+ logger.f(message,
|
|
103
|
+ time: time ?? DateTime.now(), error: error, stackTrace: stackTrace);
|
78
|
104
|
}
|
79
|
105
|
|
80
|
106
|
///显示toast
|