Add function to File Provider Logger extension to create debug logs file

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-11-01 18:52:27 +08:00
parent 0ddd22ddbb
commit 1dcfee4087
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -48,4 +48,24 @@ extension Logger {
return nil return nil
} }
} }
@available(macOSApplicationExtension 12.0, *)
static func createDebugArchive(saveFolderUrl: URL) {
let saveFileUrl = saveFolderUrl.appendingPathComponent("nc-fileprovider-debug.txt")
let saveFilePath = saveFolderUrl.path
guard FileManager.default.createFile(atPath: saveFilePath, contents: nil) else {
Logger.logger.error("Could not create log file")
return
}
guard let logs = Logger.logEntries() else {
Logger.logger.error("Cannot create debug archive without any logs.")
return
}
for logString in logs {
try? logString.write(to: saveFileUrl, atomically: true, encoding: .utf8)
}
}
} }