Swiftpack.co - Package - Kofktu/Sniffer

Sniffer

Build Status Swift CocoaPods Carthage compatible

  • Automatic networking activity logger
  • intercepting any outgoing requests and incoming responses for debugging purposes.

alt tag

Requirements

  • iOS 8.0+, macOS 10.9+, watchOS 2.0+, tvOS 9.0+
  • Swift 5.0
  • Swift 4.2 (1.7.0)
  • Swift 4.0 (1.5.0)
  • Swift 3.0 (1.0.6)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CocoaPods

Sniffer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Sniffer", '~> 2.0'

Carthage

For iOS 8+ projects with Carthage

github "Kofktu/Sniffer"

Usage

for any requests you make via 'URLSession'

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  Sniffer.register() // Register Sniffer to log all requests
  return true
}

for URLSessionConfiguration

let configuration = URLSessionConfiguration.default
Sniffer.enable(in: configuration)

for Custom Deserializer

public protocol BodyDeserializer {
    func deserialize(body: Data) -> String?
}

public final class CustomTextBodyDeserializer: BodyDeserializer {
    public func deserialize(body: Data) -> String? {
        // customization
        return String?
    }
}

Sniffer.register(deserializer: CustomTextBodyDeserializer(), for: ["text/plain"])

If you want to process the logs directly in your application

// Register the handler if you want the log to be handled directly by the application
Sniffer.onLogger = { (url, log) in
  print("\(url) : \(log)")
}

If you want to ignore domains

Sniffer.ignore(domains: ["github.com"])

References

  • Timberjack (https://github.com/andysmart/Timberjack)
  • ResponseDetective (https://github.com/netguru/ResponseDetective)

Authors

Taeun Kim (kofktu), kofktu@gmail.com

License

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

Github

link
Stars: 104

Dependencies

Used By

Total: 0

Releases

Migration to Swift 4.2 - 2018-09-26 14:57:11

  • Migration to Swift 4.2
  • Data race error fix

Migrate to Swift4 - 2017-09-27 04:35:37