Skip to content

Commit

Permalink
chore: resolve swiftlint errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Jan 2, 2024
1 parent 93690dd commit a059f5c
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class AWSCloudWatchLoggingCategoryClient {
private var userIdentifier: String?
private var authSubscription: AnyCancellable? { willSet { authSubscription?.cancel() } }
private let networkMonitor: LoggingNetworkMonitor

init(
enable: Bool,
credentialsProvider: CredentialsProviding,
Expand All @@ -62,7 +62,7 @@ final class AWSCloudWatchLoggingCategoryClient {
self?.handle(payload: payload)
}
}

func takeUserIdentifierFromCurrentUser() {
Task {
do {
Expand All @@ -74,15 +74,15 @@ final class AWSCloudWatchLoggingCategoryClient {
self.updateSessionControllers()
}
}

private func updateSessionControllers() {
lock.execute {
for controller in loggersByKey.values {
controller.setCurrentUser(identifier: self.userIdentifier)
}
}
}

private func handle(payload: HubPayload) {
enum CognitoEventName: String {
case signInAPI = "Auth.signInAPI"
Expand All @@ -98,15 +98,15 @@ final class AWSCloudWatchLoggingCategoryClient {
break
}
}

/// - Tag: CloudWatchLoggingCategoryClient.reset
func reset() async {
lock.execute {
loggersByKey = [:]
}
}
func getLoggerSessionController(forCategory category: String, logLevel: LogLevel) -> AWSCloudWatchLoggingSessionController? {

func getLoggerSessionController(forCategory category: String, logLevel: LogLevel) -> AWSCloudWatchLoggingSessionController? {
let key = LoggerKey(category: category, logLevel: logLevel)
if let existing = loggersByKey[key] {
return existing
Expand All @@ -124,7 +124,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
}
}
}

func disable() {
enabled = false
lock.execute {
Expand All @@ -133,19 +133,18 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
}
}
}

var `default`: Logger {
return self.logger(forCategory: "Amplify")
}

func logger(forCategory category: String, namespace: String?, logLevel: Amplify.LogLevel) -> Logger {
return lock.execute {
let key = LoggerKey(category: category, logLevel: logLevel)
if let existing = loggersByKey[key] {
return existing
}



let controller = AWSCloudWatchLoggingSessionController(credentialsProvider: credentialsProvider,
authentication: authentication,
logFilter: self.logFilter,
Expand All @@ -164,25 +163,25 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
return controller
}
}

func logger(forCategory category: String, logLevel: LogLevel) -> Logger {
return self.logger(forCategory: category, namespace: nil, logLevel: logLevel)
}

func logger(forCategory category: String) -> Logger {
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier)
return self.logger(forCategory: category, namespace: nil, logLevel: defaultLogLevel)
}

func logger(forNamespace namespace: String) -> Logger {
self.logger(forCategory: namespace)
}

func logger(forCategory category: String, forNamespace namespace: String) -> Logger {
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier)
return self.logger(forCategory: category, namespace: namespace, logLevel: defaultLogLevel)
}

func getInternalClient() -> CloudWatchLogsClientProtocol {
guard let client = loggersByKey.first(where: { $0.value.client != nil })?.value.client else {
return Fatal.preconditionFailure(
Expand All @@ -194,7 +193,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
}
return client
}

func flushLogs() async throws {
guard enabled else { return }
for logger in loggersByKey.values {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import Foundation
struct AWSCloudWatchLoggingError: AmplifyError {

var errorDescription: String

var recoverySuggestion: String

var underlyingError: Error?

init(errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion, error: Error) {
self.errorDescription = errorDescription
self.recoverySuggestion = recoverySuggestion
self.underlyingError = error
}

init(errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion) {
self.errorDescription = errorDescription
self.recoverySuggestion = recoverySuggestion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ import Foundation
/// delegates all calls to the default Console logger implementation.
///
/// - Tag: CloudWatchLoggingPlugin
public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
/// An instance of the authentication service.
var loggingClient: AWSCloudWatchLoggingCategoryClient!

private var loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration?
private var remoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider?

public var key: PluginKey {
return PluginConstants.awsCloudWatchLoggingPluginKey
}

public var `default`: Logger {
loggingClient.default
}

public init(
loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration? = nil,
remoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider? = nil
Expand Down Expand Up @@ -66,45 +66,45 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
public func logger(forCategory category: String) -> Logger {
return loggingClient.logger(forCategory: category)
}

public func logger(forNamespace namespace: String) -> Logger {
return loggingClient.logger(forCategory: namespace)
}

public func logger(forCategory category: String, forNamespace namespace: String) -> Logger {
return loggingClient.logger(forCategory: category, forNamespace: namespace)
}

/// enable plugin
public func enable() {
loggingClient.enable()
}

/// disable plugin
public func disable() {
loggingClient.disable()
}

/// send logs on-demand to AWS CloudWatch
public func flushLogs() async throws {
try await loggingClient.flushLogs()
}

/// Retrieve the escape hatch to perform low level operations on AWSCloudWatch
///
/// - Returns: AWS CloudWatch Client
public func getEscapeHatch() -> CloudWatchLogsClientProtocol {
return loggingClient.getInternalClient()
}

/// Resets the state of the plugin.
///
/// Calls the reset methods on the storage service and authentication service to clean up resources. Setting the
/// storage service, authentication service, and queue to nil to allow deallocation.
public func reset() async {
await loggingClient.reset()
}

/// Configures AWSS3StoragePlugin with the specified configuration.
///
/// This method will be invoked as part of the Amplify configuration flow. Retrieves the bucket, region, and
Expand All @@ -117,14 +117,14 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
if self.loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) {
self.loggingPluginConfiguration = configuration
let authService = AWSAuthService()

if let remoteConfig = configuration.defaultRemoteConfiguration, self.remoteLoggingConstraintsProvider == nil {
self.remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider(
endpoint: remoteConfig.endpoint,
region: configuration.region,
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds)
}

self.loggingClient = AWSCloudWatchLoggingCategoryClient(
enable: configuration.enable,
credentialsProvider: authService.getCredentialsProvider(),
Expand All @@ -136,7 +136,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
flushIntervalInSeconds: configuration.flushIntervalInSeconds
)
}

if self.loggingPluginConfiguration == nil {
throw LoggingError.configuration(
"""
Expand All @@ -149,12 +149,12 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
"""
)
}

if self.remoteLoggingConstraintsProvider == nil {
let localStore: LoggingConstraintsLocalStore = UserDefaults.standard
localStore.reset()
}

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
self.loggingClient.takeUserIdentifierFromCurrentUser()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ extension AWSCloudWatchLoggingSession: LogBatchProducer {
}

extension AWSCloudWatchLoggingError {
static let sessionInternalErrorForUserId = AWSCloudWatchLoggingError(errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: "")
static let sessionInternalErrorForUserId = AWSCloudWatchLoggingError(
errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: "")
}
Loading

0 comments on commit a059f5c

Please sign in to comment.