diff --git a/apps/macos/Sources/Clawdis/DebugActions.swift b/apps/macos/Sources/Clawdis/DebugActions.swift index 6dceeda5f..6f22e405b 100644 --- a/apps/macos/Sources/Clawdis/DebugActions.swift +++ b/apps/macos/Sources/Clawdis/DebugActions.swift @@ -96,7 +96,7 @@ enum DebugActions { let reason = rpcResult.error?.trimmingCharacters(in: .whitespacesAndNewlines) let detail = (reason?.isEmpty == false) ? reason! - : "No error returned. Check /tmp/clawdis.log or rpc output." + : "No error returned. Check logs or rpc output." return .failure(.message("Local send failed: \(detail)")) } } catch { @@ -114,14 +114,7 @@ enum DebugActions { } static func pinoLogPath() -> String { - let df = DateFormatter() - df.calendar = Calendar(identifier: .iso8601) - df.locale = Locale(identifier: "en_US_POSIX") - df.dateFormat = "yyyy-MM-dd" - let today = df.string(from: Date()) - let rolling = URL(fileURLWithPath: "/tmp/clawdis/clawdis-\(today).log").path - if FileManager.default.fileExists(atPath: rolling) { return rolling } - return "/tmp/clawdis.log" + LogLocator.bestLogFile()?.path ?? LogLocator.legacyLogPath } @MainActor diff --git a/apps/macos/Sources/Clawdis/GeneralSettings.swift b/apps/macos/Sources/Clawdis/GeneralSettings.swift index c36cec652..b999bf4f1 100644 --- a/apps/macos/Sources/Clawdis/GeneralSettings.swift +++ b/apps/macos/Sources/Clawdis/GeneralSettings.swift @@ -522,26 +522,7 @@ extension GeneralSettings { } private func revealLogs() { - let fm = FileManager.default - let legacy = URL(fileURLWithPath: "/tmp/clawdis/clawdis.log") - let rollingDir = URL(fileURLWithPath: "/tmp/clawdis") - - // Prefer the newest rolling log (clawdis-YYYY-MM-DD.log), fall back to legacy path. - let dirContents = (try? fm.contentsOfDirectory( - at: rollingDir, - includingPropertiesForKeys: [.contentModificationDateKey], - options: [.skipsHiddenFiles])) ?? [] - - let rollingLog = dirContents - .filter { $0.lastPathComponent.hasPrefix("clawdis-") && $0.pathExtension == "log" } - .sorted { lhs, rhs in - let lDate = (try? lhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast - let rDate = (try? rhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast - return lDate > rDate - } - .first - - let target = rollingLog ?? (fm.fileExists(atPath: legacy.path) ? legacy : nil) + let target = LogLocator.bestLogFile() if let target { NSWorkspace.shared.selectFile(target.path, inFileViewerRootedAtPath: target.deletingLastPathComponent().path) diff --git a/apps/macos/Sources/Clawdis/LogLocator.swift b/apps/macos/Sources/Clawdis/LogLocator.swift new file mode 100644 index 000000000..1b45bb4a2 --- /dev/null +++ b/apps/macos/Sources/Clawdis/LogLocator.swift @@ -0,0 +1,37 @@ +import Foundation + +enum LogLocator { + private static let logDir = URL(fileURLWithPath: "/tmp/clawdis") + private static let legacyLog = logDir.appendingPathComponent("clawdis.log") + + /// Returns the newest rolling log (clawdis-YYYY-MM-DD.log) if it exists, falling back to the legacy single-file log. + static func bestLogFile() -> URL? { + let fm = FileManager.default + let rollingFiles = (try? fm.contentsOfDirectory( + at: logDir, + includingPropertiesForKeys: [.contentModificationDateKey], + options: [.skipsHiddenFiles])) ?? [] + + let newestRolling = rollingFiles + .filter { $0.lastPathComponent.hasPrefix("clawdis-") && $0.pathExtension == "log" } + .sorted { lhs, rhs in + let lDate = (try? lhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast + let rDate = (try? rhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast + return lDate > rDate + } + .first + + if let rolling = newestRolling { + return rolling + } + if fm.fileExists(atPath: legacyLog.path) { + return legacyLog + } + return nil + } + + /// Legacy path used by launchd stdout/err; exposed for plist generation. + static var legacyLogPath: String { + legacyLog.path + } +} diff --git a/apps/macos/Sources/Clawdis/Utilities.swift b/apps/macos/Sources/Clawdis/Utilities.swift index 5a3eeab5a..11089011d 100644 --- a/apps/macos/Sources/Clawdis/Utilities.swift +++ b/apps/macos/Sources/Clawdis/Utilities.swift @@ -80,9 +80,9 @@ enum LaunchAgentManager { StandardOutPath - /tmp/clawdis.log + \(LogLocator.legacyLogPath) StandardErrorPath - /tmp/clawdis.log + \(LogLocator.legacyLogPath) """