AlamofireLogger
AlamofireLogger copied to clipboard
Tiny Alamofire plugin that logs requests and responses.
AlamofireLogger
Tiny Alamofire plugin that logs requests and responses. Uses the Apple unified logging system to persist logs if necessary.
Cocoapods: pod 'AlamofireLogger', '~> 1.0'
✓ Simple installation
import AlamofireLogger
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NetworkActivityLogManager.shared.level = .simple
return true
}
}
✓ Custom formatters
NetworkActivityLogManager.shared.level = .custom(
startFormatter: { request in
return .debug("Request started: \(request.description)")
},
stopFormatter: { request in
if let error = request.error {
return .error("Request failed: \(error.localizedDescription)")
} else {
return .debug("Request completed: \(request.description)")
}
}
)