Skip to content

Commit 84db8e2

Browse files
committed
Feat: Logger
1 parent eaa6997 commit 84db8e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+967
-202
lines changed

jsons/eh_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"showPageInterval?": true,
2424
"orientation?": "",
2525
"vibrate?": true,
26-
"tagIntroImgLv?": ""
26+
"tagIntroImgLv?": "",
27+
"debugMode?": false
2728
}

lib/common/controller/cache_controller.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CacheController extends GetxController with StateMixin<String> {
3838

3939
Future<String> getTotCacheSize() async {
4040
final int _cachesize = await _loadCache();
41-
logger.d('tot cacheSize ${renderSize(_cachesize)}');
41+
// logger.d('tot cacheSize ${renderSize(_cachesize)}');
4242
return renderSize(_cachesize);
4343
}
4444

@@ -71,7 +71,7 @@ class CacheController extends GetxController with StateMixin<String> {
7171
logger.d('临时目录大小: ' + value.toString());
7272
return value;
7373
} catch (err) {
74-
print(err);
74+
logger.e(err);
7575
return 0;
7676
}
7777
}
@@ -94,7 +94,7 @@ class CacheController extends GetxController with StateMixin<String> {
9494
}
9595
return 0;
9696
} catch (e) {
97-
print(e);
97+
logger.e('$e');
9898
return 0;
9999
}
100100
}
@@ -106,7 +106,7 @@ class CacheController extends GetxController with StateMixin<String> {
106106
//删除缓存目录
107107
await delDir(tempDir);
108108
} catch (e) {
109-
print(e);
109+
logger.e('$e');
110110
}
111111
}
112112

@@ -123,7 +123,7 @@ class CacheController extends GetxController with StateMixin<String> {
123123
await file.delete();
124124
}
125125
} catch (e) {
126-
print(e);
126+
logger.e('$e');
127127
}
128128
}
129129
}

lib/common/controller/tag_trans_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TagTransController extends GetxController {
6262
}
6363
_dbUrl = assMap['db.raw.json.gz'] ?? '';
6464

65-
logger.v(_dbUrl);
65+
logger.i(_dbUrl);
6666
return true;
6767
}
6868

@@ -172,7 +172,7 @@ class TagTransController extends GetxController {
172172
}
173173
logger.d(text);
174174
final array = text.split(RegExp(r'\s+'));
175-
logger.v(array.map((e) => '[$e]').join(','));
175+
logger.i(array.map((e) => '[$e]').join(','));
176176

177177
for (int i = 0; i < array.length; i++) {
178178
// print(array[i]);

lib/common/exts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension EhString on String {
3030
_dohDnsCacheIndex > -1 ? _dohDnsCacheList[_dohDnsCacheIndex] : null;
3131
realHost = dohDnsCache?.addr ?? host;
3232
final String realUrl = replaceFirst(host, realHost);
33-
logger.i('realUrl: $realUrl');
33+
logger.d('realUrl: $realUrl');
3434
return realUrl;
3535
}
3636
return this;

lib/common/global.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ class Global {
193193

194194
await FlutterDownloader.initialize(debug: Global.inDebugMode);
195195

196-
if (!inDebugMode) Logger.level = Level.info;
196+
if (!inDebugMode) {
197+
Logger.level = Level.info;
198+
}
197199

198200
canCheckBiometrics = await localAuth.canCheckBiometrics;
199201

lib/common/isolate/child.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Future<void> _fetchAllImageInfo(
165165
}
166166
}
167167
} catch (e, stack) {
168-
logger.d('$e\n$stack');
168+
logger.e('$e\n$stack');
169169
// rethrow;
170170
}
171171
}

lib/common/parser/gallery_list_parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class GalleryListParser {
187187
_translated = EHUtils.getLangeage(_langTag?.text ?? '');
188188
}
189189
} catch (e, stack) {
190-
logger.d('$e\n$stack');
190+
logger.e('$e\n$stack');
191191
}
192192

193193
// 封面图片

lib/common/service/ehconfig_service.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class EhConfigService extends ProfileService {
8080
// 震动总开关
8181
RxBool vibrate = true.obs;
8282

83+
final _debugMode = false.obs;
84+
get debugMode => _debugMode.value;
85+
set debugMode(val) => _debugMode.value = val;
86+
8387
@override
8488
void onInit() {
8589
super.onInit();
@@ -212,6 +216,11 @@ class EhConfigService extends ProfileService {
212216
TagIntroImgLv.nonh;
213217
everFromEunm(tagIntroImgLv,
214218
(String value) => ehConfig = ehConfig.copyWith(tagIntroImgLv: value));
219+
220+
//
221+
debugMode = ehConfig.debugMode ?? false;
222+
everProfile<bool>(_debugMode,
223+
(bool value) => ehConfig = ehConfig.copyWith(debugMode: value));
215224
}
216225

217226
/// 收藏排序

lib/common/service/log_service.dart

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import 'dart:io';
2+
3+
import 'package:fehviewer/utils/logger.dart';
4+
import 'package:get/get.dart';
5+
import 'package:intl/intl.dart';
6+
import 'package:logger/logger.dart';
7+
import 'package:path/path.dart' as path;
8+
9+
import '../global.dart';
10+
11+
const _kMaxTime = Duration(days: 7);
12+
const _kFilenameFormat = 'yyyy-MM-dd HH:mm:ss';
13+
const _kSuffix = '.log';
14+
15+
class LogService extends GetxService {
16+
final RxList<File> _logFiles = <File>[].obs;
17+
List<File> get logFiles {
18+
return _logFiles.value;
19+
}
20+
21+
set logFiles(val) => _logFiles.value = val;
22+
23+
final _curFileName = 'eh.log'.obs;
24+
get curFileName => _curFileName.value;
25+
set curFileName(val) => _curFileName.value = val;
26+
27+
final _logPath = ''.obs;
28+
get logPath => _logPath.value;
29+
set logPath(val) => _logPath.value = val;
30+
31+
final Rx<Level> _logLevel = Level.error.obs;
32+
Level get logLevel => _logLevel.value;
33+
set logLevel(val) => _logLevel.value = val;
34+
35+
@override
36+
void onInit() {
37+
super.onInit();
38+
39+
logPath = path.join(
40+
GetPlatform.isAndroid ? Global.extStorePath : Global.appDocPath, 'log');
41+
if (!Directory(logPath).existsSync()) {
42+
Directory(logPath).createSync(recursive: true);
43+
}
44+
45+
final DateTime _now = DateTime.now();
46+
final DateFormat formatter = DateFormat(_kFilenameFormat);
47+
final String _fileName = formatter.format(_now);
48+
curFileName = '$_fileName$_kSuffix';
49+
}
50+
51+
Future<List<File>?> loadFiles() async {
52+
List<File> _files = [];
53+
final Directory appDocDir = Directory(logPath);
54+
final Stream<FileSystemEntity> entityList =
55+
appDocDir.list(recursive: false, followLinks: false);
56+
await for (final FileSystemEntity entity in entityList) {
57+
if (entity.path.endsWith(_kSuffix)) {
58+
final File _logFile = File(entity.path);
59+
60+
try {
61+
// 超过最大时间的文件删除
62+
final _fileName = path.basename(_logFile.path);
63+
final _timeString = _fileName.replaceAll(_kSuffix, '');
64+
logger.i('log file time $_timeString');
65+
66+
final DateTime _nowTime = DateTime.now();
67+
final DateFormat formatter = DateFormat(_kFilenameFormat);
68+
69+
final _fileTime = formatter.parse(_timeString);
70+
// final _fileTime = DateTime.parse(_timeString);
71+
final _diff = _nowTime.difference(_fileTime);
72+
if (_diff.compareTo(_kMaxTime) > 0) {
73+
logger.d('delete $_fileName');
74+
_logFile.delete();
75+
}
76+
} catch (_) {}
77+
78+
_files.add(_logFile);
79+
}
80+
}
81+
_files
82+
.sort((a, b) => path.basename(b.path).compareTo(path.basename(a.path)));
83+
_logFiles(_files);
84+
}
85+
86+
void removeLogAt(int index) {
87+
_logFiles[index].deleteSync();
88+
_logFiles.removeAt(index);
89+
}
90+
91+
void removeAll() {
92+
for (final _file in _logFiles) {
93+
_file.delete();
94+
}
95+
_logFiles.clear();
96+
}
97+
}

lib/const/const.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,15 @@ class EHConst {
241241
'thai': 'TH',
242242
'vietnamese': 'VI',
243243
};
244+
245+
static List<String> fontFamilyFallback = [
246+
'miui',
247+
'sans-serif',
248+
];
249+
static List<String> monoFontFamilyFallback = [
250+
'monaco',
251+
'monospace',
252+
'Menlo',
253+
'Courier New',
254+
];
244255
}

0 commit comments

Comments
 (0)