Glider is the logger for just about everything!
It's designed to be:
See the project's page on GitHub for more informations.
NetWatcher
package is a simple, unintrusive network activity logger perfectly integrated in Glider.
Log every request your app makes, or limit to only those using a certain URLSession
if you'd prefer.
It also works with Alamofire and RealHTTP, if that's your thing.
NetWatcher
is not part of the Glider Core; you can install it by selecting the GliderNetWatcher
package when installing the main Glider dependency or by using the GliderNetWatcher.podspec
if you are using CocoaPods
If you want to capture all the network traffic inside the app, just call captureGlobally()
method:
// Start global capture
NetWatcher.shared.captureGlobally(true)
// ...Same to stop
NetWatcher.shared.captureGlobally(false)
for URLSessionConfiguration
:
let configuration = URLSessionConfiguration.default
**NetWatcher**.shared.capture(true, forSessionConfiguration: configuration)
// ...Same to stop
NetWatcher.shared.capture(false, forSessionConfiguration: configuration)
Most of the time you may want to capture sniffed traffics to send it to a Glider Transport service.
NetWatcher
is perfectly integrated: just set your custom configuration before activating the sniffer:
The following example uses the NetArchiveTransport
transport; a transport made to store network requests/responses directly in a compact, readable SQLite3 local database (it's like SQLiteTransport
).
// Setup the configuration
let archiveURL = URL(fileURLWithPath: ".../sniffed_network.sqlite")
let archiveConfig = NetArchiveTransport.Configuration(location: .fileURL(archiveURL))
NetWatcher.shared.setConfiguration(watcherConfig)
// Activate global sniffer
NetWatcher.shared.captureGlobally(true)
Sometimes you may want to avoid redirecting captured traffic inside a transport and just get notified about the event.
In this case just set the delegate of NetWatcher
singleton and listen for events:
class UIApplication: UIApplicationDelegate, NetWatcherDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NetWatcher.shared.delegate = self
NetWatcher.shared.captureGlobally(true)
return true
}
func netWatcher(_ watcher: NetWatcher, didCaptureEvent event: NetworkEvent) {
// A new event has been captured!
print("Captured request from \(event.url)...")
}
func netWatcher(_ watcher: NetWatcher, shouldRecordRequest request: URLRequest) -> Bool {
// implement your own logic to filter/ignore a request from being captured.
// return ...
}
}
NetWatcher
has two transport specifically made to store network events.
You can, however, create your own implementation to suit your need.
The NetSparseFilesTransport
class is used to store network activity inside a root folder.
Each call is stored with a single textual file with the id of the network call and its creation date set to the original call date.
Inside each file you can found <cURL command for request>\n\n<raw response data>
.
let sparseArchive = NetSparseFilesTransport.Config {
$0.directoryURL = localFolderURL // location of the directory (will be created if not exists)
$0.resetAtStartup = false // do not remove previously-stored data at launch
}
NetWatcher.shared.setConfiguration(sparseArchive)
The NetArchiveTransport
class is used to store network activity in a compact searchable archive powered by SQLite3.
let archive = NetArchiveTransport.Config {
$0.databaseLocation = .fileURL(localDbURL)
$0.throttledTransport = .init { t in
t.maxEntries = 500 // maximum number of logs to store
}
// The maximum age of src="https://raw.github.com/immobiliare/Glider-NetWatcher/main/ before it it will be removed automatically to preserve the space. Set as you needs.
$0.lifetimeInterval = 60 * 60 // 1h
}
NetWatcher.shared.setConfiguration(archive)
Minimum requirements are:
Made with ❤️ by ImmobiliareLabs & Contributors
We'd love for you to contribute to Glider!
If you have questions on using Glider, bugs, and enhancement, please feel free to reach out by opening a GitHub Issue.
link |
Stars: 4 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics