getLogFile method
Implementation
@override
Future<String> getLogFile(
bool debug, {
int days = 3,
String? pathStart,
}) async {
DateTime dateTime = DateTime.now();
final String tempPath;
if (pathStart != null && pathStart.isNotEmpty) {
if (pathStart.endsWith(path.separator)) {
tempPath = '${pathStart}log';
} else {
tempPath = '$pathStart${path.separator}log';
}
} else {
if (debug) {
tempPath = 'data${path.separator}log';
} else {
tempPath = '${path.separator}log';
}
}
Directory tmpDir = Directory(tempPath);
if (!tmpDir.existsSync()) {
tmpDir.createSync(recursive: true);
}
String savePath = '$tempPath/${dateFormatYMD.format(dateTime)}.log';
final daysLog = <String>[savePath];
for (int i = (days - 1); i > 0; i--) {
String tmpPath =
'$tempPath/${dateFormatYMD.format(dateTime.subtract(Duration(days: i)))}.log';
daysLog.add(tmpPath);
}
var files = tmpDir.listSync();
for (final file in files) {
if (!daysLog.contains(file.path)) {
file.deleteSync();
}
}
return savePath;
}