initLogger static method
Implementation
static Future<void> initLogger() async {
//删除过期的日志文件
Directory directory = await getAppDirectory();
Stream<FileSystemEntity> fileList = directory.list();
//删除7天前的
int time = DateTime.now().millisecondsSinceEpoch - 7 * 24 * 60 * 60 * 1000;
await for (FileSystemEntity fileSystemEntity in fileList) {
final name = fileSystemEntity.path
.substring(fileSystemEntity.path.lastIndexOf('/') + 1, fileSystemEntity.path.lastIndexOf('.'));
List<String> split = name.split('_');
if (split.length == 3) {
DateTime dateTime = DateTime(int.parse(split[0]), int.parse(split[1]), int.parse(split[2]));
if (dateTime.millisecondsSinceEpoch < time) {
fileSystemEntity.delete();
}
}
}
}