Skip to content

hkellaway/Nog

 
 

Repository files navigation

Nog: A Delicious Network Request Logger ☕

Swift SPM License Build Status

Usage

💡 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.

Filtering Requests

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

🚧


#### Displaying Requests with SwiftUI


``` swift
// :construction:

Displaying Requests in cURL Format

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.

Advanced Usage

Debug Logging

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

Additional Filtering

To fully customize filtering, you can create your own RequestFilters 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.

Mocking Requests

// :construction:
let myNetworkLogger = NetworkLogger(requestFilters: [httpOnlyRequestFilter], adapter: MyNogAdapter.shared)

Custom NetworkLogger

To fully customize how NetworkLogger handles logging requests, ...

🚧

Installation

Swift Package Manager

Point to the latest release or to the main branch for the latest.

CocoaPods

pod 'Nog', :git => 'https://github.com/hkellaway/Nog.git', :tag => 'x.x.x'
pod 'Nog', :git => 'https://github.com/hkellaway/Nog.git', :branch => 'main'

Credits

Nog was created by Harlan Kellaway forked originally from depoon/NetworkInterceptor. ❤️ 💚

License

Nog is available under the MIT license. See the LICENSE file for more info.

About

A delicious network request logger in Swift ☕

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Swift 97.1%
  • Ruby 1.8%
  • Objective-C 1.1%