3 // alamofire_activity_logger
5 // Created by Manuel García-Estañ on 2/11/16.
6 // Copyright © 2016 manuege. All rights reserved.
11 internal let appIsDebugMode = _isDebugAssertConfiguration()
19 Do not log requests or responses.
22 Logs HTTP method, URL, header fields, & request body for requests, and status code, URL, header fields, response string, & elapsed time for responses.
25 Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses.
28 Logs HTTP method & URL for requests, and status code, URL, & elapsed time for responses, but only for failed requests.
30 public enum LogLevel {
43 Only logs if the app is in Debug mode
46 Prints the JSON body on request and response
49 Include a separator string at the begining and end of each section
51 public enum LogOption {
56 public static var defaultOptions: [LogOption] {
57 return [.onlyDebug, .jsonPrettyPrint, .includeSeparator]
64 The different phases of a request that can be printed
67 The request when it is sent
70 The response when it is received; includes a parameter `success` that inform if the response has finished succesfully
74 case response(success: Bool)
76 /// Tells if there is an error in the phase
77 public var isError: Bool {
79 case let .response(success):
87 /// Instances that conforms with `Printer` protocol are able to print the information from a given request
88 public protocol Printer {
91 This method is called when the printer is requested to print a string. Use it to print the information in the way you need.
92 - parameter string: The string to be printed.
93 - parameter phase: The phase of the request that needs to be printed
95 func print(_ string: String, phase: Phase)
98 /// A printer that just use the native `Swift.print` function to print the string.
99 public struct NativePrinter: Printer {
101 /// Creates a new instance
104 public func print(_ string: String, phase: Phase) {