Extract log config to a function and base log level on wg level.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
88d84f702b
commit
0c19d713f2
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue