mac: drop legacy log path

This commit is contained in:
Peter Steinberger
2025-12-10 00:04:57 +00:00
parent 872d54a2dd
commit a7e4656834
3 changed files with 11 additions and 19 deletions

View File

@@ -114,7 +114,7 @@ enum DebugActions {
}
static func pinoLogPath() -> String {
LogLocator.bestLogFile()?.path ?? LogLocator.legacyLogPath
LogLocator.bestLogFile()?.path ?? LogLocator.launchdLogPath
}
@MainActor

View File

@@ -2,36 +2,28 @@ import Foundation
enum LogLocator {
private static let logDir = URL(fileURLWithPath: "/tmp/clawdis")
private static let legacyLog = logDir.appendingPathComponent("clawdis.log")
private static let stdoutLog = logDir.appendingPathComponent("clawdis-stdout.log")
/// Returns the newest rolling log (clawdis-YYYY-MM-DD.log) if it exists, falling back to the legacy single-file log.
/// Returns the newest log file under /tmp/clawdis/ (rolling or stdout), or nil if none exist.
static func bestLogFile() -> URL? {
let fm = FileManager.default
let rollingFiles = (try? fm.contentsOfDirectory(
let files = (try? fm.contentsOfDirectory(
at: logDir,
includingPropertiesForKeys: [.contentModificationDateKey],
options: [.skipsHiddenFiles])) ?? []
let newestRolling = rollingFiles
.filter { $0.lastPathComponent.hasPrefix("clawdis-") && $0.pathExtension == "log" }
return files
.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
/// Path to use for launchd stdout/err.
static var launchdLogPath: String {
stdoutLog.path
}
}

View File

@@ -80,9 +80,9 @@ enum LaunchAgentManager {
<true/>
</dict>
<key>StandardOutPath</key>
<string>\(LogLocator.legacyLogPath)</string>
<string>\(LogLocator.launchdLogPath)</string>
<key>StandardErrorPath</key>
<string>\(LogLocator.legacyLogPath)</string>
<string>\(LogLocator.launchdLogPath)</string>
</dict>
</plist>
"""