From bb1a35aceaea19511bcae04f3b71427393237d63 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 4 Jun 2022 09:25:15 +0200 Subject: [PATCH] Set full log path relative to App Group container Also rename from Debug.log to App.log --- .../App/Constants/Constants+Extensions.swift | 24 +++++++++---------- Passepartout/App/Contexts/AppContext.swift | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Passepartout/App/Constants/Constants+Extensions.swift b/Passepartout/App/Constants/Constants+Extensions.swift index e198bdc4..dcc9f1ae 100644 --- a/Passepartout/App/Constants/Constants+Extensions.swift +++ b/Passepartout/App/Constants/Constants+Extensions.swift @@ -149,6 +149,16 @@ extension Constants { } enum Log { + private static let parentPath = "Library/Caches" + + private static func containerLogURL(filename: String) -> URL { + Files.containerURL + .appendingPathComponent(parentPath) + .appendingPathComponent(filename) + } + + static let appLogURL = containerLogURL(filename: "App.log") + static let logLevel: SwiftyBeaver.Level = { guard let levelString = ProcessInfo.processInfo.environment["LOG_LEVEL"], let levelNum = Int(levelString) else { return .info @@ -158,12 +168,6 @@ extension Constants { static let logFormat = "$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M" - private static let appFileName = "Debug.log" - - static var appFileURL: URL { - return Files.cachesURL.appendingPathComponent(appFileName) - } - static let tunnelLogFormat = "$DHH:mm:ss$d - $M" static let tunnelLogMaxBytes = 15000 @@ -256,18 +260,12 @@ extension Constants { extension Constants { enum Files { - private static var containerURL: URL { + fileprivate static var containerURL: URL { guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: App.appGroupId) else { print("Unable to access App Group container") return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] } return url } - - static let cachesURL: URL = { - let url = containerURL.appendingPathComponent("Library/Caches", isDirectory: true) - try? FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil) - return url - }() } } diff --git a/Passepartout/App/Contexts/AppContext.swift b/Passepartout/App/Contexts/AppContext.swift index 97eb1589..0d56977c 100644 --- a/Passepartout/App/Contexts/AppContext.swift +++ b/Passepartout/App/Contexts/AppContext.swift @@ -40,7 +40,7 @@ class AppContext { private var cancellables: Set = [] init(coreContext: CoreContext) { - logManager = LogManager(logFile: Constants.Log.appFileURL) + logManager = LogManager(logFile: Constants.Log.appLogURL) logManager.logLevel = Constants.Log.logLevel logManager.logFormat = Constants.Log.logFormat logManager.configureLogging()