Skip to content

Commit

Permalink
Change to use OptionSet type for ConsoleLogger.domains (#2349)
Browse files Browse the repository at this point in the history
Instead of using Set<LogDomain>, changed to use OptionSet.
  • Loading branch information
pasin authored Jan 25, 2019
1 parent c0e10b9 commit 8286676
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 29 additions & 6 deletions Swift/ConsoleLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<LogDomain> = [.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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Swift/Tests/LogTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8286676

Please sign in to comment.