Skip to content

Conversation

@naykutguven
Copy link
Contributor

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.shared singleton class with a static, actor-backed Logging enum, 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 .debugDescription for progress and .localizedDescription for 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.

@naykutguven naykutguven marked this pull request as ready for review November 23, 2025 17:46
Copilot AI review requested due to automatic review settings November 23, 2025 17:46
Copilot finished reviewing on behalf of naykutguven November 23, 2025 17:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors WhisperKit's logging system from a singleton pattern to a static, actor-based design to ensure thread safety and async-safe operations. The new Logging enum uses Swift concurrency primitives to manage log levels and callbacks, making the logging infrastructure more robust for concurrent contexts.

Key Changes

  • Replaced Logging.shared singleton with a static actor-backed Logging enum that provides thread-safe, async-safe logging operations
  • Updated all logging API calls throughout the codebase to use the new async static methods (updateLogLevel, isLoggingEnabled, updateCallback)
  • Improved debug message clarity by explicitly converting objects to strings before logging (e.g., using .debugDescription for progress and .localizedDescription for errors)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Sources/WhisperKit/Utilities/Logging.swift Core refactor introducing actor-based Engine for thread-safe log level and callback management, with static convenience methods for logging
Sources/WhisperKit/Core/WhisperKit.swift Updated to use new async logging API including updateLogLevel, isLoggingEnabled, and updateCallback; improved error message formatting
Sources/WhisperKit/Core/TranscribeTask.swift Updated to use isLoggingEnabled() async function instead of directly accessing shared log level
Tests/WhisperKitTests/UnitTests.swift Updated test setup to use new async updateLogLevel API
Tests/WhisperKitTests/RegressionTests.swift Improved debug logging by explicitly converting values to strings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 520 to 524
open func loggingCallback(_ callback: Logging.LoggingCallback?) {
Logging.shared.loggingCallback = callback
Task(priority: .utility) {
await Logging.updateCallback(callback)
}
}
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loggingCallback method creates an unstructured task to update the callback asynchronously, but doesn't await it or return the task. This creates a potential race condition where:

  1. A caller sets a logging callback
  2. Immediately after, logging calls are made
  3. The callback might not be set yet, causing logs to go to the default OSLog instead

Consider one of these approaches:

  • Make this an async function: open func loggingCallback(_ callback: Logging.LoggingCallback?) async
  • Or return the task so callers can await it if needed: @discardableResult open func loggingCallback(_ callback: Logging.LoggingCallback?) -> Task<Void, Never>

Copilot uses AI. Check for mistakes.
@naykutguven naykutguven force-pushed the logging-swift-6-refactor branch from daccc6a to 2b104b4 Compare November 26, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant