mac: open latest log file
This commit is contained in:
@@ -522,15 +522,35 @@ extension GeneralSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func revealLogs() {
|
private func revealLogs() {
|
||||||
let path = URL(fileURLWithPath: "/tmp/clawdis/clawdis.log")
|
let fm = FileManager.default
|
||||||
if FileManager.default.fileExists(atPath: path.path) {
|
let legacy = URL(fileURLWithPath: "/tmp/clawdis/clawdis.log")
|
||||||
NSWorkspace.shared.selectFile(path.path, inFileViewerRootedAtPath: path.deletingLastPathComponent().path)
|
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)
|
||||||
|
|
||||||
|
if let target {
|
||||||
|
NSWorkspace.shared.selectFile(target.path, inFileViewerRootedAtPath: target.deletingLastPathComponent().path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.messageText = "Log file not found"
|
alert.messageText = "Log file not found"
|
||||||
alert.informativeText = "Expected log at \(path.path). Run a health check or generate activity first."
|
alert.informativeText = "Looked for clawdis logs in /tmp/clawdis/. Run a health check or send a message to generate activity, then try again."
|
||||||
alert.alertStyle = .informational
|
alert.alertStyle = .informational
|
||||||
alert.addButton(withTitle: "OK")
|
alert.addButton(withTitle: "OK")
|
||||||
alert.runModal()
|
alert.runModal()
|
||||||
|
|||||||
Reference in New Issue
Block a user