Logging: Write versions from both app and extension

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander
2018-12-13 18:09:38 +05:30
parent ae565db371
commit efd4b28a0d
3 changed files with 13 additions and 17 deletions
+10
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright © 2018 WireGuard LLC. All Rights Reserved. // Copyright © 2018 WireGuard LLC. All Rights Reserved.
import Foundation
import os.log import os.log
class Logger { 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) { 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)
@@ -22,6 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
wg_log(.info, message: "Launching app") wg_log(.info, message: "Launching app")
wg_log_versions_to_file()
let window = UIWindow(frame: UIScreen.main.bounds) let window = UIWindow(frame: UIScreen.main.bounds)
window.backgroundColor = UIColor.white window.backgroundColor = UIColor.white
@@ -48,11 +48,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
// Configure logging // Configure logging
configureLogger() configureLogger()
wg_log(.info, message: "WireGuard for iOS version \(appVersion())") wg_log(.info, message: "Starting tunnel '\(tunnelConfiguration.interface.name)'")
wg_log(.info, message: "WireGuard Go backend version \(goBackendVersion())") wg_log_versions_to_file()
wg_log(.info, message: "Tunnel interface name: \(tunnelConfiguration.interface.name)")
wg_log(.info, staticMessage: "Starting tunnel")
// Resolve endpoint domains // Resolve endpoint domains
@@ -184,18 +181,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
return wgTurnOn(nameGoStr, settingsGoStr, fileDescriptor) 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<R>(_ str1: String, _ str2: String, closure: (gostring_t, gostring_t) -> R) -> R { private func withStringsAsGoStrings<R>(_ str1: String, _ str2: String, closure: (gostring_t, gostring_t) -> R) -> R {