Skip to content

Commit

Permalink
fix(Auth): Add logging to Amplify Auth tasks (#3365)
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 authored Dec 11, 2023
1 parent 2530737 commit d3af5f9
Show file tree
Hide file tree
Showing 23 changed files with 18 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,4 @@ class AWSAuthChangePasswordTask: AuthChangePasswordTask, DefaultLogger {
_ = try await userPoolService.changePassword(input: input)
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,4 @@ public class AWSAuthClearFederationToIdentityPoolTask: AuthClearFederationToIden
return
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,4 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg
_ = try await userPoolService.confirmForgotPassword(input: input)
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,4 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask, DefaultLogger {
friendlyDeviceName: pluginOptions?.friendlyDeviceName)
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,4 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger {
}
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,4 @@ class AWSAuthDeleteUserTask: AuthDeleteUserTask, DefaultLogger {
await taskHelper.didStateMachineConfigured()
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,4 @@ public class AWSAuthFederateToIdentityPoolTask: AuthFederateToIdentityPoolTask,
}
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,4 @@ class AWSAuthFetchSessionTask: AuthFetchSessionTask, DefaultLogger {
forceRefresh: doesNeedForceRefresh)
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,4 @@ class AWSAuthResendSignUpCodeTask: AuthResendSignUpCodeTask, DefaultLogger {
return deliveryDetails
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,4 @@ class AWSAuthResetPasswordTask: AuthResetPasswordTask, DefaultLogger {
let authResetPasswordResult = AuthResetPasswordResult(isPasswordReset: false, nextStep: nextStep)
return authResetPasswordResult
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,4 @@ class AWSAuthSignInTask: AuthSignInTask, DefaultLogger {

return clientMetadata
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,4 @@ class AWSAuthSignOutTask: AuthSignOutTask, DefaultLogger {
let event = AuthenticationEvent(eventType: .signOutRequested(signOutData))
await authStateMachine.send(event)
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,4 @@ class AWSAuthSignUpTask: AuthSignUpTask, DefaultLogger {
)
}
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,5 @@ class AWSAuthWebUISignInTask: AuthWebUISignInTask, DefaultLogger {
}
}

public static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self))
}

public var log: Logger {
Self.log
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AWSPluginsCore
import ClientRuntime
import AWSCognitoIdentityProvider

class AWSAuthFetchDevicesTask: AuthFetchDevicesTask {
class AWSAuthFetchDevicesTask: AuthFetchDevicesTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthFetchDevicesRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AWSPluginsCore
import ClientRuntime
import AWSCognitoIdentityProvider

class AWSAuthForgetDeviceTask: AuthForgetDeviceTask {
class AWSAuthForgetDeviceTask: AuthForgetDeviceTask, DefaultLogger {

private let request: AuthForgetDeviceRequest
private let authStateMachine: AuthStateMachine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AWSPluginsCore
import ClientRuntime
import AWSCognitoIdentityProvider

class AWSAuthRememberDeviceTask: AuthRememberDeviceTask {
class AWSAuthRememberDeviceTask: AuthRememberDeviceTask, DefaultLogger {

private let request: AuthRememberDeviceRequest
private let authStateMachine: AuthStateMachine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ protocol AmplifyAuthTask {

}

extension AmplifyAuthTask {
extension AmplifyAuthTask where Self: DefaultLogger {
var value: Success {
get async throws {
do {
log.info("Starting execution for \(eventName)")
let valueReturned = try await execute()
log.info("Successfully completed execution for \(eventName) with result:\n\(prettify(valueReturned))")
dispatch(result: .success(valueReturned))
return valueReturned
} catch let error as Failure {
log.error("Failed execution for \(eventName) with error:\n\(prettify(error))")
dispatch(result: .failure(error))
throw error
}
Expand All @@ -44,4 +47,10 @@ extension AmplifyAuthTask {
let payload = HubPayload(eventName: eventName, context: nil, data: result)
Amplify.Hub.dispatch(to: channel, payload: payload)
}

private func prettify<T>(_ value: T) -> String {
var result = ""
dump(value, to: &result)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Amplify
import AWSPluginsCore
import AWSCognitoIdentityProvider

class AWSAuthAttributeResendConfirmationCodeTask: AuthAttributeResendConfirmationCodeTask {
class AWSAuthAttributeResendConfirmationCodeTask: AuthAttributeResendConfirmationCodeTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthAttributeResendConfirmationCodeRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AWSPluginsCore
import ClientRuntime
import AWSCognitoIdentityProvider

class AWSAuthConfirmUserAttributeTask: AuthConfirmUserAttributeTask {
class AWSAuthConfirmUserAttributeTask: AuthConfirmUserAttributeTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthConfirmUserAttributeRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AWSPluginsCore
import ClientRuntime
import AWSCognitoIdentityProvider

class AWSAuthFetchUserAttributeTask: AuthFetchUserAttributeTask {
class AWSAuthFetchUserAttributeTask: AuthFetchUserAttributeTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthFetchUserAttributesRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Amplify
import AWSPluginsCore
import AWSCognitoIdentityProvider

class AWSAuthUpdateUserAttributeTask: AuthUpdateUserAttributeTask {
class AWSAuthUpdateUserAttributeTask: AuthUpdateUserAttributeTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthUpdateUserAttributeRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Amplify
import AWSPluginsCore
import AWSCognitoIdentityProvider

class AWSAuthUpdateUserAttributesTask: AuthUpdateUserAttributesTask {
class AWSAuthUpdateUserAttributesTask: AuthUpdateUserAttributesTask, DefaultLogger {
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior

private let request: AuthUpdateUserAttributesRequest
Expand Down

0 comments on commit d3af5f9

Please sign in to comment.