From a6f80135ef65f33da67459b56c7f659c64d6d341 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 17 Mar 2019 00:41:10 -0600 Subject: ringlogger: support mpsc for singlefile Signed-off-by: Jason A. Donenfeld --- WireGuard/Shared/Logging/Logger.swift | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'WireGuard/Shared/Logging/Logger.swift') diff --git a/WireGuard/Shared/Logging/Logger.swift b/WireGuard/Shared/Logging/Logger.swift index 23cc719..345fc10 100644 --- a/WireGuard/Shared/Logging/Logger.swift +++ b/WireGuard/Shared/Logging/Logger.swift @@ -12,10 +12,12 @@ public class Logger { static var global: Logger? var log: OpaquePointer + var tag: String - init(withFilePath filePath: String) throws { + init(tagged tag: String, withFilePath filePath: String) throws { guard let log = open_log(filePath) else { throw LoggerError.openFailure } self.log = log + self.tag = tag } deinit { @@ -23,17 +25,14 @@ public class Logger { } func log(message: String) { - write_msg_to_log(log, message.trimmingCharacters(in: .newlines)) + write_msg_to_log(log, tag, message.trimmingCharacters(in: .newlines)) } - func writeLog(called ourTag: String, mergedWith otherLogFile: String, called otherTag: String, to targetFile: String) -> Bool { - guard let other = open_log(otherLogFile) else { return false } - let ret = write_logs_to_file(targetFile, log, ourTag, other, otherTag) - close_log(other) - return ret == 0 + func writeLog(to targetFile: String) -> Bool { + return write_log_to_file(targetFile, self.log) == 0 } - static func configureGlobal(withFilePath filePath: String?) { + static func configureGlobal(tagged tag: String, withFilePath filePath: String?) { if Logger.global != nil { return } @@ -41,7 +40,7 @@ public class Logger { os_log("Unable to determine log destination path. Log will not be saved to file.", log: OSLog.default, type: .error) return } - guard let logger = try? Logger(withFilePath: filePath) else { + guard let logger = try? Logger(tagged: tag, withFilePath: filePath) else { os_log("Unable to open log file for writing. Log will not be saved to file.", log: OSLog.default, type: .error) return } @@ -52,7 +51,6 @@ public class Logger { } let goBackendVersion = WIREGUARD_GO_VERSION Logger.global?.log(message: "App version: \(appVersion); Go backend version: \(goBackendVersion)") - } } -- cgit v1.2.3-59-g8ed1b