WhisperKit
WhisperKit copied to clipboard
Refactor Logging utility for thread safety
This pull request refactors the logging system throughout the WhisperKit codebase to use a new, actor-based, async-safe static Logging API. The update removes the singleton pattern, introduces async log level and callback management, and standardizes how log messages are dispatched. Additionally, it updates all existing usages to the new API and improves the clarity of some debug messages.
Logging System Refactor:
- Replaced the
Logging.sharedsingleton class with a static, actor-backedLoggingenum, making logging async-safe and thread-safe. The new design centralizes log level and callback management and uses Swift Concurrency for updates. (Sources/WhisperKit/Utilities/Logging.swift) - Updated all usages of the old logging API to the new async static API, including setting log level, logging callbacks, and checking if logging is enabled. (
Sources/WhisperKit/Core/WhisperKit.swift,Sources/WhisperKit/Core/TranscribeTask.swift,Tests/WhisperKitTests/UnitTests.swift)
Debug Message Improvements:
- Improved debug message clarity by converting objects to string representations before logging, such as using
.debugDescriptionfor progress and.localizedDescriptionfor errors. (Sources/WhisperKit/Core/WhisperKit.swift,Tests/WhisperKitTests/RegressionTests.swift)
Code Clean-up and Modernization:
- Removed deprecated global functions for memory logging and simplified formatting utility methods. (
Sources/WhisperKit/Utilities/Logging.swift)
These changes modernize the logging infrastructure, making it safer and more robust for concurrent and async contexts, and improve the consistency and clarity of log output across the codebase.