diff --git a/lib/common/utils/log.dart b/lib/common/utils/log.dart index 9356b8d..2184ab2 100644 --- a/lib/common/utils/log.dart +++ b/lib/common/utils/log.dart @@ -19,8 +19,22 @@ void dPrint(src) async { }); } -void setDPrintFile(File file) { - _logFile = file; +Future initDPrintFile(String applicationSupportDir) async { + 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() {