Skip to content

Commit 5431edf

Browse files
authored
fix(Logging): fix concurrency issues with logLevel (#1431)
1 parent 12d140d commit 5431edf

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Amplify/Categories/Logging/LoggingCategory.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ final public class LoggingCategory: Category {
2222

2323
let concurrencyQueue = DispatchQueue(label: "com.amazonaws.Amplify.Logging.concurrency",
2424
target: DispatchQueue.global())
25+
let lock: NSLocking = NSLock()
2526

2627
public let categoryType = CategoryType.logging
2728

29+
private var _logLevel = LogLevel.error
30+
2831
/// The global logLevel. Messages logged at a priority less than or equal to this value will be logged (e.g., if
2932
/// `logLevel` is set to `.info`, then messages sent at `.error`, `.warn`, and `.info` will be logged, but messages
3033
/// at `.debug` and `.verbose` will not be logged. The global log level is also used for the default logger
@@ -38,7 +41,18 @@ final public class LoggingCategory: Category {
3841
/// viewLogger.info("A view loaded") // Will not be logged
3942
/// networkLogger.info("A network operation started") // Will be logged
4043
/// ```
41-
public var logLevel = LogLevel.error
44+
public var logLevel: LogLevel {
45+
get {
46+
lock.execute {
47+
_logLevel
48+
}
49+
}
50+
set {
51+
lock.execute {
52+
_logLevel = newValue
53+
}
54+
}
55+
}
4256

4357
var configurationState = ConfigurationState.default
4458

0 commit comments

Comments
 (0)