Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(logging): resolve swiftformat errors and warnings #3850

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// SPDX-License-Identifier: Apache-2.0
//

import AWSPluginsCore
import Amplify
import AWSClientRuntime
import AWSCloudWatchLogs
import AWSPluginsCore
import Combine
import Foundation
import AWSCloudWatchLogs
import AWSClientRuntime
import Network

/// Concrete implementation of
Expand Down Expand Up @@ -57,7 +57,7 @@ final class AWSCloudWatchLoggingCategoryClient {
self.networkMonitor = networkMonitor
self.networkMonitor.startMonitoring(using: DispatchQueue(label: "com.amazonaws.awscloudwatchlogging.networkmonitor"))
self.automaticFlushLogMonitor = AWSCLoudWatchLoggingMonitor(flushIntervalInSeconds: TimeInterval(flushIntervalInSeconds), eventDelegate: self)
self.automaticFlushLogMonitor?.setAutomaticFlushIntervals()
automaticFlushLogMonitor?.setAutomaticFlushIntervals()
self.authSubscription = Amplify.Hub.publisher(for: .auth).sink { [weak self] payload in
self?.handle(payload: payload)
}
Expand Down Expand Up @@ -92,8 +92,8 @@ final class AWSCloudWatchLoggingCategoryClient {
case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue:
takeUserIdentifierFromCurrentUser()
case HubPayload.EventName.Auth.signedOut, CognitoEventName.signOutAPI.rawValue:
self.userIdentifier = nil
self.updateSessionControllers()
userIdentifier = nil
updateSessionControllers()
default:
break
}
Expand Down Expand Up @@ -135,7 +135,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
}

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

func logger(forCategory category: String, namespace: String?, logLevel: Amplify.LogLevel) -> Logger {
Expand All @@ -145,17 +145,19 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
return existing
}

let controller = AWSCloudWatchLoggingSessionController(credentialsProvider: credentialsProvider,
authentication: authentication,
logFilter: self.logFilter,
category: category,
namespace: namespace,
logLevel: logLevel,
logGroupName: self.logGroupName,
region: self.region,
localStoreMaxSizeInMB: self.localStoreMaxSizeInMB,
userIdentifier: self.userIdentifier,
networkMonitor: self.networkMonitor)
let controller = AWSCloudWatchLoggingSessionController(
credentialsProvider: credentialsProvider,
authentication: authentication,
logFilter: self.logFilter,
category: category,
namespace: namespace,
logLevel: logLevel,
logGroupName: self.logGroupName,
region: self.region,
localStoreMaxSizeInMB: self.localStoreMaxSizeInMB,
userIdentifier: self.userIdentifier,
networkMonitor: self.networkMonitor
)
if enabled {
controller.enable()
}
Expand All @@ -165,21 +167,21 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
}

func logger(forCategory category: String, logLevel: LogLevel) -> Logger {
return self.logger(forCategory: category, namespace: nil, logLevel: logLevel)
return 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)
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: userIdentifier)
return logger(forCategory: category, namespace: nil, logLevel: defaultLogLevel)
}

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

func getInternalClient() -> CloudWatchLogsClientProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import Amplify
import AWSCloudWatchLogs
import AWSPluginsCore
import Amplify
import Combine
import Foundation

Expand Down Expand Up @@ -54,7 +54,8 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
self.remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider(
endpoint: remoteConfig.endpoint,
region: configuration.region,
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds)
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds
)
}
}
}
Expand Down Expand Up @@ -114,18 +115,19 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
/// - Throws:
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty
public func configure(using configuration: Any?) throws {
if self.loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) {
self.loggingPluginConfiguration = configuration
if loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) {
loggingPluginConfiguration = configuration
let authService = AWSAuthService()

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

self.loggingClient = AWSCloudWatchLoggingCategoryClient(
loggingClient = AWSCloudWatchLoggingCategoryClient(
enable: configuration.enable,
credentialsProvider: authService.getCredentialsProvider(),
authentication: Amplify.Auth,
Expand All @@ -137,7 +139,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
)
}

if self.loggingPluginConfiguration == nil {
if loggingPluginConfiguration == nil {
throw LoggingError.configuration(
"""
Missing configuration for AWSCloudWatchLoggingPlugin
Expand All @@ -150,7 +152,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
)
}

if self.remoteLoggingConstraintsProvider == nil {
if remoteLoggingConstraintsProvider == nil {
let localStore: LoggingConstraintsLocalStore = UserDefaults.standard
localStore.reset()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ final class AWSCloudWatchLoggingSession {
self.category = category
self.namespace = namespace
self.userIdentifier = userIdentifier
self.logger = try Self.createLogger(category: category,
namespace: namespace,
logLevel: logLevel,
userIdentifier: userIdentifier,
localStoreMaxSizeInMB: localStoreMaxSizeInMB)
self.logger = try Self.createLogger(
category: category,
namespace: namespace,
logLevel: logLevel,
userIdentifier: userIdentifier,
localStoreMaxSizeInMB: localStoreMaxSizeInMB
)
}

private static func createLogger(
Expand All @@ -43,12 +45,14 @@ final class AWSCloudWatchLoggingSession {
let directory = try directory(for: category, userIdentifier: userIdentifier)
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
try (directory as NSURL).setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1048576
return try RotatingLogger(directory: directory,
category: category,
namespace: namespace,
logLevel: logLevel,
fileSizeLimitInBytes: cacheMaxSizeInBytes)
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1_048_576
return try RotatingLogger(
directory: directory,
category: category,
namespace: namespace,
logLevel: logLevel,
fileSizeLimitInBytes: cacheMaxSizeInBytes
)
}

private static func directory(for category: String, userIdentifier: String?, fileManager: FileManager = .default) throws -> URL {
Expand All @@ -64,7 +68,7 @@ final class AWSCloudWatchLoggingSession {
}

private static func normalized(userIdentifier: String?) throws -> String {
guard let userIdentifier = userIdentifier else {
guard let userIdentifier else {
return "guest"
}

Expand All @@ -85,5 +89,6 @@ extension AWSCloudWatchLoggingSession: LogBatchProducer {

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