diff --git a/@packages/shared/Sources/MacSyncShared/Sync/TraceLog.swift b/@packages/shared/Sources/MacSyncShared/Sync/TraceLog.swift index 41d8151..66193cb 100644 --- a/@packages/shared/Sources/MacSyncShared/Sync/TraceLog.swift +++ b/@packages/shared/Sources/MacSyncShared/Sync/TraceLog.swift @@ -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