Swiftpack.co - Kofktu/Sniffer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Kofktu.
Kofktu/Sniffer 2.1.2
Networking activity logger for Swift
⭐️ 120
🕓 3 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Kofktu/Sniffer.git", from: "2.1.2")

Sniffer

Build Status Swift Platform CocoaPods Carthage compatible SwiftPM 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

Authors

Taeun Kim (kofktu), [email protected]

License

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

GitHub

link
Stars: 120
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Support SPM
3 years ago
  • Support SPM
  • Multipart log 추가

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics