Skip to content

Commit 748755e

Browse files
authored
chore(logging): resolve swiftformat errors and warnings (#3850)
* chore(logging): resolve swiftformat errors and warnings * updated swiftformat rules
1 parent e75d0e1 commit 748755e

File tree

46 files changed

+627
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+627
-538
lines changed

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import AWSPluginsCore
98
import Amplify
9+
import AWSClientRuntime
10+
import AWSCloudWatchLogs
11+
import AWSPluginsCore
1012
import Combine
1113
import Foundation
12-
import AWSCloudWatchLogs
13-
import AWSClientRuntime
1414
import Network
1515

1616
/// Concrete implementation of
@@ -57,7 +57,7 @@ final class AWSCloudWatchLoggingCategoryClient {
5757
self.networkMonitor = networkMonitor
5858
self.networkMonitor.startMonitoring(using: DispatchQueue(label: "com.amazonaws.awscloudwatchlogging.networkmonitor"))
5959
self.automaticFlushLogMonitor = AWSCLoudWatchLoggingMonitor(flushIntervalInSeconds: TimeInterval(flushIntervalInSeconds), eventDelegate: self)
60-
self.automaticFlushLogMonitor?.setAutomaticFlushIntervals()
60+
automaticFlushLogMonitor?.setAutomaticFlushIntervals()
6161
self.authSubscription = Amplify.Hub.publisher(for: .auth).sink { [weak self] payload in
6262
self?.handle(payload: payload)
6363
}
@@ -92,8 +92,8 @@ final class AWSCloudWatchLoggingCategoryClient {
9292
case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue:
9393
takeUserIdentifierFromCurrentUser()
9494
case HubPayload.EventName.Auth.signedOut, CognitoEventName.signOutAPI.rawValue:
95-
self.userIdentifier = nil
96-
self.updateSessionControllers()
95+
userIdentifier = nil
96+
updateSessionControllers()
9797
default:
9898
break
9999
}
@@ -135,7 +135,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
135135
}
136136

137137
var `default`: Logger {
138-
return self.logger(forCategory: "Amplify")
138+
return logger(forCategory: "Amplify")
139139
}
140140

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

148-
let controller = AWSCloudWatchLoggingSessionController(credentialsProvider: credentialsProvider,
149-
authentication: authentication,
150-
logFilter: self.logFilter,
151-
category: category,
152-
namespace: namespace,
153-
logLevel: logLevel,
154-
logGroupName: self.logGroupName,
155-
region: self.region,
156-
localStoreMaxSizeInMB: self.localStoreMaxSizeInMB,
157-
userIdentifier: self.userIdentifier,
158-
networkMonitor: self.networkMonitor)
148+
let controller = AWSCloudWatchLoggingSessionController(
149+
credentialsProvider: credentialsProvider,
150+
authentication: authentication,
151+
logFilter: self.logFilter,
152+
category: category,
153+
namespace: namespace,
154+
logLevel: logLevel,
155+
logGroupName: self.logGroupName,
156+
region: self.region,
157+
localStoreMaxSizeInMB: self.localStoreMaxSizeInMB,
158+
userIdentifier: self.userIdentifier,
159+
networkMonitor: self.networkMonitor
160+
)
159161
if enabled {
160162
controller.enable()
161163
}
@@ -165,21 +167,21 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior {
165167
}
166168

167169
func logger(forCategory category: String, logLevel: LogLevel) -> Logger {
168-
return self.logger(forCategory: category, namespace: nil, logLevel: logLevel)
170+
return logger(forCategory: category, namespace: nil, logLevel: logLevel)
169171
}
170172

171173
func logger(forCategory category: String) -> Logger {
172-
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier)
173-
return self.logger(forCategory: category, namespace: nil, logLevel: defaultLogLevel)
174+
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: userIdentifier)
175+
return logger(forCategory: category, namespace: nil, logLevel: defaultLogLevel)
174176
}
175177

176178
func logger(forNamespace namespace: String) -> Logger {
177-
self.logger(forCategory: namespace)
179+
logger(forCategory: namespace)
178180
}
179181

180182
func logger(forCategory category: String, forNamespace namespace: String) -> Logger {
181-
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier)
182-
return self.logger(forCategory: category, namespace: namespace, logLevel: defaultLogLevel)
183+
let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: userIdentifier)
184+
return logger(forCategory: category, namespace: namespace, logLevel: defaultLogLevel)
183185
}
184186

185187
func getInternalClient() -> CloudWatchLogsClientProtocol {

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
import Amplify
89
import AWSCloudWatchLogs
910
import AWSPluginsCore
10-
import Amplify
1111
import Combine
1212
import Foundation
1313

@@ -54,7 +54,8 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
5454
self.remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider(
5555
endpoint: remoteConfig.endpoint,
5656
region: configuration.region,
57-
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds)
57+
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds
58+
)
5859
}
5960
}
6061
}
@@ -114,18 +115,19 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
114115
/// - Throws:
115116
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty
116117
public func configure(using configuration: Any?) throws {
117-
if self.loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) {
118-
self.loggingPluginConfiguration = configuration
118+
if loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) {
119+
loggingPluginConfiguration = configuration
119120
let authService = AWSAuthService()
120121

121-
if let remoteConfig = configuration.defaultRemoteConfiguration, self.remoteLoggingConstraintsProvider == nil {
122-
self.remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider(
122+
if let remoteConfig = configuration.defaultRemoteConfiguration, remoteLoggingConstraintsProvider == nil {
123+
remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider(
123124
endpoint: remoteConfig.endpoint,
124125
region: configuration.region,
125-
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds)
126+
refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds
127+
)
126128
}
127129

128-
self.loggingClient = AWSCloudWatchLoggingCategoryClient(
130+
loggingClient = AWSCloudWatchLoggingCategoryClient(
129131
enable: configuration.enable,
130132
credentialsProvider: authService.getCredentialsProvider(),
131133
authentication: Amplify.Auth,
@@ -137,7 +139,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
137139
)
138140
}
139141

140-
if self.loggingPluginConfiguration == nil {
142+
if loggingPluginConfiguration == nil {
141143
throw LoggingError.configuration(
142144
"""
143145
Missing configuration for AWSCloudWatchLoggingPlugin
@@ -150,7 +152,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
150152
)
151153
}
152154

153-
if self.remoteLoggingConstraintsProvider == nil {
155+
if remoteLoggingConstraintsProvider == nil {
154156
let localStore: LoggingConstraintsLocalStore = UserDefaults.standard
155157
localStore.reset()
156158
}

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ final class AWSCloudWatchLoggingSession {
2525
self.category = category
2626
self.namespace = namespace
2727
self.userIdentifier = userIdentifier
28-
self.logger = try Self.createLogger(category: category,
29-
namespace: namespace,
30-
logLevel: logLevel,
31-
userIdentifier: userIdentifier,
32-
localStoreMaxSizeInMB: localStoreMaxSizeInMB)
28+
self.logger = try Self.createLogger(
29+
category: category,
30+
namespace: namespace,
31+
logLevel: logLevel,
32+
userIdentifier: userIdentifier,
33+
localStoreMaxSizeInMB: localStoreMaxSizeInMB
34+
)
3335
}
3436

3537
private static func createLogger(
@@ -43,12 +45,14 @@ final class AWSCloudWatchLoggingSession {
4345
let directory = try directory(for: category, userIdentifier: userIdentifier)
4446
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
4547
try (directory as NSURL).setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
46-
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1048576
47-
return try RotatingLogger(directory: directory,
48-
category: category,
49-
namespace: namespace,
50-
logLevel: logLevel,
51-
fileSizeLimitInBytes: cacheMaxSizeInBytes)
48+
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1_048_576
49+
return try RotatingLogger(
50+
directory: directory,
51+
category: category,
52+
namespace: namespace,
53+
logLevel: logLevel,
54+
fileSizeLimitInBytes: cacheMaxSizeInBytes
55+
)
5256
}
5357

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

6670
private static func normalized(userIdentifier: String?) throws -> String {
67-
guard let userIdentifier = userIdentifier else {
71+
guard let userIdentifier else {
6872
return "guest"
6973
}
7074

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

8690
extension AWSCloudWatchLoggingError {
8791
static let sessionInternalErrorForUserId = AWSCloudWatchLoggingError(
88-
errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: "")
92+
errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: ""
93+
)
8994
}

0 commit comments

Comments
 (0)