From b3f4134a821114cd4d2cda6a3169cff7ad7f373d Mon Sep 17 00:00:00 2001 From: Evgenii Kononenko Date: Fri, 6 Sep 2024 18:25:58 +0200 Subject: [PATCH 1/2] removed passing log handler factory in AuthConfig --- Sources/Auth/Model/AuthConfig.swift | 9 +++------ Sources/Auth/TidalAuth.swift | 4 ---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Sources/Auth/Model/AuthConfig.swift b/Sources/Auth/Model/AuthConfig.swift index 6b615a05..29d9de11 100644 --- a/Sources/Auth/Model/AuthConfig.swift +++ b/Sources/Auth/Model/AuthConfig.swift @@ -1,7 +1,4 @@ import Foundation -import protocol Logging.LogHandler - -public typealias LogHandlerFactory = (String) -> LogHandler public struct AuthConfig { public let clientId: String @@ -13,7 +10,7 @@ public struct AuthConfig { public let tidalLoginServiceBaseUri: String public let tidalAuthServiceBaseUri: String public let enableCertificatePinning: Bool - public let logHandlerFactory: LogHandlerFactory? + public let enableLogging: Bool public init( clientId: String, @@ -25,7 +22,7 @@ public struct AuthConfig { tidalLoginServiceBaseUri: String = "https://login.tidal.com", tidalAuthServiceBaseUri: String = "https://auth.tidal.com", enableCertificatePinning: Bool = true, - logHandlerFactory: LogHandlerFactory? = nil + enableLogging: Bool = false ) { self.clientId = clientId self.clientUniqueKey = clientUniqueKey @@ -36,6 +33,6 @@ public struct AuthConfig { self.tidalLoginServiceBaseUri = tidalLoginServiceBaseUri self.tidalAuthServiceBaseUri = tidalAuthServiceBaseUri self.enableCertificatePinning = enableCertificatePinning - self.logHandlerFactory = logHandlerFactory + self.enableLogging = enableLogging } } diff --git a/Sources/Auth/TidalAuth.swift b/Sources/Auth/TidalAuth.swift index 43f5c020..dd98e1a6 100644 --- a/Sources/Auth/TidalAuth.swift +++ b/Sources/Auth/TidalAuth.swift @@ -1,5 +1,4 @@ import Foundation -import Logging import Common // MARK: - TidalAuth @@ -19,9 +18,6 @@ public class TidalAuth: Auth & CredentialsProvider { loginRepository = provideLoginRepository(config, tokensStore: tokensStore) tokenRepository = provideTokenRepository(config, tokensStore: tokensStore) - // if logger is not provided, use logger that does nothing - let logHandlerFactory = config.logHandlerFactory ?? { _ in SwiftLogNoOpLogHandler() } - LoggingSystem.bootstrap(logHandlerFactory) } private func provideLoginRepository(_ config: AuthConfig, tokensStore: TokensStore) -> LoginRepository { From 65949f6037803dd7911b6a46e3fd845c342c97f8 Mon Sep 17 00:00:00 2001 From: Evgenii Kononenko Date: Fri, 6 Sep 2024 18:27:09 +0200 Subject: [PATCH 2/2] Auth: log only if logging is enabled --- Sources/Auth/Model/AuthLoggable.swift | 4 ++++ Sources/Auth/TidalAuth.swift | 1 + 2 files changed, 5 insertions(+) diff --git a/Sources/Auth/Model/AuthLoggable.swift b/Sources/Auth/Model/AuthLoggable.swift index 34217cd8..37bb78c3 100644 --- a/Sources/Auth/Model/AuthLoggable.swift +++ b/Sources/Auth/Model/AuthLoggable.swift @@ -20,6 +20,7 @@ enum AuthLoggable { // MARK: - Logging extension AuthLoggable { + static var enableLogging: Bool = false private static let metadataErrorKey = "error" private static let metadataReasonKey = "reason" private static let metadataPreviousSubstatusKey = "previous_substatus" @@ -90,6 +91,9 @@ extension AuthLoggable { } func log() { + guard Self.enableLogging else { + return + } var logger = Logger(label: "auth_logger") // IIUC, this is a minimum level for the logger logger.logLevel = .trace diff --git a/Sources/Auth/TidalAuth.swift b/Sources/Auth/TidalAuth.swift index dd98e1a6..ab859212 100644 --- a/Sources/Auth/TidalAuth.swift +++ b/Sources/Auth/TidalAuth.swift @@ -18,6 +18,7 @@ public class TidalAuth: Auth & CredentialsProvider { loginRepository = provideLoginRepository(config, tokensStore: tokensStore) tokenRepository = provideTokenRepository(config, tokensStore: tokensStore) + AuthLoggable.enableLogging = config.enableLogging } private func provideLoginRepository(_ config: AuthConfig, tokensStore: TokensStore) -> LoginRepository {