From 9c9703668434c79f6c3af5192c599d99bf8da8da Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 19 Jul 2026 01:00:01 +0200 Subject: [PATCH] Make Enable Logging the master switch over all verbose logging The verbose toggles (MPV, remote control) kept working with the master "Enable Logging" toggle off: the settings UI hides them, but their stored values - verboseMPVLogging is even iCloud-synced - were still honored at runtime, producing console output and enabling the periodic MPV stats collection while logging appeared disabled. Enable Logging now takes precedence everywhere: - LoggingService gates its DEBUG-build OSLog console output on the master toggle (it previously ran before the isEnabled guard, so the Xcode console was never silent) - MPVLogging requires loggingEnabled && verboseMPVLogging, which also gates the 10s playback stats task via MPVLogging.verboseEnabled - rcDebug in LocalNetworkService and RemoteControlCoordinator requires the master toggle alongside verboseRemoteControlLogging --- Yattee/Services/Logging/LoggingService.swift | 27 +++++++++++-------- Yattee/Services/Player/MPV/MPVLogging.swift | 7 +++-- .../RemoteControl/LocalNetworkService.swift | 4 ++- .../RemoteControlCoordinator.swift | 4 ++- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Yattee/Services/Logging/LoggingService.swift b/Yattee/Services/Logging/LoggingService.swift index 248f5110..1050a7ca 100644 --- a/Yattee/Services/Logging/LoggingService.swift +++ b/Yattee/Services/Logging/LoggingService.swift @@ -192,18 +192,23 @@ final class LoggingService: Sendable { /// OSLog output is synchronous; in-app storage is dispatched to MainActor. nonisolated func log(level: LogLevel, category: LogCategory, message: String, details: String? = nil) { // Log to OSLog in DEBUG builds for Xcode console visibility - // OSLog/Logger is thread-safe, so this can be called from any thread + // OSLog/Logger is thread-safe, so this can be called from any thread. + // The master "Enable Logging" toggle gates this too - it takes + // precedence over everything, so logging off means a silent console. + // (Read UserDefaults directly: this runs off the MainActor.) #if DEBUG - let fullMessage = details.map { "\(message) - \($0)" } ?? message - switch level { - case .debug: - osLogger.debug("[\(category.rawValue)] \(fullMessage)") - case .info: - osLogger.info("[\(category.rawValue)] \(fullMessage)") - case .warning: - osLogger.warning("[\(category.rawValue)] \(fullMessage)") - case .error: - osLogger.error("[\(category.rawValue)] \(fullMessage)") + if UserDefaults.standard.bool(forKey: "loggingEnabled") { + let fullMessage = details.map { "\(message) - \($0)" } ?? message + switch level { + case .debug: + osLogger.debug("[\(category.rawValue)] \(fullMessage)") + case .info: + osLogger.info("[\(category.rawValue)] \(fullMessage)") + case .warning: + osLogger.warning("[\(category.rawValue)] \(fullMessage)") + case .error: + osLogger.error("[\(category.rawValue)] \(fullMessage)") + } } #endif diff --git a/Yattee/Services/Player/MPV/MPVLogging.swift b/Yattee/Services/Player/MPV/MPVLogging.swift index a3235aab..becd73b3 100644 --- a/Yattee/Services/Player/MPV/MPVLogging.swift +++ b/Yattee/Services/Player/MPV/MPVLogging.swift @@ -37,8 +37,11 @@ enum MPVLogging { if now - _lastCheckTime > cacheDurationNanos { _lastCheckTime = now // Read from UserDefaults directly for thread safety - // (SettingsManager is @MainActor) - _cachedIsEnabled = UserDefaults.standard.bool(forKey: "verboseMPVLogging") + // (SettingsManager is @MainActor). + // The master "Enable Logging" switch takes precedence: with it off, + // verbose MPV logging is off no matter what the verbose flag says. + _cachedIsEnabled = UserDefaults.standard.bool(forKey: "loggingEnabled") + && UserDefaults.standard.bool(forKey: "verboseMPVLogging") } return _cachedIsEnabled diff --git a/Yattee/Services/RemoteControl/LocalNetworkService.swift b/Yattee/Services/RemoteControl/LocalNetworkService.swift index da9cf373..64bb845d 100644 --- a/Yattee/Services/RemoteControl/LocalNetworkService.swift +++ b/Yattee/Services/RemoteControl/LocalNetworkService.swift @@ -92,8 +92,10 @@ final class LocalNetworkService { } /// Log debug-level message. Only logs if verbose remote control logging is enabled. + /// The master "Enable Logging" toggle takes precedence over the verbose flag. private func rcDebug(_ operation: String, _ message: String) { - guard UserDefaults.standard.bool(forKey: "verboseRemoteControlLogging") else { return } + guard UserDefaults.standard.bool(forKey: "loggingEnabled"), + UserDefaults.standard.bool(forKey: "verboseRemoteControlLogging") else { return } let fullMessage = "[RemoteControl] \(operation) - \(message)" LoggingService.shared.logRemoteControlDebug(fullMessage) } diff --git a/Yattee/Services/RemoteControl/RemoteControlCoordinator.swift b/Yattee/Services/RemoteControl/RemoteControlCoordinator.swift index 4fab21fb..e64c1bdc 100644 --- a/Yattee/Services/RemoteControl/RemoteControlCoordinator.swift +++ b/Yattee/Services/RemoteControl/RemoteControlCoordinator.swift @@ -116,8 +116,10 @@ final class RemoteControlCoordinator { } /// Log debug-level message. Only logs if verbose remote control logging is enabled. + /// The master "Enable Logging" toggle takes precedence over the verbose flag. private func rcDebug(_ operation: String, _ message: String) { - guard UserDefaults.standard.bool(forKey: "verboseRemoteControlLogging") else { return } + guard UserDefaults.standard.bool(forKey: "loggingEnabled"), + UserDefaults.standard.bool(forKey: "verboseRemoteControlLogging") else { return } let fullMessage = "[RemoteControl] \(operation) - \(message)" LoggingService.shared.logRemoteControlDebug(fullMessage) }