A Moya plugin for one-line logs.
MoyaLaconicPlugin logs your Moya requests and their responses using a short message for each.
In an application with many network calls, sometimes it is enough to just know when a request is fired and when its response comes back.
Let your Moya targets conform to the Laconic protocol and assign an identifier to your endpoints:
extension HTTPCatTarget: Laconic {
var primaryIdentifier: String {
return "🐈"
}
var secondaryIdentifier: String {
switch self {
case .catOk:
return "😸"
case .catNotFound:
return "😿"
}
}
}
You are free to assign any string to your endpoints, they will appear in the following order: pluginIdentifier``primaryIdentifier``secondaryIdentifier
MoyaLaconicPlugin will use these and write into the Console an one-line message, together with the status code of each response:
1982-03-19 22:10:46.692489+0300 MoyaLaconicPlugin_Example[3565:3675403] 💭🐈🔜😿
1982-03-19 22:10:46.766139+0300 MoyaLaconicPlugin_Example[3565:3675154] 💭🐈🔙✅😿 (HTTP 200)
By default, the plugin uses:
- 💭 as a top-level identifier to help filter out messages related to networking
- 🔜 for requests
- 🔙 for resposnes
- ✅ for representing
.success
- ❌ for representing
.failure
It's easy to use your own strings by using the plugin's initializer:
LaconicPlugin(pluginIdentifier: "*️⃣", requestIdentifier: "➡️", responseIdentifier: "⬅️", successIdentifier: "🆗", failureIdentifier: "🆖")
Then the logs above would become:
1982-03-19 22:10:46.692489+0300 MoyaLaconicPlugin_Example[3565:3675403] *️⃣🐈➡️😿
1982-03-19 22:10:46.766139+0300 MoyaLaconicPlugin_Example[3565:3675154] *️⃣🐈⬅️🆗😿 (HTTP 200)
To activate the plugin, add it in the array of plugins when creating the Moya provider:
provider = MoyaProvider<MultiTarget>(plugins: [ LaconicPlugin(), /* other plugins */ ])
To run the example project, clone the repo, and run pod install
from the Example directory first.
MoyaLaconicPlugin is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MoyaLaconicPlugin'
MoyaLaconicPlugin is available under the MIT license. See the LICENSE file for more info.