Skip to content

Commit c130105

Browse files
authored
chore: kickoff release
2 parents ce87564 + ef085ad commit c130105

File tree

7 files changed

+56
-15
lines changed

7 files changed

+56
-15
lines changed

Amplify/Categories/Logging/LogLevel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
///
1010
public extension Amplify {
1111
enum LogLevel: Int, Codable {
12+
case none
1213
case error
1314
case warn
1415
case info
1516
case debug
1617
case verbose
17-
case none
1818

1919
public init(from decoder: Decoder) throws {
2020
let container = try decoder.singleValueContainer()

Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/OSLogWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ final class OSLogWrapper: Logger {
2929
}
3030

3131
public func error(_ message: @autoclosure () -> String) {
32-
guard enabled else { return }
32+
guard enabled, logLevel.rawValue >= LogLevel.error.rawValue else { return }
3333
os_log("%@",
3434
log: osLog,
3535
type: OSLogType.error,
3636
message())
3737
}
3838

3939
public func error(error: Error) {
40-
guard enabled else { return }
40+
guard enabled, logLevel.rawValue >= LogLevel.error.rawValue else { return }
4141
os_log("%@",
4242
log: osLog,
4343
type: OSLogType.error,

AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginTests/AWSCloudWatchLoggingPluginConfigurationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
@testable import AWSCloudWatchLoggingPlugin
9-
9+
import Amplify
1010
import XCTest
1111

1212
final class AWSCloudWatchLoggingPluginConfigurationTests: XCTestCase {
@@ -36,7 +36,7 @@ final class AWSCloudWatchLoggingPluginConfigurationTests: XCTestCase {
3636
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.localStoreMaxSizeInMB, 5)
3737
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.logGroupName, "testLogGroup")
3838
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.region, "us-east-1")
39-
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.loggingConstraints.defaultLogLevel.rawValue, 0)
39+
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.loggingConstraints.defaultLogLevel.rawValue, LogLevel.error.rawValue)
4040
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.loggingConstraints.categoryLogLevel?.count, 2)
4141
XCTAssertEqual(config.awsCloudWatchLoggingPlugin.loggingConstraints.userLogLevel?.count, 1)
4242
}
@@ -56,9 +56,9 @@ final class AWSCloudWatchLoggingPluginConfigurationTests: XCTestCase {
5656
XCTFail("Unable to decode from data")
5757
return
5858
}
59-
XCTAssertEqual(loggingConstraints.defaultLogLevel.rawValue, 0)
59+
XCTAssertEqual(loggingConstraints.defaultLogLevel.rawValue, LogLevel.error.rawValue)
6060
XCTAssertEqual(loggingConstraints.categoryLogLevel?.count, 4)
6161
XCTAssertEqual(loggingConstraints.userLogLevel?.count, 2)
62-
XCTAssertEqual(loggingConstraints.userLogLevel?["sub1"]?.defaultLogLevel.rawValue, 2)
62+
XCTAssertEqual(loggingConstraints.userLogLevel?["sub1"]?.defaultLogLevel.rawValue, LogLevel.info.rawValue)
6363
}
6464
}

AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginTests/AWSCloudWatchLoggingPluginTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@testable import AWSCloudWatchLoggingPlugin
99

1010
import XCTest
11+
import Amplify
1112

1213
final class AWSCloudWatchLoggingPluginTests: XCTestCase {
1314

@@ -33,16 +34,16 @@ final class AWSCloudWatchLoggingPluginTests: XCTestCase {
3334
let configuration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "testLogGroup", region: "us-east-1")
3435
let plugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: configuration)
3536
var authLogger = plugin.logger(forCategory: "Auth")
36-
XCTAssertEqual(authLogger.logLevel.rawValue, 0)
37-
37+
XCTAssertEqual(authLogger.logLevel.rawValue, LogLevel.error.rawValue)
38+
3839
authLogger = plugin.logger(forCategory: "Auth", forNamespace: "test")
39-
XCTAssertEqual(authLogger.logLevel.rawValue, 0)
40+
XCTAssertEqual(authLogger.logLevel.rawValue, LogLevel.error.rawValue)
4041

4142
let apiLogger = plugin.logger(forCategory: "API", logLevel: .debug)
42-
XCTAssertEqual(apiLogger.logLevel.rawValue, 3)
43+
XCTAssertEqual(apiLogger.logLevel.rawValue, LogLevel.debug.rawValue)
4344

4445
let defaultLogger = plugin.logger(forNamespace: "test")
45-
XCTAssertEqual(defaultLogger.logLevel.rawValue, 0)
46+
XCTAssertEqual(defaultLogger.logLevel.rawValue, LogLevel.error.rawValue)
4647
}
4748

4849
/// Given: a AWSCloudWatchLoggingPlugin

AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginTests/LoggingConstraintsLocalStoreTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class LoggingConstraintsLocalStoreTests: XCTestCase {
4343
localStore.setLocalLoggingConstraints(loggingConstraints: loggingConstraints)
4444

4545
XCTAssertEqual(localStore.getLocalLoggingConstraintsEtag(), "testString")
46-
XCTAssertEqual(localStore.getLocalLoggingConstraints()!.defaultLogLevel.rawValue, 0)
46+
XCTAssertEqual(localStore.getLocalLoggingConstraints()!.defaultLogLevel.rawValue, LogLevel.error.rawValue)
4747
XCTAssertTrue(localStore.getLocalLoggingConstraints()!.categoryLogLevel!.isEmpty)
4848
XCTAssertTrue(localStore.getLocalLoggingConstraints()!.userLogLevel!.isEmpty)
4949
}
@@ -60,7 +60,7 @@ final class LoggingConstraintsLocalStoreTests: XCTestCase {
6060
localStore.setLocalLoggingConstraints(loggingConstraints: loggingConstraints)
6161

6262
XCTAssertEqual(localStore.getLocalLoggingConstraintsEtag(), "testString")
63-
XCTAssertEqual(localStore.getLocalLoggingConstraints()?.defaultLogLevel.rawValue, 1)
63+
XCTAssertEqual(localStore.getLocalLoggingConstraints()?.defaultLogLevel.rawValue, LogLevel.warn.rawValue)
6464
XCTAssertEqual(localStore.getLocalLoggingConstraints()!.categoryLogLevel!.count, 1)
6565
XCTAssertTrue(localStore.getLocalLoggingConstraints()!.userLogLevel!.isEmpty)
6666
}

AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginTests/RotatingLogBatchTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import Foundation
9+
import Amplify
910
import XCTest
1011

1112
@testable import AWSCloudWatchLoggingPlugin
@@ -43,7 +44,7 @@ final class RotatingLogBatchTests: XCTestCase {
4344
let entries = try? rotatingLogBatch.readEntries()
4445
XCTAssertEqual(entries?.count, 1)
4546
XCTAssertEqual(entries![0].category, "Auth")
46-
XCTAssertEqual(entries![0].logLevel.rawValue, 0)
47+
XCTAssertEqual(entries![0].logLevel.rawValue, LogLevel.error.rawValue)
4748
XCTAssertEqual(entries![0].message, "error message")
4849
XCTAssertEqual(entries![0].namespace, "namespace")
4950
}

AmplifyTests/CategoryTests/Logging/DefaultLoggingPluginTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,43 @@ class DefaultLoggingPluginTests: XCTestCase {
155155
globalMessageCorrectlyEvaluated],
156156
timeout: 0.1)
157157
}
158+
159+
/// - Given: default configuration
160+
/// - When:
161+
/// - set logLevel to .none
162+
/// - Then:
163+
/// - no log is recorded
164+
func testLoggerWithNoneLogLevel_noLogsAreRecorded() async {
165+
Amplify.Logging.logLevel = .none
166+
167+
let errorMessageIncorrectlyEvaluated = expectation(description: "error message was incorrectly evaluated")
168+
errorMessageIncorrectlyEvaluated.isInverted = true
169+
Amplify.Logging.error("error \(errorMessageIncorrectlyEvaluated.fulfill())")
170+
171+
let warnMessageIncorrectlyEvaluated = expectation(description: "warn message was incorrectly evaluated")
172+
warnMessageIncorrectlyEvaluated.isInverted = true
173+
Amplify.Logging.warn("warn \(warnMessageIncorrectlyEvaluated.fulfill())")
174+
175+
let infoMessageIncorrectlyEvaluated = expectation(description: "info message was incorrectly evaluated")
176+
infoMessageIncorrectlyEvaluated.isInverted = true
177+
Amplify.Logging.info("info \(infoMessageIncorrectlyEvaluated.fulfill())")
178+
179+
let debugMessageIncorrectlyEvaluated = expectation(description: "debug message was incorrectly evaluated")
180+
debugMessageIncorrectlyEvaluated.isInverted = true
181+
Amplify.Logging.debug("debug \(debugMessageIncorrectlyEvaluated.fulfill())")
182+
183+
let verboseMessageIncorrectlyEvaluated = expectation(description: "verbose message was incorrectly evaluated")
184+
verboseMessageIncorrectlyEvaluated.isInverted = true
185+
Amplify.Logging.verbose("verbose \(verboseMessageIncorrectlyEvaluated.fulfill())")
186+
await fulfillment(
187+
of: [
188+
errorMessageIncorrectlyEvaluated,
189+
warnMessageIncorrectlyEvaluated,
190+
infoMessageIncorrectlyEvaluated,
191+
debugMessageIncorrectlyEvaluated,
192+
verboseMessageIncorrectlyEvaluated
193+
],
194+
timeout: 0.3
195+
)
196+
}
158197
}

0 commit comments

Comments
 (0)