Skip to content

Commit 81a8a44

Browse files
fix configure
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent e23f089 commit 81a8a44

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Sources/NextcloudKit/Log/NKLogFileManager.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public final class NKLogFileManager: @unchecked Sendable {
6666

6767
public static func configure(logLevel: NKLogLevel = .normal) {
6868
shared.setConfiguration(logLevel: logLevel)
69+
shared.createLogsFolder()
6970
}
7071

7172
/// Returns the file URL of the currently active log file.
@@ -101,6 +102,28 @@ public final class NKLogFileManager: @unchecked Sendable {
101102
self.currentLogDate = Self.currentDateString()
102103
}
103104

105+
/// Creates the "Logs" folder inside the user's Documents directory if it does not already exist.
106+
///
107+
/// This method performs the following steps:
108+
/// - Retrieves the path to the `.documentDirectory` using `FileManager`.
109+
/// - Appends a "Logs" subdirectory path.
110+
/// - Checks if the folder already exists.
111+
/// - If not, it creates the folder, including any intermediate directories.
112+
/// - Finally, it sets the `logDirectory` and initializes the current log date.
113+
///
114+
/// If folder creation fails, the method silently ignores the error.
115+
///
116+
/// - Note: The `logDirectory` property will point to the created `Logs` folder.
117+
///
118+
private func createLogsFolder() {
119+
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
120+
let logsFolder = documents.appendingPathComponent("Logs", isDirectory: true)
121+
if !FileManager.default.fileExists(atPath: logsFolder.path) {
122+
try? FileManager.default.createDirectory(at: logsFolder, withIntermediateDirectories: true)
123+
}
124+
self.currentLogDate = Self.currentDateString()
125+
}
126+
104127
/// Sets configuration parameters for the logger.
105128
/// - Parameters:
106129
/// - logLevel: The NKLogLevel { disabled .. verbose }

0 commit comments

Comments
 (0)