diff options
author | 2018-08-28 14:03:53 +0200 | |
---|---|---|
committer | 2018-08-28 14:03:53 +0200 | |
commit | 0c19d713f29c4c623f11f53350e460afc030398b (patch) | |
tree | 41714d77c0a085a618e9483c56f2a7f963b87b03 | |
parent | Make wgContext lazy. (diff) | |
download | wireguard-apple-0c19d713f29c4c623f11f53350e460afc030398b.tar.xz wireguard-apple-0c19d713f29c4c623f11f53350e460afc030398b.zip |
Extract log config to a function and base log level on wg level.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuardNetworkExtension/PacketTunnelProvider.swift | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index 4734eac..b7a481e 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -42,15 +42,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider { guard let firstEndpoint = validatedEndpoints.first else { startTunnelCompletionHandler(PacketTunnelProviderError.tunnelSetupFailed) return - - } - - wgSetLogger { (level, tagCStr, msgCStr) in - let tag = (tagCStr != nil) ? String(cString: tagCStr!) : "" - let msg = (msgCStr != nil) ? String(cString: msgCStr!) : "" - NSLog("wg log: \(level): \(tag): \(msg)") } + configureLogger() let handle = withStringsAsGoStrings(interfaceName, settings) { (nameGoStr, settingsGoStr) -> Int32 in return withUnsafeMutablePointer(to: &wgContext) { (wgCtxPtr) -> Int32 in @@ -167,6 +161,26 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let responseData = "Hello app".data(using: String.Encoding.utf8) completionHandler?(responseData) } + + private func configureLogger() { + wgSetLogger { (level, tagCStr, msgCStr) in + let logType: OSLogType + switch level { + case 0: + logType = .debug + case 1: + logType = .info + case 2: + logType = .error + default: + logType = .default + } + let tag = (tagCStr != nil) ? String(cString: tagCStr!) : "" + let msg = (msgCStr != nil) ? String(cString: msgCStr!) : "" + os_log("wg log: %{public}s: %{public}s", log: Log.general, type: logType, tag, msg) + } + } + } class WireGuardContext { |