NE: Logging: Make it clear which calls to wg_log use String and which use StaticString
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
4e386e85e4
commit
bf86731879
|
@ -42,7 +42,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
// Configure logging
|
// Configure logging
|
||||||
configureLogger()
|
configureLogger()
|
||||||
|
|
||||||
wg_log(.info, "Starting tunnel")
|
wg_log(.info, staticMessage: "Starting tunnel")
|
||||||
|
|
||||||
// Resolve endpoint domains
|
// Resolve endpoint domains
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
do {
|
do {
|
||||||
resolvedEndpoints = try DNSResolver.resolveSync(endpoints: endpoints)
|
resolvedEndpoints = try DNSResolver.resolveSync(endpoints: endpoints)
|
||||||
} catch DNSResolverError.dnsResolutionFailed(let hostnames) {
|
} catch DNSResolverError.dnsResolutionFailed(let hostnames) {
|
||||||
wg_log(.error, "Starting tunnel failed: DNS resolution failure")
|
wg_log(.error, staticMessage: "Starting tunnel failed: DNS resolution failure")
|
||||||
wg_log(.error, "Hostnames for which DNS resolution failed: \(hostnames.joined(separator: ", "))")
|
wg_log(.error, message: "Hostnames for which DNS resolution failed: \(hostnames.joined(separator: ", "))")
|
||||||
ErrorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames), from: self)
|
ErrorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames), from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
|
startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
|
||||||
return
|
return
|
||||||
|
@ -71,7 +71,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
let fd = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32
|
let fd = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32
|
||||||
if fd < 0 {
|
if fd < 0 {
|
||||||
wg_log(.error, "Starting tunnel failed: Could not determine file descriptor")
|
wg_log(.error, staticMessage: "Starting tunnel failed: Could not determine file descriptor")
|
||||||
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
||||||
return
|
return
|
||||||
|
@ -81,7 +81,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
let handle = connect(interfaceName: tunnelConfiguration.interface.name, settings: wireguardSettings, fd: fd)
|
let handle = connect(interfaceName: tunnelConfiguration.interface.name, settings: wireguardSettings, fd: fd)
|
||||||
|
|
||||||
if handle < 0 {
|
if handle < 0 {
|
||||||
wg_log(.error, "Starting tunnel failed: Could not start WireGuard")
|
wg_log(.error, staticMessage: "Starting tunnel failed: Could not start WireGuard")
|
||||||
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
|
||||||
return
|
return
|
||||||
|
@ -94,8 +94,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
let networkSettings: NEPacketTunnelNetworkSettings = packetTunnelSettingsGenerator.generateNetworkSettings()
|
let networkSettings: NEPacketTunnelNetworkSettings = packetTunnelSettingsGenerator.generateNetworkSettings()
|
||||||
setTunnelNetworkSettings(networkSettings) { (error) in
|
setTunnelNetworkSettings(networkSettings) { (error) in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
wg_log(.error, "Starting tunnel failed: Error setting network settings.")
|
wg_log(.error, staticMessage: "Starting tunnel failed: Error setting network settings.")
|
||||||
wg_log(.error, "Error from setTunnelNetworkSettings: \(error.localizedDescription)")
|
wg_log(.error, message: "Error from setTunnelNetworkSettings: \(error.localizedDescription)")
|
||||||
ErrorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings, from: self)
|
ErrorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings, from: self)
|
||||||
startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
|
startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,7 +106,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
/// Begin the process of stopping the tunnel.
|
/// Begin the process of stopping the tunnel.
|
||||||
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||||
wg_log(.info, "Stopping tunnel")
|
wg_log(.info, staticMessage: "Stopping tunnel")
|
||||||
if let handle = wgHandle {
|
if let handle = wgHandle {
|
||||||
wgTurnOff(handle)
|
wgTurnOff(handle)
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
logType = .default
|
logType = .default
|
||||||
}
|
}
|
||||||
let msg = (msgCStr != nil) ? String(cString: msgCStr!) : ""
|
let msg = (msgCStr != nil) ? String(cString: msgCStr!) : ""
|
||||||
wg_log(logType, msg)
|
wg_log(logType, message: msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ private func withStringsAsGoStrings<R>(_ str1: String, _ str2: String, closure:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func wg_log(_ type: OSLogType, _ msg: StaticString) {
|
private func wg_log(_ type: OSLogType, staticMessage msg: StaticString) {
|
||||||
// Write to os log
|
// Write to os log
|
||||||
os_log(msg, log: OSLog.default, type: type)
|
os_log(msg, log: OSLog.default, type: type)
|
||||||
// Write to file log
|
// Write to file log
|
||||||
|
@ -179,7 +179,7 @@ private func wg_log(_ type: OSLogType, _ msg: StaticString) {
|
||||||
file_log(type: type, message: msgString)
|
file_log(type: type, message: msgString)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func wg_log(_ type: OSLogType, _ msg: String) {
|
private func wg_log(_ type: OSLogType, message msg: String) {
|
||||||
// Write to os log
|
// Write to os log
|
||||||
os_log("%{public}s", log: OSLog.default, type: type, msg)
|
os_log("%{public}s", log: OSLog.default, type: type, msg)
|
||||||
// Write to file log
|
// Write to file log
|
||||||
|
|
Loading…
Reference in New Issue