You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.6 KiB

  1. # AlamofireNetworkActivityLogger
  2. [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/AlamofireNetworkActivityLogger.svg)](https://img.shields.io/cocoapods/v/AlamofireNetworkActivityLogger.svg)
  3. [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
  4. [![Platform](https://img.shields.io/cocoapods/p/AlamofireNetworkActivityLogger.svg?style=flat)](http://cocoadocs.org/docsets/AlamofireNetworkActivityLogger)
  5. Network activity logger for Alamofire.
  6. ## Requirements
  7. - iOS 9.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
  8. - Xcode 8.0+
  9. - Swift 3.2+
  10. ## Dependencies
  11. - [Alamofire 4.8+](https://github.com/Alamofire/Alamofire)
  12. ## Installation
  13. ### CocoaPods
  14. [CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
  15. ```bash
  16. $ gem install cocoapods
  17. ```
  18. > CocoaPods 1.6.0+ is required.
  19. To integrate AlamofireNetworkActivityLogger into your Xcode project using CocoaPods, specify it in your `Podfile`:
  20. ```ruby
  21. source 'https://github.com/CocoaPods/Specs.git'
  22. platform :ios, '10.0'
  23. use_frameworks!
  24. pod 'AlamofireNetworkActivityLogger', '~> 2.4'
  25. ```
  26. Then, run the following command:
  27. ```bash
  28. $ pod install
  29. ```
  30. ### Carthage
  31. [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
  32. You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
  33. ```bash
  34. $ brew update
  35. $ brew install carthage
  36. ```
  37. To integrate AlamofireNetworkActivityLogger into your Xcode project using Carthage, specify it in your `Cartfile`:
  38. ```ogdl
  39. github "konkab/AlamofireNetworkActivityLogger" ~> 2.4
  40. ```
  41. ---
  42. ## Usage
  43. Import the library:
  44. ```swift
  45. import AlamofireNetworkActivityLogger
  46. ```
  47. Add the following code to `AppDelegate.swift application:didFinishLaunchingWithOptions:`:
  48. ```swift
  49. NetworkActivityLogger.shared.startLogging()
  50. ```
  51. Now all NSURLSessionTask objects created by an Alamofire.SessionManager will have their request and response logged to the console, a la:
  52. ```
  53. ---------------------
  54. GET 'http://example.com/foo/bar.json'
  55. ---------------------
  56. 200 'http://example.com/foo/bar.json' [0.2535 s]
  57. ```
  58. If the default logging level is too verbose—say, if you only want to know when requests fail—then changing it is as simple as:
  59. ```swift
  60. NetworkActivityLogger.shared.level = .error
  61. ```
  62. ## Contact
  63. Konstantin Kabanov
  64. - kabanov_kv@me.com
  65. - Skype: konstantin_kabanov
  66. - [Linkedin](https://ru.linkedin.com/in/konstantinkabanov)
  67. ## License
  68. AlamofireNetworkActivityLogger is released under the MIT license. See LICENSE for details.