in Sources/XCMetricsClient/Log Management/LogManager.swift [191:221]
func evictLogs() throws -> Set<URL> {
// Remove logs older than 7 days from cache directory.
let cachedLogs = try retrieveCachedLogs()
let logsToBeEvicted = cachedLogs.filter { logURL in
do {
let attributes = try fileAccessor.attributesOfItem(atPath: logURL.path)
guard let lastModificationDate = attributes[FileAttributeKey.modificationDate] as? Date else { return false }
let components = Calendar.current.dateComponents([.day], from: lastModificationDate, to: dateProvider())
if components.day ?? 0 > 7 {
return true
}
return false
} catch {
log("Failed to get attributes for item at \(logURL.path): \(error.localizedDescription)")
return false
}
}
var removedLogs = Set<URL>()
for logURL in logsToBeEvicted {
do {
// Remove old xcactivitylog.
try fileAccessor.removeItem(at: logURL)
log("Evicted xcactivitylog at url \(logURL)")
removedLogs.insert(logURL)
} catch {
log("Failed to evict log or upload request for url \(logURL) with error \(error.localizedDescription)")
}
}
return removedLogs
}