From 8d0d8cc11f521d9d0ed59c72e42c8ed3bbf3a5fb Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 13 Dec 2018 18:09:38 +0530 Subject: [PATCH] Logging: Write versions from both app and extension --- WireGuard/Shared/Logging/Logger.swift | 10 ++++++++++ WireGuard/WireGuard/UI/iOS/AppDelegate.swift | 1 + .../PacketTunnelProvider.swift | 19 ++----------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/WireGuard/Shared/Logging/Logger.swift b/WireGuard/Shared/Logging/Logger.swift index 88df246..7df162a 100644 --- a/WireGuard/Shared/Logging/Logger.swift +++ b/WireGuard/Shared/Logging/Logger.swift @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright © 2018 WireGuard LLC. All Rights Reserved. +import Foundation import os.log class Logger { @@ -32,6 +33,15 @@ class Logger { } } +func wg_log_versions_to_file() { + var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown version" + if let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String { + appVersion += " (\(appBuild))" + } + let goBackendVersion = WIREGUARD_GO_VERSION + file_log(message: "App version: \(appVersion); Go backend version: \(goBackendVersion)") +} + func wg_log(_ type: OSLogType, staticMessage msg: StaticString) { // Write to os log os_log(msg, log: OSLog.default, type: type) diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift index f15aede..a5856e0 100644 --- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift @@ -22,6 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } wg_log(.info, message: "Launching app") + wg_log_versions_to_file() let window = UIWindow(frame: UIScreen.main.bounds) window.backgroundColor = UIColor.white diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift index 04e3893..03da7bb 100644 --- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -48,11 +48,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider { // Configure logging configureLogger() - wg_log(.info, message: "WireGuard for iOS version \(appVersion())") - wg_log(.info, message: "WireGuard Go backend version \(goBackendVersion())") - wg_log(.info, message: "Tunnel interface name: \(tunnelConfiguration.interface.name)") - - wg_log(.info, staticMessage: "Starting tunnel") + wg_log(.info, message: "Starting tunnel '\(tunnelConfiguration.interface.name)'") + wg_log_versions_to_file() // Resolve endpoint domains @@ -184,18 +181,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider { return wgTurnOn(nameGoStr, settingsGoStr, fileDescriptor) } } - - func appVersion() -> String { - var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown version" - if let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String { - appVersion += " (\(appBuild))" - } - return appVersion - } - - func goBackendVersion() -> String { - return WIREGUARD_GO_VERSION - } } private func withStringsAsGoStrings(_ str1: String, _ str2: String, closure: (gostring_t, gostring_t) -> R) -> R {