Move print logs to OSLogger (#179)
This aids in debugging in console.app, since print statements from the PacketTunnelProvider are not shown in xcode's console.
This commit is contained in:
parent
2d74360bc2
commit
494f071ed5
|
@ -7,7 +7,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
private var networkMonitor: NWPathMonitor?
|
private var networkMonitor: NWPathMonitor?
|
||||||
|
|
||||||
private var site: Site?
|
private var site: Site?
|
||||||
private var log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider")
|
private let log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider")
|
||||||
private var nebula: MobileNebulaNebula?
|
private var nebula: MobileNebulaNebula?
|
||||||
private var dnUpdater = DNUpdater()
|
private var dnUpdater = DNUpdater()
|
||||||
private var didSleep = false
|
private var didSleep = false
|
||||||
|
@ -106,7 +106,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey())
|
try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey())
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
self.log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)")
|
log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import MobileNebula
|
import MobileNebula
|
||||||
import SwiftyJSON
|
import SwiftyJSON
|
||||||
|
import os.log
|
||||||
|
|
||||||
|
let log = Logger(subsystem: "net.defined.mobileNebula", category: "Site")
|
||||||
|
|
||||||
extension String: Error {}
|
extension String: Error {}
|
||||||
|
|
||||||
|
@ -430,7 +433,7 @@ struct IncomingSite: Codable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Saving to \(configPath)")
|
log.notice("Saving to \(configPath, privacy: .public)")
|
||||||
do {
|
do {
|
||||||
if (self.key != nil) {
|
if (self.key != nil) {
|
||||||
let data = self.key!.data(using: .utf8)
|
let data = self.key!.data(using: .utf8)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import os.log
|
||||||
|
|
||||||
class DNUpdater {
|
class DNUpdater {
|
||||||
private let apiClient = APIClient()
|
private let apiClient = APIClient()
|
||||||
private let timer = RepeatingTimer(timeInterval: 15 * 60) // 15 * 60 is 15 minutes
|
private let timer = RepeatingTimer(timeInterval: 30) // 15 * 60 is 15 minutes
|
||||||
|
private let log = Logger(subsystem: "net.defined.mobileNebula", category: "DNUpdater")
|
||||||
|
|
||||||
func updateAll(onUpdate: @escaping (Site) -> ()) {
|
func updateAll(onUpdate: @escaping (Site) -> ()) {
|
||||||
_ = SiteList{ (sites, _) -> () in
|
_ = SiteList{ (sites, _) -> () in
|
||||||
|
@ -55,7 +57,7 @@ class DNUpdater {
|
||||||
} catch (APIClientError.invalidCredentials) {
|
} catch (APIClientError.invalidCredentials) {
|
||||||
if (!credentials.invalid) {
|
if (!credentials.invalid) {
|
||||||
try site.invalidateDNCredentials()
|
try site.invalidateDNCredentials()
|
||||||
print("Invalidated credentials in site \(site.name)")
|
log.notice("Invalidated credentials in site: \(site.name, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -63,7 +65,7 @@ class DNUpdater {
|
||||||
|
|
||||||
newSite?.save(manager: nil) { error in
|
newSite?.save(manager: nil) { error in
|
||||||
if (error != nil) {
|
if (error != nil) {
|
||||||
print("failed to save update: \(error!.localizedDescription)")
|
self.log.error("failed to save update: \(error!.localizedDescription, privacy: .public)")
|
||||||
} else {
|
} else {
|
||||||
onUpdate(Site(incoming: newSite!))
|
onUpdate(Site(incoming: newSite!))
|
||||||
}
|
}
|
||||||
|
@ -71,11 +73,11 @@ class DNUpdater {
|
||||||
|
|
||||||
if (credentials.invalid) {
|
if (credentials.invalid) {
|
||||||
try site.validateDNCredentials()
|
try site.validateDNCredentials()
|
||||||
print("Revalidated credentials in site \(site.name)")
|
log.notice("Revalidated credentials in site \(site.name, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
print("Error while updating \(site.name): \(error.localizedDescription)")
|
log.error("Error while updating \(site.name, privacy: .public): \(error.localizedDescription, privacy: .public)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue