in Sources/XCMetricsClient/Log Management/LogManager.swift [100:121]
func retrieveXcodeLogs(in buildDirectory: String, timeout: Int) throws -> (currentLog: URL?, otherLogs: Set<URL>){
// Find all logs in Xcode's build and archive directories.
let xcodeLogs = findXCActivityLogsInDirectoriesSorted(buildDirectory)
let mostRecentLog = xcodeLogs.first
let mostRecentLogDate = mostRecentLog?.modificationDate
if let mostRecentLog = mostRecentLog,
let recentLogDate = mostRecentLogDate, dateProvider().timeIntervalSince(recentLogDate) < LogManagerImplementation.maximumCurrentLogAge {
return (mostRecentLog.url, Set(xcodeLogs.dropFirst().map { $0.url }))
}
// In some cases, Xcode will take a while to write the log (size of the log, CPU usage, etc.).
// This is a best-effort logic to try and wait up until the amount of seconds specified before timing out.
var timePassed = 0
while timePassed < timeout {
_ = sleepFunction(1)
timePassed += 1
if let latestLogURL = try? checkIfNewerLogAppeared(in: buildDirectory, afterDate: mostRecentLogDate) {
log("Latest log found.")
return (latestLogURL, Set(xcodeLogs.map({$0.url})))
}
}
return (nil, Set(xcodeLogs.map{$0.url}))
}