clearLogDirectoryLogs static method
Implementation
static Future<bool> clearLogDirectoryLogs() async {
if (!_config.canWriteToFile) return false;
if (_config.logDirectory == null) return false;
final dir = _config.logDirectory!;
if (!await dir.exists()) {
try {
await dir.create(recursive: true);
} catch (_) {
return false;
}
}
var ok = true;
await for (final entity in dir.list(recursive: false, followLinks: false)) {
if (entity is File && entity.path.endsWith('.log')) {
try {
await entity.delete();
} catch (_) {
ok = false;
}
}
}
try {
final latest = File('${dir.path}/${_config.latestFileName}');
await latest.create(recursive: true);
await latest.writeAsString('', mode: FileMode.write);
} catch (_) {
ok = false;
}
return ok;
}