mirror of
https://github.com/apple/swift-log
synced 2026-11-30 04:18:44 +00:00
Use Set to spot duplicated log handler warnings. (#306)
Motivation: Feels like a better fit for the problem when a dictionary of bools. Modifications: Convert storage to set. Result: Fewer lines of code, less waste.
This commit is contained in:
1 parent
23517234d5
commit
0f170b4764
1 file changed
+3
-7
@@ -1347,17 +1347,13 @@ extension Logger.MetadataValue: ExpressibleByArrayLiteral {
|
||||
/// Contains state to manage all kinds of "warn only once" warnings which the logging system may want to issue.
|
||||
private final class WarnOnceBox {
|
||||
private let lock: Lock = Lock()
|
||||
private var warnOnceLogHandlerNotSupportedMetadataProviderPerType: [ObjectIdentifier: Bool] = [:]
|
||||
private var warnOnceLogHandlerNotSupportedMetadataProviderPerType = Set<ObjectIdentifier>()
|
||||
|
||||
func warnOnceLogHandlerNotSupportedMetadataProvider<Handler: LogHandler>(type: Handler.Type) -> Bool {
|
||||
self.lock.withLock {
|
||||
let id = ObjectIdentifier(type)
|
||||
if warnOnceLogHandlerNotSupportedMetadataProviderPerType[id] ?? false {
|
||||
return false // don't warn, it was already warned about
|
||||
} else {
|
||||
warnOnceLogHandlerNotSupportedMetadataProviderPerType[id] = true
|
||||
return true // warn about this handler type, it is the first time we encountered it
|
||||
}
|
||||
let (inserted, _) = warnOnceLogHandlerNotSupportedMetadataProviderPerType.insert(id)
|
||||
return inserted // warn about this handler type, it is the first time we encountered it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user