ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
482 stars 216 forks source link

Can we print logs detail of network and VPN? #142

Closed ms-tii closed 5 years ago

ms-tii commented 5 years ago

Hi guys,

I want to show network logs same exactly like openVpn Client app. I don't know how to get the network test details. If we can do the same please help me HOW and where we can get these details in this adapter(In tunnelProvider or viewController). Below are the screenshots of OpenVPN client app's Logs : Screenshot 2019-09-17 at 6 55 00 PM

ss-abramchuk commented 5 years ago

Hi @ms-tii,

Declaration of OpenVPNAdapterDelegate has optional method openVPNAdapter(openVPNAdapter:handleLogMessage). If you implement it you will get all log messages OpenVPN library generates.

ms-tii commented 5 years ago

@ss-abramchuk Thank you for your reply despite your busy schedule,

I tried to use this method but it doesn't transfer live continuos value to print on run time in viewController class. I was using userDefaults share data between app and tunnelExtension like:- In PacketTunnel - let kAppGroupName = "group.com.abc.efgh" var sharedContainer : UserDefaults? self.sharedContainer = UserDefaults(suiteName: kAppGroupName) func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) { // Handle log messages if let sharedContainer = self.sharedContainer { sharedContainer.set(logMessage as String, forKey: "networkLogsMessages") sharedContainer.synchronize() } }

In viewController where networkmonitor - let kAppGroupName = "group.com.abc.efgh" var sharedContainer : UserDefaults? self.sharedContainer = UserDefaults(suiteName: kAppGroupName) func networkStatusMonitor(){ NetStatus.shared.netStatusChangeHandler = { DispatchQueue.main.async { [unowned self] in if let sharedContainer = self.sharedContainer { let logMessages = sharedContainer.string(forKey: "networkLogsMessages") print(logMessages) } } } } But it only shows once and old saved logs because when any logMessage occured it saves in userDefaults(in extension) and when in viewController on button click I retrieve these message(In viewDidLoad) from userdefaults it show once only. Within this time period there are new logs occured and it only shows the previous fetched.

If you don't mind and can take time for this, can you share the code snippet to show logs continuously in viewController class. It will be really kind and appreciate. Thank you very much.

ss-abramchuk commented 5 years ago

You need to use KVO for UserDefaults. I don't have a snippet but you may find how to do it in this topic -> How to use KVO for UserDefaults in Swift?

ms-tii commented 5 years ago

@ss-abramchuk Thank you very much for the help.