From 1dcfee4087a8adea962ffcbf0873704ef7c5ff83 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 1 Nov 2023 18:52:27 +0800 Subject: [PATCH] Add function to File Provider Logger extension to create debug logs file Signed-off-by: Claudio Cambra --- .../Extensions/Logger+Extensions.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Logger+Extensions.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Logger+Extensions.swift index f84ea068e..cffeb366f 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Logger+Extensions.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Logger+Extensions.swift @@ -48,4 +48,24 @@ extension Logger { 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) + } + } }