diff --git a/Swift/ConsoleLogger.swift b/Swift/ConsoleLogger.swift index 8c4b70f37..7cd7ae652 100644 --- a/Swift/ConsoleLogger.swift +++ b/Swift/ConsoleLogger.swift @@ -20,6 +20,33 @@ import Foundation /// Console logger for writing log messages to the system console. + +/// Log domain options that can be enabled in the console logger. +public struct LogDomains: OptionSet { + /// Raw value. + public let rawValue: Int + + /// Constructor with the raw value. + public init(rawValue: Int) { + self.rawValue = rawValue + } + + /// All domains. + public static let all = LogDomains(rawValue: Int(LogDomain.all.rawValue)) + + /// Database domain. + public static let database = LogDomains(rawValue: Int(LogDomain.database.rawValue)) + + /// Database domain. + public static let query = LogDomains(rawValue: Int(LogDomain.query.rawValue)) + + /// Replicator domain. + public static let replicator = LogDomains(rawValue: Int(LogDomain.replicator.rawValue)) + + /// Network domain. + public static let network = LogDomains(rawValue: Int(LogDomain.network.rawValue)) +} + public class ConsoleLogger { /// The minimum log level of the log messages to be logged. The default log level for @@ -32,13 +59,9 @@ public class ConsoleLogger { /// The set of log domains of the log messages to be logged. By default, the log /// messages of all domains will be logged. - public var domains: Set = [.all] { + public var domains: LogDomains = .all { didSet { - var domain: UInt8 = 0 - for d in domains { - domain = domain | d.rawValue - } - CBLDatabase.log().console.domains = CBLLogDomain(rawValue: UInt(domain)) + CBLDatabase.log().console.domains = CBLLogDomain(rawValue: UInt(domains.rawValue)) } } diff --git a/Swift/Tests/LogTest.swift b/Swift/Tests/LogTest.swift index f44f07799..a5ffab96b 100644 --- a/Swift/Tests/LogTest.swift +++ b/Swift/Tests/LogTest.swift @@ -337,7 +337,7 @@ class LogTest: CBLTestCase { let customLogger = LogTestLogger() customLogger.level = .verbose Database.log.custom = customLogger - Database.log.console.domains = [LogDomain.all] + Database.log.console.domains = .all Database.log.console.level = .verbose let hebrew = "מזג האוויר נחמד היום" // The weather is nice today. let doc = MutableDocument()