KtorSniffer is a Kotlin Multiplatform library for logging, inspecting, and persisting HTTP network traffic in Ktor client applications. It is designed to help developers debug, analyze, and visualize network requests and responses across Android, iOS.
- Automatic Logging: Intercepts and logs all HTTP requests and responses made via Ktor client.
- Persistence: Stores network logs in a local database (Room).
- UI Integration: Comes with a ready-to-use Compose Multiplatform UI for browsing and inspecting logs.
- ProtoBuf Support: Handles ProtoBuf request/response bodies in addition to JSON and plain text.
- Customizable: Easily configure how to format ProtoBuf bodies.
Note: Instructions below assume you have a Kotlin Multiplatform project with Ktor client and Compose Multiplatform set up.
Add the dependency to your shared module:
implementation("io.github.frankieshao:ktorsniffer:0.1.1")
val client = HttpClient {
install(Sniffer)
// ... your other plugins
}
In your Application
or main Activity
:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
KtorSniffer.init(this)
}
}
Note: You must call
KtorSniffer.init(context)
before using the log UI or DAO on Android.
You can embed the provided Compose UI to browse and inspect logs:
@Composable
fun MyApp() {
KtorSnifferScreen(onBack = { /* handle back navigation */ })
}
- Interception: The
Sniffer
plugin hooks into Ktor's client pipeline, capturing request and response data at multiple stages. - Persistence: Logs are saved to a local database using a multiplatform DAO abstraction (Room on Android).
- UI: The Compose UI provides a searchable, filterable list of network logs, with detail views for headers, bodies, and errors.
You can customize logging behavior via the SnifferConfig
DSL:
install(Sniffer) {
protoBuf { /* configure ProtoBuf formatting */ }
coroutineScope { /* provide custom CoroutineScope if needed */ }
}
- Android (Room database, Compose UI)
- iOS (Room database, Compose UI)
See the composeApp
module for a full sample app demonstrating GET/POST/ProtoBuf requests and the log UI.
- Export logs to file
- Integration with other logging/analytics tools
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.
Enjoy debugging with KtorSniffer!
If you like this project, please star it on GitHub and share your feedback.