fix(@mac-sync): 🐛 add debug flag for send-queue tracing

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-21 19:39:09 -07:00
parent 08c638532c
commit b104ee1b12

View file

@ -9,6 +9,14 @@ import Foundation
/// Intentionally minimal and dependency-free. Serialized on a private queue
/// so concurrent callers don't interleave partial lines.
public enum TraceLog {
/// Verbose send-queue file tracing. Disabled unless `debugSendQueue` is
/// set `true` in the app config (`config.json` UserDefaults). The trace
/// calls are intentionally kept in the code (not deleted) so the send
/// pipeline can be re-diagnosed by flipping this flag no rebuild needed.
public static var isEnabled: Bool {
UserDefaults.standard.bool(forKey: "debugSendQueue")
}
private static let url: URL = FileManager.default
.homeDirectoryForCurrentUser
.appendingPathComponent("Library/Application Support/MacSync", isDirectory: true)
@ -22,8 +30,9 @@ public enum TraceLog {
return f
}()
public static func write(_ message: String) {
let line = "\(formatter.string(from: Date())) \(message)\n"
public static func write(_ message: @autoclosure () -> String) {
guard isEnabled else { return }
let line = "\(formatter.string(from: Date())) \(message())\n"
queue.async {
guard let data = line.data(using: .utf8) else { return }
let fm = FileManager.default