💡 Nog assumes usage of
URLSessionConfiguration.default
.
To start logging network requests, create an instance of NetworkLogger
and call start
:
let myNetworkLogger = NetworkLogger()
myNetworkLogger.start()
Nog will print request URLs to the console:
[Nog] Request #1: URL => https://github.com/
To stop logging, simply call stop
:
myNetworkLogger.stop()
To check whether logging is currently on, call isLogging
:
myNetworkLogger.isLogging
See the Demo project for sample usage.
By default Nog will print out only requests that start with https
or http
. However, you can introduce your own additional filter to specify when requests should or shouldn't be logged.
Simply initialize NetworkLogger
with a function that takes in a URLRequest
and returns a Bool
:
let myNetworkLogger = NetworkLogger(filter: {
$0.url?.absoluteString.contains("github") ?? false
})
🚧
#### Displaying Requests with SwiftUI
``` swift
// :construction:
When using NetworkLoggerViewController
, the cURL representation of requests is right-at-hand.
Simply tap a request to view it's cURL representation then select Copy cURL.
By default, Nog will print messages to console to assist with debugging. Debug logs are appended with [Nog]
to help isolate in console.
To turn off debug logging, either initialize with verbose: false
or set at a later time:
let quietNetworkLogger = NetworkLogger(requestFilters: [httpOnlyRequestFilter], verbose: false)
let myNetworkLogger = NetworkLogger()
myNetworkLogger.verbose = false
To fully customize filtering, you can create your own RequestFilter
s and provide an array:
let gitHubOnlyRequestFilter: RequestFilter = {
$0.url?.absoluteString.contains("github") ?? false
}
let myNetworkLogger = NetworkLogger(requestFilters: [httpOnlyRequestFilter, gitHubOnlyRequestFilter])
Note: If you still want to filter out only HTTP requests like Nog does by default, make sure to include httpOnlyRequestFilter
in the list.
// :construction:
let myNetworkLogger = NetworkLogger(requestFilters: [httpOnlyRequestFilter], adapter: MyNogAdapter.shared)
To fully customize how NetworkLogger
handles logging requests, ...
🚧
Point to the latest release or to the main
branch for the latest.
pod 'Nog', :git => 'https://github.com/hkellaway/Nog.git', :tag => 'x.x.x'
pod 'Nog', :git => 'https://github.com/hkellaway/Nog.git', :branch => 'main'
Nog was created by Harlan Kellaway forked originally from depoon/NetworkInterceptor. ❤️ 💚
Nog is available under the MIT license. See the LICENSE file for more info.