diff --git a/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift b/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift index 81514be5e1..a7a804c870 100644 --- a/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift +++ b/Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift @@ -20,10 +20,7 @@ import MLXLMCommon /// KV cache. public enum GuidedGenerationLoop { - private static let logger = Logger( - subsystem: "com.apple.FoundationModels-MLX", - category: "GuidedGenerationLoop" - ) + private static let logger = MLXLogger(label: "GuidedGenerationLoop") /// Result of a single generation step. enum StepResult { diff --git a/Libraries/MLXGuidedGeneration/Linux/Logger.swift b/Libraries/MLXGuidedGeneration/Linux/Logger.swift deleted file mode 100644 index c9428da842..0000000000 --- a/Libraries/MLXGuidedGeneration/Linux/Logger.swift +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2026 Apple Inc. - -#if canImport(os) - -import os - -typealias Logger = os.Logger - -#else - -final class Logger: Sendable { - private let subsystem: String - private let category: String - - init(subsystem: String, category: String) { - self.subsystem = subsystem - self.category = category - } - - func debug(_ message: String) { - print("[DEBUG] [\(subsystem).\(category)] \(message)") - } - - func info(_ message: String) { - print("[INFO] [\(subsystem).\(category)] \(message)") - } - - func notice(_ message: String) { - print("[NOTICE] [\(subsystem).\(category)] \(message)") - } - - func warning(_ message: String) { - print("[WARNING] [\(subsystem).\(category)] \(message)") - } - - func error(_ message: String) { - print("[ERROR] [\(subsystem).\(category)] \(message)") - } - - func fault(_ message: String) { - print("[FAULT] [\(subsystem).\(category)] \(message)") - } -} - -#endif diff --git a/Libraries/MLXLMCommon/InferenceState.swift b/Libraries/MLXLMCommon/InferenceState.swift index 157cb1dfe6..1384bca34c 100644 --- a/Libraries/MLXLMCommon/InferenceState.swift +++ b/Libraries/MLXLMCommon/InferenceState.swift @@ -15,8 +15,7 @@ package struct InferenceStatePreparationReport { package var succeeded: Bool { failures.isEmpty } } -private let inferenceStateLogger = Logger( - subsystem: "mlx-swift-lm", category: "inference-state") +private let inferenceStateLogger = MLXLogger(label: "inference-state") /// Prepare a language model after checkpoint loading or an explicit topology /// update. diff --git a/Libraries/MLXLMCommon/Linux/Logger.swift b/Libraries/MLXLMCommon/Linux/Logger.swift deleted file mode 100644 index c9428da842..0000000000 --- a/Libraries/MLXLMCommon/Linux/Logger.swift +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2026 Apple Inc. - -#if canImport(os) - -import os - -typealias Logger = os.Logger - -#else - -final class Logger: Sendable { - private let subsystem: String - private let category: String - - init(subsystem: String, category: String) { - self.subsystem = subsystem - self.category = category - } - - func debug(_ message: String) { - print("[DEBUG] [\(subsystem).\(category)] \(message)") - } - - func info(_ message: String) { - print("[INFO] [\(subsystem).\(category)] \(message)") - } - - func notice(_ message: String) { - print("[NOTICE] [\(subsystem).\(category)] \(message)") - } - - func warning(_ message: String) { - print("[WARNING] [\(subsystem).\(category)] \(message)") - } - - func error(_ message: String) { - print("[ERROR] [\(subsystem).\(category)] \(message)") - } - - func fault(_ message: String) { - print("[FAULT] [\(subsystem).\(category)] \(message)") - } -} - -#endif diff --git a/Libraries/MLXLMCommon/ParoQuant/ParoQuantLoader.swift b/Libraries/MLXLMCommon/ParoQuant/ParoQuantLoader.swift index 762b46ced5..ee8170fcbe 100644 --- a/Libraries/MLXLMCommon/ParoQuant/ParoQuantLoader.swift +++ b/Libraries/MLXLMCommon/ParoQuant/ParoQuantLoader.swift @@ -2,7 +2,7 @@ import Foundation import MLX import MLXNN -private let logger = Logger(subsystem: "mlx-swift-lm", category: "paroquant") +private let logger = MLXLogger(label: "paroquant") // MARK: - Detection @@ -790,8 +790,8 @@ public func loadParoQuantModel( phaseTimes .map { String(format: "%@=%.2fs", $0.0, $0.1) } .joined(separator: " ") - logger.notice( - "ParoQuant load phases: \(breakdown, privacy: .public) total=\(String(format: "%.2f", totalSeconds), privacy: .public)s" + logger.info( + "ParoQuant load phases: \(breakdown) total=\(String(format: "%.2f", totalSeconds))s" ) // 12b. Persist the Prepared Checkpoint in the background when this load diff --git a/Libraries/MLXLMCommon/ParoQuant/PreparedCheckpoint.swift b/Libraries/MLXLMCommon/ParoQuant/PreparedCheckpoint.swift index 6ac9ed0ade..fe458f89bf 100644 --- a/Libraries/MLXLMCommon/ParoQuant/PreparedCheckpoint.swift +++ b/Libraries/MLXLMCommon/ParoQuant/PreparedCheckpoint.swift @@ -1,8 +1,7 @@ import Foundation import MLX -import os -private let logger = Logger(subsystem: "mlx-swift-lm", category: "paroquant") +private let logger = MLXLogger(label: "paroquant") /// Prepared Checkpoint — the once-converted MLX-native form of a PARO /// checkpoint, stored beside the original so later loads skip the AutoAWQ @@ -143,14 +142,14 @@ public enum ParoQuantPreparedCheckpoint { Manifest.self, from: Data(manifestJSON.utf8)), stored == manifest else { - logger.notice("Prepared Checkpoint is stale — re-converting") + logger.info("Prepared Checkpoint is stale — re-converting") try? FileManager.default.removeItem(at: url) return nil } return arrays } catch { logger.warning( - "Prepared Checkpoint unreadable (\(String(describing: error), privacy: .public)) — re-converting" + "Prepared Checkpoint unreadable (\(String(describing: error))) — re-converting" ) try? FileManager.default.removeItem(at: url) return nil @@ -186,8 +185,8 @@ public enum ParoQuantPreparedCheckpoint { importantUsage > 0 ? importantUsage : Int64(capacity?.volumeAvailableCapacity ?? 0) if free > 0, free < estimatedBytes * freeSpaceSafetyFactor { - logger.notice( - "Prepared Checkpoint write skipped — free space \(free, privacy: .public)B < \(freeSpaceSafetyFactor, privacy: .public)× estimated \(estimatedBytes, privacy: .public)B" + logger.info( + "Prepared Checkpoint write skipped — free space \(free)B < \(freeSpaceSafetyFactor)× estimated \(estimatedBytes)B" ) return } @@ -204,12 +203,12 @@ public enum ParoQuantPreparedCheckpoint { try? fm.removeItem(at: url) try fm.moveItem(at: tmpURL, to: url) let seconds = (clock.now - start) / .seconds(1) - logger.notice( - "Prepared Checkpoint written: \(estimatedBytes, privacy: .public)B in \(String(format: "%.1f", seconds), privacy: .public)s" + logger.info( + "Prepared Checkpoint written: \(estimatedBytes)B in \(String(format: "%.1f", seconds))s" ) } catch { logger.warning( - "Prepared Checkpoint write failed (\(String(describing: error), privacy: .public)) — next load converts again" + "Prepared Checkpoint write failed (\(String(describing: error))) — next load converts again" ) try? fm.removeItem(at: tmpURL) } diff --git a/Libraries/MLXLMCommon/TokenLoopHandler.swift b/Libraries/MLXLMCommon/TokenLoopHandler.swift index d8dcb82b46..47918c612f 100644 --- a/Libraries/MLXLMCommon/TokenLoopHandler.swift +++ b/Libraries/MLXLMCommon/TokenLoopHandler.swift @@ -1,5 +1,7 @@ // Copyright © 2026 Apple Inc. +import MLX + /// Controls whether the generation loop continues. public enum TokenLoopDisposition: Sendable { /// Continue generating tokens. @@ -66,8 +68,7 @@ extension TokenLoopHandler { public struct TextToolTokenLoopHandler: TokenLoopHandler { public typealias Output = Generation - private static let logger = Logger( - subsystem: "mlx-swift-lm", category: "TokenStreamProtocol") + private static let logger = MLXLogger(label: "TokenStreamProtocol") private var decoder: any TokenStreamDecoder public init(