AlamofireLogger
一个小巧的 Alamofire 插件,可以记录请求和响应。使用Apple 统一记录系统在需要时持久化日志。
Cocoapods: pod 'AlamofireLogger', '~> 1.0'
✓ 简单安装
import AlamofireLogger
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NetworkActivityLogManager.shared.level = .simple
return true
}
}
✓ 自定义格式化
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)")
}
}
)