feat: delete logs when inDays > 7

This commit is contained in:
xkeyC 2024-05-03 13:12:11 +08:00
parent d05aa0d5f8
commit dd14a34285

View File

@ -19,8 +19,22 @@ void dPrint(src) async {
}); });
} }
void setDPrintFile(File file) { Future<void> initDPrintFile(String applicationSupportDir) async {
_logFile = file; final now = DateTime.now();
final logFile =
File("$applicationSupportDir\\logs\\${now.millisecondsSinceEpoch}.log");
await logFile.create(recursive: true);
_logFile = logFile;
final logsDir = Directory("$applicationSupportDir\\logs");
await for (final files in logsDir.list()) {
if (files is File) {
final stat = await files.stat();
if (stat.type == FileSystemEntityType.file &&
now.difference(await files.lastModified()).inDays > 7) {
await files.delete();
}
}
}
} }
File? getDPrintFile() { File? getDPrintFile() {