Skip to content

Commit

Permalink
Merge pull request #80 from tidal-music/ekononenko/do-not-set-up-logg…
Browse files Browse the repository at this point in the history
…ing-system-in-auth

Do not set up logging system in auth
  • Loading branch information
e-kononenko committed Sep 9, 2024
2 parents bb5b018 + 65949f6 commit 51117a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
9 changes: 3 additions & 6 deletions Sources/Auth/Model/AuthConfig.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import Foundation
import protocol Logging.LogHandler

public typealias LogHandlerFactory = (String) -> LogHandler

public struct AuthConfig {
public let clientId: String
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -36,6 +33,6 @@ public struct AuthConfig {
self.tidalLoginServiceBaseUri = tidalLoginServiceBaseUri
self.tidalAuthServiceBaseUri = tidalAuthServiceBaseUri
self.enableCertificatePinning = enableCertificatePinning
self.logHandlerFactory = logHandlerFactory
self.enableLogging = enableLogging
}
}
4 changes: 4 additions & 0 deletions Sources/Auth/Model/AuthLoggable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions Sources/Auth/TidalAuth.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Logging
import Common

// MARK: - TidalAuth
Expand All @@ -19,9 +18,7 @@ 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)
AuthLoggable.enableLogging = config.enableLogging
}

private func provideLoginRepository(_ config: AuthConfig, tokensStore: TokensStore) -> LoginRepository {
Expand Down

0 comments on commit 51117a9

Please sign in to comment.