1 # AlamofireActivityLogger
3 A response serializer for [**Alamofire**](https://github.com/Alamofire/Alamofire) which logs both request and response. It provides 4 log levels and a few options to configure your logs.
5 **AlamofireActivityLogger** is available for:
13 > **NOTE**: This version is written for **Alamofire 4.x** and **Swift 3**. To support **Swift 2** and **Alamofire 3.x** use the [version 1.0.1](https://github.com/ManueGE/AlamofireActivityLogger/tree/1.0.1/).
15 ## Installing AlamofireActivityLogger
19 Add the following to your `Podfile`:
22 pod 'AlamofireActivityLogger'
25 Then run `$ pod install`.
27 And finally, in the classes where you need **AlamofireActivityLogger**:
30 import AlamofireActivityLogger
33 If you don’t have CocoaPods installed or integrated into your project, you can learn how to do so [here](http://cocoapods.org).
37 To log a request you just have to write:
46 Additionally, you can provide the log level and some options:
51 .log(level: level, options: options, printer: myPrinter)
55 Let's see the **levels** and **options**.
59 Are instances of the enum `LogLevel`. The available values are:
61 * **`none`**: Do not log requests or responses.
63 * **`all`**: Logs HTTP method, URL, header fields, & request body for requests, and status code, URL, header fields, response string, & elapsed time for responses.
65 * **`info`**: Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses.
67 * **`error`**: Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses, but only for failed requests.
69 The default value is **`all`**.
73 Are instances of the enum `LogOption`. The available values are:
75 * **`onlyDebug`**: Only logs if the app is in Debug mode
77 * **`jsonPrettyPrint`**: Prints the JSON body on request and response
79 * **`includeSeparator`**: Include a separator string at the begining and end of each section
81 The default value is **`[.onlyDebug, .jsonPrettyPrint, .includeSeparator]`**.
85 If you use a third party logger, you can integrate it with AlamofireActivityLogger. To do it, you must provide a `Printer` object.
87 `Printer` is a protocol which just requires one method:
90 func print(_ string: String, phase: Phase)
93 As an example, let’s suppose you have [SwiftyBeaver](https://github.com/SwiftyBeaver/SwiftyBeaver) integrated in your app. We can create a `SwiftyBeaverPrinter` struct like this:
96 struct SwiftyBeaverPrinter: Printer {
97 func print(_ string: String, phase: Phase) {
113 .log(printer: SwiftyBeaverPrinter())
117 By default, a instance of `NativePrinter` is used. It just make use of the native `Swift.print` to print the info.
120 ## Supported requests
122 At the moment, **AlamofireActivityLogger** has support for `DataRequest` and `DownloadRequest`. If you need to add support to any other `Request` subclass, just make it conforms the `LoggeableRequest` protocol. Take a look at the `DataRequest` implementation to know how.
127 [Manuel García-Estañ Martínez](http://github.com/ManueGE)
128 [@manueGE](https://twitter.com/ManueGE)
132 AlamofireActivityLogger is available under the [MIT license](LICENSE.md).