mac: drop legacy log path
parent
872d54a2dd
commit
a7e4656834
|
|
@ -114,7 +114,7 @@ enum DebugActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func pinoLogPath() -> String {
|
static func pinoLogPath() -> String {
|
||||||
LogLocator.bestLogFile()?.path ?? LogLocator.legacyLogPath
|
LogLocator.bestLogFile()?.path ?? LogLocator.launchdLogPath
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
||||||
|
|
@ -2,36 +2,28 @@ import Foundation
|
||||||
|
|
||||||
enum LogLocator {
|
enum LogLocator {
|
||||||
private static let logDir = URL(fileURLWithPath: "/tmp/clawdis")
|
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? {
|
static func bestLogFile() -> URL? {
|
||||||
let fm = FileManager.default
|
let fm = FileManager.default
|
||||||
let rollingFiles = (try? fm.contentsOfDirectory(
|
let files = (try? fm.contentsOfDirectory(
|
||||||
at: logDir,
|
at: logDir,
|
||||||
includingPropertiesForKeys: [.contentModificationDateKey],
|
includingPropertiesForKeys: [.contentModificationDateKey],
|
||||||
options: [.skipsHiddenFiles])) ?? []
|
options: [.skipsHiddenFiles])) ?? []
|
||||||
|
|
||||||
let newestRolling = rollingFiles
|
return files
|
||||||
.filter { $0.lastPathComponent.hasPrefix("clawdis-") && $0.pathExtension == "log" }
|
.filter { $0.lastPathComponent.hasPrefix("clawdis") && $0.pathExtension == "log" }
|
||||||
.sorted { lhs, rhs in
|
.sorted { lhs, rhs in
|
||||||
let lDate = (try? lhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
let lDate = (try? lhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
||||||
let rDate = (try? rhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
let rDate = (try? rhs.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast
|
||||||
return lDate > rDate
|
return lDate > rDate
|
||||||
}
|
}
|
||||||
.first
|
.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.
|
/// Path to use for launchd stdout/err.
|
||||||
static var legacyLogPath: String {
|
static var launchdLogPath: String {
|
||||||
legacyLog.path
|
stdoutLog.path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,9 @@ enum LaunchAgentManager {
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
<key>StandardOutPath</key>
|
<key>StandardOutPath</key>
|
||||||
<string>\(LogLocator.legacyLogPath)</string>
|
<string>\(LogLocator.launchdLogPath)</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>\(LogLocator.legacyLogPath)</string>
|
<string>\(LogLocator.launchdLogPath)</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue