Skip to content

Commit 1999e1c

Browse files
cod
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent 81a8a44 commit 1999e1c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

Sources/NextcloudKit/Log/NKLogFileManager.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,26 @@ public final class NKLogFileManager: @unchecked Sendable {
6363
/// Configures the shared logger instance.
6464
/// - Parameters:
6565
/// - minLevel: The minimum log level to be recorded.
66-
6766
public static func configure(logLevel: NKLogLevel = .normal) {
6867
shared.setConfiguration(logLevel: logLevel)
68+
}
69+
70+
/// Creates the "Logs" folder inside the user's Documents directory if it does not already exist.
71+
///
72+
/// This static method delegates to the singleton instance (`shared`) and ensures
73+
/// that the log folder structure is created or re-created when needed.
74+
///
75+
/// This is useful in scenarios where the log folder may have been deleted externally
76+
/// (e.g., by iTunes File Sharing, iCloud Drive sync conflicts, or cleanup tools),
77+
/// and must be re-initialized manually.
78+
///
79+
/// The folder path is:
80+
/// `~/Documents/Logs`
81+
///
82+
/// If the folder already exists, the method does nothing. If creation fails, the error is silently ignored.
83+
///
84+
/// - Note: This does not create or write any log file, only the folder itself.
85+
public static func createLogsFolder() {
6986
shared.createLogsFolder()
7087
}
7188

@@ -266,6 +283,11 @@ public final class NKLogFileManager: @unchecked Sendable {
266283
private func appendToLog(_ message: String) {
267284
let logPath = logDirectory.appendingPathComponent(logFileName)
268285

286+
// Ensure log directory exists
287+
if !fileManager.fileExists(atPath: logDirectory.path) {
288+
try? fileManager.createDirectory(at: logDirectory, withIntermediateDirectories: true)
289+
}
290+
269291
guard let data = message.data(using: .utf8) else { return }
270292

271293
if fileManager.fileExists(atPath: logPath.path) {

0 commit comments

Comments
 (0)