aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-13 15:26:04 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-13 18:06:37 +0100
commit642b627d277cdb30b91682ba29b5c3a226d607d9 (patch)
tree2df2a73a01f7123b313ed3c23950b1437f934fff /WireGuard/WireGuard
parentMore reliable logo sizing (diff)
downloadwireguard-apple-642b627d277cdb30b91682ba29b5c3a226d607d9.tar.xz
wireguard-apple-642b627d277cdb30b91682ba29b5c3a226d607d9.zip
Rewrite Logger
This reverts all of Roop's changes to the C code, and then rewrites the logger logic to be cleaner. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/AppDelegate.swift12
-rw-r--r--WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift6
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift27
3 files changed, 8 insertions, 37 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
index a5856e0..32c1286 100644
--- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
@@ -12,17 +12,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
-
- if let appLogFilePath = FileManager.appLogFileURL?.path {
- if !Logger.configure(withFilePath: appLogFilePath) {
- os_log("Can't open log file for writing. Log is not saved to file.", log: OSLog.default, type: .error)
- }
- } else {
- os_log("Can't obtain log file URL. Log is not saved to file.", log: OSLog.default, type: .error)
- }
-
- wg_log(.info, message: "Launching app")
- wg_log_versions_to_file()
+ Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path, withTag: "APP")
let window = UIWindow(frame: UIScreen.main.bounds)
window.backgroundColor = UIColor.white
diff --git a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
index 2d17224..af9893d 100644
--- a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
@@ -115,13 +115,13 @@ class SettingsTableViewController: UITableViewController {
}
guard let networkExtensionLogFilePath = FileManager.networkExtensionLogFileURL?.path else {
- ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Internal error obtaining extension log path", from: self)
+ ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Unable to determine extension log path", from: self)
return
}
- let isWritten = Logger.writeLog(mergedWith: networkExtensionLogFilePath, tag: "APP", otherTag: "EXT", to: destinationURL.path)
+ let isWritten = Logger.global?.writeLog(mergedWith: networkExtensionLogFilePath, to: destinationURL.path) ?? false
guard isWritten else {
- ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Internal error merging logs", from: self)
+ ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Unable to write logs to file", from: self)
return
}
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index 03da7bb..65400e0 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -13,8 +13,6 @@ enum PacketTunnelProviderError: Error {
case coultNotSetNetworkSettings
}
-private var logFileHandle: FileHandle?
-
/// A packet tunnel provider object.
class PacketTunnelProvider: NEPacketTunnelProvider {
@@ -45,13 +43,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
func startTunnel(with tunnelConfiguration: TunnelConfiguration, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
- // Configure logging
configureLogger()
wg_log(.info, message: "Starting tunnel '\(tunnelConfiguration.interface.name)'")
- wg_log_versions_to_file()
-
- // Resolve endpoint domains
let endpoints = tunnelConfiguration.peers.map { $0.endpoint }
var resolvedEndpoints = [Endpoint?]()
@@ -141,25 +135,13 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
if let handle = wgHandle {
wgTurnOff(handle)
}
- if let fileHandle = logFileHandle {
- fileHandle.closeFile()
- }
completionHandler()
}
private func configureLogger() {
-
- // Setup writing the log to a file
- if let networkExtensionLogFilePath = FileManager.networkExtensionLogFileURL?.path {
- if !Logger.configure(withFilePath: networkExtensionLogFilePath) {
- os_log("Can't open log file for writing. Log is not saved to file.", log: OSLog.default, type: .error)
- }
- } else {
- os_log("Can't obtain log file URL. Log is not saved to file.", log: OSLog.default, type: .error)
- }
-
- // Setup WireGuard logger
- wgSetLogger { level, msgCStr in
+ Logger.configureGlobal(withFilePath: FileManager.networkExtensionLogFileURL?.path, withTag: "EXT")
+ wgSetLogger { level, msgC in
+ guard let msgC = msgC else { return }
let logType: OSLogType
switch level {
case 0:
@@ -171,8 +153,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
default:
logType = .default
}
- let msg = (msgCStr != nil) ? String(cString: msgCStr!) : ""
- wg_log(logType, message: msg)
+ wg_log(logType, message: String(cString: msgC))
}
}