AlamofireLogger 1.0.2

AlamofireLogger 1.0.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2020年11月
SPM支持 SPM

Daniel Clelland 维护。



  • Daniel Clelland

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)")
        }
    }
)